about summary refs log tree commit diff
path: root/spec/support/matchers
diff options
context:
space:
mode:
authorSamy KACIMI <samy.kacimi@gmail.com>2017-04-05 00:29:56 +0200
committerSamy KACIMI <samy.kacimi@gmail.com>2017-04-05 00:29:56 +0200
commit81c76fe375d9342e5a436db05c8e25305c650e8d (patch)
tree9d81c36f8745de3d5ab8827a82a14be369f0d23e /spec/support/matchers
parent6fd865c0004efbf11ee87c06fea9f48af567fabe (diff)
add more tests to models
Diffstat (limited to 'spec/support/matchers')
-rw-r--r--spec/support/matchers/model/model_have_error_on_field.rb15
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