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

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initializeArBeValid

Returns a new instance of ArBeValid.



8
9
10
11
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/ar_be_valid.rb', line 8

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

Instance Method Details

#descriptionObject



31
32
33
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/ar_be_valid.rb', line 31

def description
  "be valid"
end

#failure_message_for_shouldObject



18
19
20
21
22
23
24
25
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/ar_be_valid.rb', line 18

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



27
28
29
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/ar_be_valid.rb', line 27

def failure_message_for_should_not
  @matcher.failure_message_for_should_not
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
# File 'lib/vendor/plugins/rspec-rails/lib/spec/rails/matchers/ar_be_valid.rb', line 13

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