diff --git a/lib/matchers/document/be_stored_in.rb b/lib/matchers/document/be_stored_in.rb index 2553f1f..ffd614d 100644 --- a/lib/matchers/document/be_stored_in.rb +++ b/lib/matchers/document/be_stored_in.rb @@ -17,6 +17,14 @@ def matches? subject class_of(subject).collection_name.to_s == collection_name end + def failure_message + "Expected #{inspect} to #{description}" + end + + def negative_failure_message + "Expected not to #{description}" + end + def description "be stored in #{collection_name.inspect}" end diff --git a/lib/matchers/document/document.rb b/lib/matchers/document/document.rb index 2f22fbc..511a67d 100644 --- a/lib/matchers/document/document.rb +++ b/lib/matchers/document/document.rb @@ -41,6 +41,14 @@ def matches? subject class_of(subject).included_modules.include? mod end + def failure_message + "Expected #{inspect} to #{description}" + end + + def negative_failure_message + "Expected not to #{description}" + end + def description msg = case when mod == DOCUMENT then '' diff --git a/lib/matchers/document/have_field.rb b/lib/matchers/document/have_field.rb index 806505b..4bc568f 100644 --- a/lib/matchers/document/have_field.rb +++ b/lib/matchers/document/have_field.rb @@ -14,6 +14,7 @@ class HaveFieldMatcher < Matcher def initialize *fields @fields = fields.collect(&:to_s) + @errors = [] end def of_type type @@ -27,8 +28,7 @@ def with_default_value default end def matches? subject - @klass = class_of subject - @errors = [] + @klass = class_of subject fields.each do |field| if klass.fields.include? field diff --git a/lib/matchers/document/have_index.rb b/lib/matchers/document/have_index.rb index 7ede086..4b1b835 100644 --- a/lib/matchers/document/have_index.rb +++ b/lib/matchers/document/have_index.rb @@ -16,7 +16,7 @@ def initialize *attrs def matches? subject @klass = class_of subject - klass.index_options.any? { |idx, _| idx.keys == @attrs } + klass.index_options.any? { |idx, _| idx.keys == attrs } end def failure_message diff --git a/lib/matchers/matcher.rb b/lib/matchers/matcher.rb index 3a0764f..65d5037 100644 --- a/lib/matchers/matcher.rb +++ b/lib/matchers/matcher.rb @@ -2,14 +2,6 @@ module Mongoid module Matchers class Matcher include MiniTest::Matchers::ActiveModel::Helpers - - def failure_message - "Expected #{inspect} to #{description}".squeeze ' ' - end - - def negative_failure_message - "Expected not to #{description}".squeeze ' ' - end end end end