Class: Spec::Rails::Matchers::ArBeValid

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/rails/matchers/ar_be_valid.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeArBeValid

Returns a new instance of ArBeValid.



7
8
9
10
# File 'lib/spec/rails/matchers/ar_be_valid.rb', line 7

def initialize
  @matcher = Spec::Matchers::Be.new :be_valid
  @matcher.__send__ :handling_predicate!
end

Instance Method Details

#descriptionObject



30
31
32
# File 'lib/spec/rails/matchers/ar_be_valid.rb', line 30

def description
  "be valid"
end

#failure_message_for_shouldObject



17
18
19
20
21
22
23
24
# File 'lib/spec/rails/matchers/ar_be_valid.rb', line 17

def failure_message_for_should
  if @actual.respond_to?(:errors) &&
      ActiveRecord::Errors === @actual.errors
    "Expected #{@actual.inspect} to be valid, but it was not\nErrors: " + @actual.errors.full_messages.join(", ")            
  else
    @matcher.failure_message_for_should
  end
end

#failure_message_for_should_notObject



26
27
28
# File 'lib/spec/rails/matchers/ar_be_valid.rb', line 26

def failure_message_for_should_not
  @matcher.failure_message_for_should_not
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
# File 'lib/spec/rails/matchers/ar_be_valid.rb', line 12

def matches?(actual)
  @actual = actual
  @matcher.matches? @actual
end