Class: RSpectacular::ActiveRecord::Matchers::PositivityMatcher

Inherits:
Shoulda::ActiveRecord::Matchers::ValidateNumericalityOfMatcher
  • Object
show all
Defined in:
lib/rspectacular/matchers/active_record/positivity_matcher.rb

Instance Method Summary collapse

Instance Method Details

#descriptionObject



29
30
31
# File 'lib/rspectacular/matchers/active_record/positivity_matcher.rb', line 29

def description
  "should be contain a positive number"
end

#disallows_negative_valuesObject



20
21
22
23
# File 'lib/rspectacular/matchers/active_record/positivity_matcher.rb', line 20

def disallows_negative_values
  disallows_value_of(-1) &&
  disallows_value_of(-100)
end

#disallows_zero_valuesObject



25
26
27
# File 'lib/rspectacular/matchers/active_record/positivity_matcher.rb', line 25

def disallows_zero_values
  disallows_value_of(0)
end

#failure_messageObject



12
13
14
# File 'lib/rspectacular/matchers/active_record/positivity_matcher.rb', line 12

def failure_message
  "Expected #{@attribute.to_s} to be a positive number, got: #{pretty_error_messages(@attribute)}"
end

#matches?(positivitable) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
8
9
10
# File 'lib/rspectacular/matchers/active_record/positivity_matcher.rb', line 5

def matches?(positivitable)
  super(positivitable)

  disallows_zero_values &&
  disallows_negative_values
end

#negative_failure_messageObject



16
17
18
# File 'lib/rspectacular/matchers/active_record/positivity_matcher.rb', line 16

def negative_failure_message
  "Expected #{@attribute.to_s} to be a negative number, got: #{pretty_error_messages(@attribute)}"
end