Class: Mongoid::Matchers::SaveMatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/matchers/document.rb

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ SaveMatcher

Returns a new instance of SaveMatcher.



62
63
64
# File 'lib/matchers/document.rb', line 62

def initialize(attributes = {})
  @attributes = attributes
end

Instance Method Details

#descriptionObject



81
82
83
# File 'lib/matchers/document.rb', line 81

def description
  "save properly"
end

#failure_message_for_shouldObject



73
74
75
# File 'lib/matchers/document.rb', line 73

def failure_message_for_should
  "Expected #{@actual.inspect} to save properly, got #{@actual.errors.full_messages.to_sentence}"
end

#failure_message_for_should_notObject



77
78
79
# File 'lib/matchers/document.rb', line 77

def failure_message_for_should_not
  "Expected #{@actual.inspect} to not save, got saved instead"
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
69
70
71
# File 'lib/matchers/document.rb', line 66

def matches?(actual)
  @actual = actual.is_a?(Class) ? 
    ( defined?(::Factory) ? ::Factory.build(actual.name.underscore, @attributes) : actual.new(@attributes)) :
    actual
  @actual.valid? and @actual.save
end