# File lib/rspec/matchers/be_within.rb, line 8 def initialize(delta) @delta = delta end
# File lib/rspec/matchers/be_within.rb, line 32 def description "be within #{delta} of #{expected}" end
# File lib/rspec/matchers/be_within.rb, line 24 def failure_message_for_should "expected #{actual} to #{description}" end
# File lib/rspec/matchers/be_within.rb, line 28 def failure_message_for_should_not "expected #{actual} not to #{description}" end
# File lib/rspec/matchers/be_within.rb, line 12 def matches?(actual) unless defined?(@expected) raise ArgumentError.new("You must set an expected value using #of: be_within(#{delta}).of(expected_value)") end (super(actual) - expected).abs < delta end
# File lib/rspec/matchers/be_within.rb, line 19 def of(expected) @expected = expected self end