Forum: RSpec rspec assert inclusion in..

78e7109f5fd74ae07678541288f0a417?d=identicon&s=25 slavix tube (slavix)
on 2011-09-04 03:09
(Received via mailing list)
hello,
I would like to assert that an attribute of a model has value among
those in an array. How would I do it in rspec?

Something like this...

describe OptionType do
  context "shoulda validations" do
    it { assert_contains :type, ['Type1', 'Type1']}
  end
end
49de4cd2f26705785cbef2b15a9df7aa?d=identicon&s=25 Nick Hoffman (nickh)
on 2011-09-04 03:51
(Received via mailing list)
Hey Slavix. How about this:

it 'has a valid "attribute_x" value' do
  valid_values = %w(some values here)
  valid_values.should include subject.attribute_x
end
78e7109f5fd74ae07678541288f0a417?d=identicon&s=25 slavix tube (slavix)
on 2011-09-04 05:43
(Received via mailing list)
this seems to be the way to do it.

    it
{ should_validate_numericality_of :amount, :greater_than_or_equal_to
=> 0 }
    it { should_validate_inclusion_of :gender, :in => %w( m f )
78e7109f5fd74ae07678541288f0a417?d=identicon&s=25 slavix tube (slavix)
on 2011-09-04 06:18
(Received via mailing list)
Thanks. I wanted to test it as part of model validation like

    it { should validate_presence_of(:some_attribute).among(['value1',
'value2']) }
    it { should validate_that(:some_attribute) >= 0 }
This topic is locked and can not be replied to.