David R
David R

Reputation: 328

Shoulda rspec matchers ensure_inclusion_of

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

Upvotes: 4

Views: 2290

Answers (1)

Andy Waite
Andy Waite

Reputation: 11076

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?

Upvotes: 3

Related Questions