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

16 lines
339 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2017-04-04 15:29:56 -07:00
RSpec::Matchers.define :model_have_error_on_field do |expected|
match do |record|
record.valid? if record.errors.empty?
2017-04-04 15:29:56 -07:00
record.errors.key?(expected)
2017-04-04 15:29:56 -07:00
end
failure_message do |record|
keys = record.errors.attribute_names
2017-11-16 17:52:30 -08:00
2017-04-04 15:29:56 -07:00
"expect record.errors(#{keys}) to include #{expected}"
end
end