2023-02-22 00:55:31 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-04 22:29:56 +00:00
|
|
|
RSpec::Matchers.define :model_have_error_on_field do |expected|
|
|
|
|
match do |record|
|
2023-02-18 11:37:47 +00:00
|
|
|
record.valid? if record.errors.empty?
|
2017-04-04 22:29:56 +00:00
|
|
|
|
2023-03-16 00:36:37 +00:00
|
|
|
record.errors.key?(expected)
|
2017-04-04 22:29:56 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
failure_message do |record|
|
2022-02-24 13:46:21 +00:00
|
|
|
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
|