Examples:
it { should validate_numericality_of(:attr). is_greater_than(6). less_than(20)...(and so on) }
# File lib/shoulda/matchers/active_model/comparison_matcher.rb, line 9 def initialize(value, operator) @value = value @operator = operator end
# File lib/shoulda/matchers/active_model/comparison_matcher.rb, line 24 def allowed_types 'integer' end
# File lib/shoulda/matchers/active_model/comparison_matcher.rb, line 14 def for(attribute) @attribute = attribute self end
# File lib/shoulda/matchers/active_model/comparison_matcher.rb, line 19 def matches?(subject) @subject = subject disallows_value_of(value_to_compare) end
# 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
# 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