diff options
author | Samy KACIMI <samy.kacimi@gmail.com> | 2017-04-05 00:29:56 +0200 |
---|---|---|
committer | Samy KACIMI <samy.kacimi@gmail.com> | 2017-04-05 00:29:56 +0200 |
commit | 81c76fe375d9342e5a436db05c8e25305c650e8d (patch) | |
tree | 9d81c36f8745de3d5ab8827a82a14be369f0d23e /spec/support/matchers/model | |
parent | 6fd865c0004efbf11ee87c06fea9f48af567fabe (diff) |
add more tests to models
Diffstat (limited to 'spec/support/matchers/model')
-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 |