The following test is always failing, but it's not clear why.
# entry_spec.rb
require 'spec_helper'
describe Entry do
before { @entry = build_stubbed :entry }
subject { @entry }
it { should respond_to :published }
describe 'validation' do
it { should ensure_inclusion_of(:published).in_array([true, false]) }
end
end
# entry.rb
class Entry < ActiveRecord::Base
validates :published, inclusion: { in: [true, false] }
end
The failure:
1) Entry validation should ensure inclusion of published in [true, false]
Failure/Error: it { should ensure_inclusion_of(:published).in_array([true, false]) }
[true, false] doesn't match array in validation
# ./spec/models/entry_spec.rb:18:in `block (3 levels) in <top (required)>'
Factory:
FactoryGirl.define do
factory :entry do
published true
end
end
I'm ommitted a couple of other attributes, but there is nothing special going on there, and they shouldn't impact the code.
This appears to be a bug with shoulda-matchers. The suggested workaround is to use allow_value
matcher instead.