class Foo
include ActiveModel::Validations
def bar
errors.add(:base, 'WHAT THE HELL!?')
end
end
describe 'nonsense' do
specify do
foo = Foo.new
foo.bar
expect(foo).to have(1).error_on(:base)
end
end
Failure/Error: specify { expect(foo).to have(1).error_on(:base) }
expected 1 error on :base, got 0
describe 'nonsense' do
specify do
foo = Foo.new
foo.bar
pus foo.errors.inspect
expect(foo).to have(1).error_on(:base)
end
end
===>
#<ActiveModel::Errors:0x00000109ba51a8 @base=#<Foo:0x00000109ba51f8 @errors=#<ActiveModel::Errors:0x00000109ba51a8 ...>>, @messages={:base=>["WHAT THE HELL!?"]}>
It appears that if you don't call the "valid?" method prior to using the "have(n).errors_on" matcher in a spec, it will always return false, even if your errors object has stuff in it!