Class: RSpec::Matchers::BuiltIn::BeWithin
- Inherits:
-
Object
- Object
- RSpec::Matchers::BuiltIn::BeWithin
- Defined in:
- lib/rspec/matchers/built_in/be_within.rb
Instance Method Summary collapse
- #description ⇒ Object
- #failure_message_for_should ⇒ Object
- #failure_message_for_should_not ⇒ Object
-
#initialize(delta) ⇒ BeWithin
constructor
A new instance of BeWithin.
- #matches?(actual) ⇒ Boolean (also: #==)
- #of(expected) ⇒ Object
Constructor Details
#initialize(delta) ⇒ BeWithin
Returns a new instance of BeWithin.
5 6 7 |
# File 'lib/rspec/matchers/built_in/be_within.rb', line 5 def initialize(delta) @delta = delta end |
Instance Method Details
#description ⇒ Object
30 31 32 |
# File 'lib/rspec/matchers/built_in/be_within.rb', line 30 def description "be within #{@delta} of #{@expected}" end |
#failure_message_for_should ⇒ Object
22 23 24 |
# File 'lib/rspec/matchers/built_in/be_within.rb', line 22 def "expected #{@actual} to #{description}" end |
#failure_message_for_should_not ⇒ Object
26 27 28 |
# File 'lib/rspec/matchers/built_in/be_within.rb', line 26 def "expected #{@actual} not to #{description}" end |
#matches?(actual) ⇒ Boolean Also known as: ==
9 10 11 12 13 14 |
# File 'lib/rspec/matchers/built_in/be_within.rb', line 9 def matches?(actual) @actual = actual raise needs_expected unless defined? @expected raise needs_subtractable unless @actual.respond_to? :- (@actual - @expected).abs <= @delta end |
#of(expected) ⇒ Object
17 18 19 20 |
# File 'lib/rspec/matchers/built_in/be_within.rb', line 17 def of(expected) @expected = expected self end |