Skip to content

Commit

Permalink
refactor 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Francesco Rodriguez committed Feb 27, 2013
1 parent e8d4ab4 commit 1dcb38c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
8 changes: 8 additions & 0 deletions lib/matchers/document/be_stored_in.rb
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions lib/matchers/document/document.rb
Expand Up @@ -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 ''
Expand Down
4 changes: 2 additions & 2 deletions lib/matchers/document/have_field.rb
Expand Up @@ -14,6 +14,7 @@ class HaveFieldMatcher < Matcher

def initialize *fields
@fields = fields.collect(&:to_s)
@errors = []
end

def of_type type
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/matchers/document/have_index.rb
Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions lib/matchers/matcher.rb
Expand Up @@ -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.