class MiniTest::Matchers::ActiveModel::ValidateExclusionMatcher

Public Class Methods

new(attr) click to toggle source
Calls superclass method
# File lib/matchers/validate_exclusion_matcher.rb, line 12
def initialize attr
  super attr, :exclusion
end

Public Instance Methods

description() click to toggle source
Calls superclass method
# File lib/matchers/validate_exclusion_matcher.rb, line 45
def description
  if Array === @not_allowed_values
    super << " not allowing the values: #{to_sentence(@not_allowed_values)}"
  elsif @not_allowed_values
    super << " not allowing the values in #{@not_allowed_values.inspect}"
  end
end
matches?(subject) click to toggle source
Calls superclass method
# File lib/matchers/validate_exclusion_matcher.rb, line 21
def matches? subject
  return false unless result = super(subject)

  if Array === @not_allowed_values
    allowed_values = @not_allowed_values - @validator.options[:in].to_a
    if allowed_values.empty?
      @positive_message << ' not allowing all values mentioned'
    else
      @negative_message << ' allowing the values:'
      @negative_message << " #{to_sentence(allowed_values)}"
      result = false
    end
  elsif @not_allowed_values
    if @not_allowed_values == @validator.options[:in]
      @positive_message << " not allowing values in #{@not_allowed_values.inspect}"
    else
      @negative_message << " not allowing values in #{@validator.options[:in].inspect}"
      result = false
    end
  end

  result
end
to_not_allow(*values) click to toggle source
# File lib/matchers/validate_exclusion_matcher.rb, line 16
def to_not_allow *values
  @not_allowed_values = (values.length > 1) ? values.flatten : values[0]
  self
end