This repository has been archived on 2024-07-31. You can view files and clone it, but cannot push or open issues or pull requests.
2023-02-21 19:55:31 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-04 18:29:56 -04:00
|
|
|
RSpec::Matchers.define :model_have_error_on_field do |expected|
|
|
|
|
match do |record|
|
2023-02-18 06:37:47 -05:00
|
|
|
record.valid? if record.errors.empty?
|
2017-04-04 18:29:56 -04:00
|
|
|
|
|
|
|
record.errors.has_key?(expected)
|
|
|
|
end
|
|
|
|
|
|
|
|
failure_message do |record|
|
2022-02-24 08:46:21 -05:00
|
|
|
keys = record.errors.attribute_names
|
2017-11-16 20:52:30 -05:00
|
|
|
|
2017-04-04 18:29:56 -04:00
|
|
|
"expect record.errors(#{keys}) to include #{expected}"
|
|
|
|
end
|
|
|
|
end
|