Class: MotionSpec::Matcher::BeWithin
- Defined in:
- lib/motion-spec/matcher/be_within.rb
Constant Summary collapse
- INVALID_MATCH_ERROR =
'be_within matcher incomplete. Missing .of value'
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.
7 8 9 |
# File 'lib/motion-spec/matcher/be_within.rb', line 7 def initialize(range) @range = range end |
Instance Method Details
#fail!(subject, negated) ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/motion-spec/matcher/be_within.rb', line 21 def fail!(subject, negated) fail FailedExpectation.new( FailMessageRenderer.( negated, subject, @range, @center_value ) ) end |
#matches?(subject) ⇒ Boolean
16 17 18 19 |
# File 'lib/motion-spec/matcher/be_within.rb', line 16 def matches?(subject) fail InvalidMatcher.new(INVALID_MATCH_ERROR) unless @center_value (subject - @center_value).abs <= @range end |
#of(center_value) ⇒ Object
11 12 13 14 |
# File 'lib/motion-spec/matcher/be_within.rb', line 11 def of(center_value) @center_value = center_value self end |