class Shoulda::Matchers::ActiveModel::ComparisonMatcher

Examples:

it { should validate_numericality_of(:attr).
              is_greater_than(6).
              less_than(20)...(and so on) }

Public Class Methods

new(value, operator) click to toggle source
# File lib/shoulda/matchers/active_model/comparison_matcher.rb, line 9
def initialize(value, operator)
  @value = value
  @operator = operator
end

Public Instance Methods

allowed_types() click to toggle source
# File lib/shoulda/matchers/active_model/comparison_matcher.rb, line 24
def allowed_types
  'integer'
end
for(attribute) click to toggle source
# File lib/shoulda/matchers/active_model/comparison_matcher.rb, line 14
def for(attribute)
  @attribute = attribute
  self
end
matches?(subject) click to toggle source
# File lib/shoulda/matchers/active_model/comparison_matcher.rb, line 19
def matches?(subject)
  @subject = subject
  disallows_value_of(value_to_compare)
end

Private Instance Methods

expectation() click to toggle source
# File lib/shoulda/matchers/active_model/comparison_matcher.rb, line 40
def expectation
  case @operator
    when :> then "greater than"
    when :>= then "greater than or equal to"
    when :== then "equal to"
    when :< then "less than"
    when :<= then "less than or equal to"
  end
end
value_to_compare() click to toggle source
# File lib/shoulda/matchers/active_model/comparison_matcher.rb, line 30
def value_to_compare
  case @operator
    when :> then [@value, @value - 1].sample
    when :>= then @value - 1
    when :== then @value + 1
    when :< then [@value, @value + 1].sample
    when :<= then @value + 1
  end
end