Class: BeCloseMatcher
- Defined in:
- lib/extensions/mspec/mspec/matchers/be_close.rb
Instance Method Summary collapse
- #failure_message ⇒ Object
-
#initialize(expected, tolerance) ⇒ BeCloseMatcher
constructor
A new instance of BeCloseMatcher.
- #matches?(actual) ⇒ Boolean
- #negative_failure_message ⇒ Object
Constructor Details
#initialize(expected, tolerance) ⇒ BeCloseMatcher
Returns a new instance of BeCloseMatcher.
4 5 6 7 |
# File 'lib/extensions/mspec/mspec/matchers/be_close.rb', line 4 def initialize(expected, tolerance) @expected = expected @tolerance = tolerance end |
Instance Method Details
#failure_message ⇒ Object
14 15 16 |
# File 'lib/extensions/mspec/mspec/matchers/be_close.rb', line 14 def ["Expected #{@expected}", "to be within +/- #{@tolerance} of #{@actual}"] end |
#matches?(actual) ⇒ Boolean
9 10 11 12 |
# File 'lib/extensions/mspec/mspec/matchers/be_close.rb', line 9 def matches?(actual) @actual = actual (@actual - @expected).abs < @tolerance end |
#negative_failure_message ⇒ Object
18 19 20 |
# File 'lib/extensions/mspec/mspec/matchers/be_close.rb', line 18 def ["Expected #{@expected}", "not to be within +/- #{@tolerance} of #{@actual}"] end |