Class: BaconExpect::Matcher::BeWithin
- Inherits:
-
Object
- Object
- BaconExpect::Matcher::BeWithin
- Defined in:
- lib/bacon-expect/matchers/be_within.rb
Instance Method Summary collapse
- #fail!(subject, negated) ⇒ Object
-
#initialize(range) ⇒ BeWithin
constructor
A new instance of BeWithin.
- #matches?(subject) ⇒ Boolean
- #of(center_value) ⇒ Object
Constructor Details
#initialize(range) ⇒ BeWithin
Returns a new instance of BeWithin.
3 4 5 |
# File 'lib/bacon-expect/matchers/be_within.rb', line 3 def initialize(range) @range = range end |
Instance Method Details
#fail!(subject, negated) ⇒ Object
17 18 19 |
# File 'lib/bacon-expect/matchers/be_within.rb', line 17 def fail!(subject, negated) raise FailedExpectation.new(FailMessageRenderer.(negated, subject, @range, @center_value)) end |
#matches?(subject) ⇒ Boolean
12 13 14 15 |
# File 'lib/bacon-expect/matchers/be_within.rb', line 12 def matches?(subject) raise InvalidMatcher.new("be_within matcher incomplete. Missing .of value") unless @center_value (subject - @center_value).abs <= @range end |
#of(center_value) ⇒ Object
7 8 9 10 |
# File 'lib/bacon-expect/matchers/be_within.rb', line 7 def of(center_value) @center_value = center_value self end |