Question

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
Was it helpful?

Solution

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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top