mastodon/spec/support/matchers/model/model_have_error_on_field.rb

14 lines
312 B
Ruby
Raw Normal View History

2017-04-04 22:29:56 +00:00
RSpec::Matchers.define :model_have_error_on_field do |expected|
match do |record|
record.valid? if record.errors.empty?
2017-04-04 22:29:56 +00:00
record.errors.has_key?(expected)
end
failure_message do |record|
keys = record.errors.attribute_names
2017-11-17 01:52:30 +00:00
2017-04-04 22:29:56 +00:00
"expect record.errors(#{keys}) to include #{expected}"
end
end