diff options
Diffstat (limited to 'spec/support/matchers')
-rw-r--r-- | spec/support/matchers/model/model_have_error_on_field.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/spec/support/matchers/model/model_have_error_on_field.rb b/spec/support/matchers/model/model_have_error_on_field.rb new file mode 100644 index 000000000..5d5fe1c7b --- /dev/null +++ b/spec/support/matchers/model/model_have_error_on_field.rb @@ -0,0 +1,15 @@ +RSpec::Matchers.define :model_have_error_on_field do |expected| + match do |record| + if record.errors.empty? + record.valid? + end + + record.errors.has_key?(expected) + end + + failure_message do |record| + keys = record.errors.keys + + "expect record.errors(#{keys}) to include #{expected}" + end +end |