class Mongoid::Matchers::Validations::ValidateWithCustomValidatorMatcher

Public Class Methods

new(field) click to toggle source
# File lib/matchers/validations/custom_validation_of.rb, line 6
def initialize(field)
  super(field, :custom)
end

Public Instance Methods

description() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/matchers/validations/custom_validation_of.rb, line 10
def with_validator(custom_validator)
  @custom_validator = custom_validator
  self
end

Private Instance Methods

check_custom_validator() click to toggle source
# File lib/matchers/validations/custom_validation_of.rb, line 32
def check_custom_validator
  if @validator.kind_of? @custom_validator
    @positive_result_message << " with custom validator of type #{@custom_validator.name}"
  else
    @negative_result_message << " with custom validator not of type #{@custom_validator.name}"
    @result = false
  end
end