4

I have a test using shoulda that is failing for reasons I don't understand. Any idea what the fix is for this? I hardcoded the array for testing purposes.

All my other shoulda matcher based tests are working fine.

Validation

validates_inclusion_of :status, :in => ["Active", "Closed"]

Test:

it { should ensure_inclusion_of(:status).in_array(["Active", "Closed"]) }

Failure

Failure/Error: it { should ensure_inclusion_of(:status).in_array(["Active", "Closed"]) }
   ["Active", "Closed"] doesn't match array in validation
David R
  • 328
  • 1
  • 15

1 Answers1

3

Looking at the source code for that matcher:

https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb#L88

Do you have another validation which prevents nil or blank values for :status?

Andy Waite
  • 10,785
  • 4
  • 33
  • 47
  • Thanks. That looks like the issue. – David R Mar 29 '13 at 18:28
  • the code has changed, the new link is: https://github.com/thoughtbot/shoulda-matchers/blob/master/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb#L22 – Peter P. Apr 28 '14 at 21:11
  • Link changed again: https://www.omniref.com/ruby/gems/shoulda-matchers/2.2.0/files/lib/shoulda/matchers/active_model/ensure_inclusion_of_matcher.rb – BananaNeil Apr 02 '15 at 00:46