Class: RspecModelValidations::Matchers::Validate

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/rspec_model_validations/matchers/validate.rb

Overview

Test if model validation does not lead to errors on the given attribute.

Instance Method Summary collapse

Methods included from Base

#initialize, #on

Instance Method Details

#descriptionString

One line syntax description



34
# File 'lib/rspec_model_validations/matchers/validate.rb', line 34

def description; "validate #{@attribute.inspect} attribute" end

#failure_messageString

Explain why matches? fail and show errors



22
23
24
# File 'lib/rspec_model_validations/matchers/validate.rb', line 22

def failure_message
  message "#{attribute_value(@model).inspect} to be a valid value for #{@model.class}##{@attribute}", @errors
end

#failure_message_when_negatedString

Explain why matches? fail when negated



28
29
30
# File 'lib/rspec_model_validations/matchers/validate.rb', line 28

def failure_message_when_negated
  message "#{attribute_value(@model).inspect} to be an invalid value for #{@model.class}##{@attribute}", @errors
end

#matches?(model) ⇒ Boolean

Run the test

Raises:



11
12
13
14
15
16
17
18
# File 'lib/rspec_model_validations/matchers/validate.rb', line 11

def matches? model
  attribute_belongs_to! model

  @model = model
  @errors = attribute_errors model

  @errors.empty?
end