Skip to content
Browse files

refactor 2

  • Loading branch information...
1 parent e8d4ab4 commit 1dcb38c2196c4792eefbd07ba67cfc8d15107aad Francesco Rodriguez committed Feb 27, 2013
View
8 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
View
8 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 ''
View
4 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
View
2 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
View
8 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

0 comments on commit 1dcb38c

Please sign in to comment.
Something went wrong with that request. Please try again.