Class: RSpec::Matchers::BuiltIn::BeWithin Private
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- RSpec::Matchers::BuiltIn::BeWithin
- Defined in:
- lib/rspec/matchers/built_in/be_within.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Provides the implementation for be_within
.
Not intended to be instantiated directly.
Constant Summary
Constant Summary
Constants inherited from BaseMatcher
RSpec::Matchers::BuiltIn::BaseMatcher::UNDEFINED
Instance Method Summary (collapse)
- - (String) description private
- - (String) failure_message private
- - (String) failure_message_when_negated private
-
- (BeWithin) initialize(delta)
constructor
private
A new instance of BeWithin.
-
- (Object) of(expected)
Sets the expected value.
-
- (Object) percent_of(expected)
Sets the expected value, and makes the matcher do a percent comparison.
Methods inherited from BaseMatcher
#diffable?, #expects_call_stack_jump?, #match_unless_raises, #supports_block_expectations?
Methods included from Composable
#===, #and, #description_of, #or, should_enumerate?, surface_descriptions_in, unreadable_io?, #values_match?
Constructor Details
- (BeWithin) initialize(delta)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of BeWithin
8 9 10 |
# File 'lib/rspec/matchers/built_in/be_within.rb', line 8 def initialize(delta) @delta = delta end |
Instance Method Details
- (String) description
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
52 53 54 |
# File 'lib/rspec/matchers/built_in/be_within.rb', line 52 def description "be within #{@delta}#{@unit} of #{@expected}" end |
- (String) failure_message
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
40 41 42 |
# File 'lib/rspec/matchers/built_in/be_within.rb', line 40 def "expected #{actual_formatted} to #{description}#{not_numeric_clause}" end |
- (String) failure_message_when_negated
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
46 47 48 |
# File 'lib/rspec/matchers/built_in/be_within.rb', line 46 def "expected #{actual_formatted} not to #{description}" end |
- (Object) of(expected)
Sets the expected value.
14 15 16 17 18 19 |
# File 'lib/rspec/matchers/built_in/be_within.rb', line 14 def of(expected) @expected = expected @tolerance = @delta @unit = '' self end |
- (Object) percent_of(expected)
Sets the expected value, and makes the matcher do a percent comparison.
24 25 26 27 28 29 |
# File 'lib/rspec/matchers/built_in/be_within.rb', line 24 def percent_of(expected) @expected = expected @tolerance = @delta * @expected.abs / 100.0 @unit = '%' self end |