Class: Mongoid::Matchers::Validations::ValidateWithCustomValidatorMatcher

Inherits:
HaveValidationMatcher show all
Includes:
WithMessage
Defined in:
lib/matchers/validations/custom_validation_of.rb

Instance Method Summary collapse

Methods included from WithMessage

#with_message

Methods inherited from HaveValidationMatcher

#check_on, #failure_message_for_should, #failure_message_for_should_not, #on

Constructor Details

#initialize(field) ⇒ ValidateWithCustomValidatorMatcher

Returns a new instance of ValidateWithCustomValidatorMatcher.



6
7
8
# File 'lib/matchers/validations/custom_validation_of.rb', line 6

def initialize(field)
  super(field, :custom)
end

Instance Method Details

#descriptionObject



23
24
25
26
27
28
# File 'lib/matchers/validations/custom_validation_of.rb', line 23

def description
  options_desc = []
  options_desc << " with custom validator #{@custom_validator.name}" if @validator
  options_desc << " with message '#{@expected_message}'" if @expected_message
  "validate field #{@field.inspect}" << options_desc.to_sentence
end

#matches?(actual) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
20
21
# File 'lib/matchers/validations/custom_validation_of.rb', line 15

def matches?(actual)
  return false unless (@result = super(actual))
  check_custom_validator if @custom_validator
  check_expected_message if @expected_message

  @result
end

#with_validator(custom_validator) ⇒ Object



10
11
12
13
# File 'lib/matchers/validations/custom_validation_of.rb', line 10

def with_validator(custom_validator)
  @custom_validator = custom_validator
  self
end