Shoulda Question: how to test validates_inclusion_of...?

I'm using thoughtbot's shoulda, and I have this in a model:

validates_inclusion_of :year, :in => %w[ 09-10 10-11 ]

where :year is of type string. How do I test this in shoulda? Is it with (1) should ensure_inclusion_of or do I have to do (2) should allow_value('09-10').for(:year) and the should_not equivalents?

So? (2) seems verbose... I mean, having to do a bunch of should's and should_not's?

I’m using thoughtbot’s shoulda, and I have this in a model:

validates_inclusion_of :year, :in => %w[ 09-10 10-11 ]

where :year is of type string. How do I test this in shoulda? Is it

with

(1) should ensure_inclusion_of

or do I have to do

(2) should allow_value(‘09-10’).for(:year) and the should_not

equivalents?

So? (2) seems verbose… I mean, having to do a bunch of should’s and

should_not’s?

I would be curious if there was another way if I understand exactly what you are doing, but I think (2) is what you have to do… seems to me it is similar to validating the format of an attribute.

Although, you might have to change your structure but seems that somehow you could use “should include_value_in_range”…

(see http://rubydoc.info/github/thoughtbot/shoulda/master/Shoulda/ActiveRecord/Macros)

I’m using thoughtbot’s shoulda, and I have this in a model:

validates_inclusion_of :year, :in => %w[ 09-10 10-11 ]

where :year is of type string. How do I test this in shoulda? Is it

with

(1) should ensure_inclusion_of

or do I have to do

(2) should allow_value(‘09-10’).for(:year) and the should_not

equivalents?

So? (2) seems verbose… I mean, having to do a bunch of should’s and

should_not’s?

I would be curious if there was another way if I understand exactly what you are doing, but I think (2) is what you have to do… seems to me it is similar to validating the format of an attribute.

Although, you might have to change your structure but seems that somehow you could use “should include_value_in_range”…

(see http://rubydoc.info/github/thoughtbot/shoulda/master/Shoulda/ActiveRecord/Macros)

Oops, I was looking at deprecated stuff… anyhow you would probably have to change your structure to something numeric or date-like to use ensure_inclusion_of but maybe in the end that would be the right way to do it.