Question

old_spec.rb

it { should allow_value(:nil).for(:invoice_type) }
it { should allow_value(:customer_invoice).for(:invoice_type) }
it { should allow_value(:creative_invoice).for(:invoice_type) }
it { should_not allow_value(:other).for(:invoice_type) }

I have these code in my spec file and I convert them like below.

new_spec.rb

   it { should ensure_inclusion_of(:invoice_type).in_array(
     [:nil,:customer_invoice,:creative_invoice]) }

I wonder that in the second file (new_spec.rb) do I have to write this line.

it { should_not allow_value(:other).for(:invoice_type) }
Was it helpful?

Solution

Based on the description of how ensure_inclusion_of works, you shouldn't need to explicitly prevent other values.

Of course, it would be very easy to check this for yourself...

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