0
код
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!?"]}>
Возможный дубликат [Shoulda/RSpec: Убедитесь, что сообщение проверки «xxx» включено: база] (http://stackoverflow.com/questions/11453152/shoulda-rspec-make-sure-that-validation-message -xxx-это-на-основание) – BBonifield