# File lib/rspec/matchers/built_in/be_within.rb, line 5 def initialize(delta) @delta = delta end
# File lib/rspec/matchers/built_in/be_within.rb, line 29 def description "be within #{@delta} of #{@expected}" end
# File lib/rspec/matchers/built_in/be_within.rb, line 21 def failure_message_for_should "expected #{@actual} to #{description}" end
# File lib/rspec/matchers/built_in/be_within.rb, line 25 def failure_message_for_should_not "expected #{@actual} not to #{description}" end
# 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
# File lib/rspec/matchers/built_in/be_within.rb, line 16 def of(expected) @expected = expected self end
# File lib/rspec/matchers/built_in/be_within.rb, line 39 def needs_expected ArgumentError.new "You must set an expected value using #of: be_within(#{@delta}).of(expected_value)" end
# File lib/rspec/matchers/built_in/be_within.rb, line 35 def needs_subtractable ArgumentError.new "The actual value (#{@actual.inspect}) must respond to `-`" end