about summary refs log tree commit diff
path: root/spec/support/matchers/model/model_have_error_on_field.rb
blob: 21632b5748fd6a1974486a38fe014ee0dc324681 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# frozen_string_literal: true

RSpec::Matchers.define :model_have_error_on_field do |expected|
  match do |record|
    record.valid? if record.errors.empty?

    record.errors.has_key?(expected)
  end

  failure_message do |record|
    keys = record.errors.attribute_names

    "expect record.errors(#{keys}) to include #{expected}"
  end
end