1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
5 it "should match when value == target" do
6 BeClose.new(5.0, 0.5).matches?(5.0).should be_true
8 it "should match when value < (target + delta)" do
9 BeClose.new(5.0, 0.5).matches?(5.49).should be_true
11 it "should match when value > (target - delta)" do
12 BeClose.new(5.0, 0.5).matches?(4.51).should be_true
14 it "should not match when value == (target - delta)" do
15 BeClose.new(5.0, 0.5).matches?(4.5).should be_false
17 it "should not match when value < (target - delta)" do
18 BeClose.new(5.0, 0.5).matches?(4.49).should be_false
20 it "should not match when value == (target + delta)" do
21 BeClose.new(5.0, 0.5).matches?(5.5).should be_false
23 it "should not match when value > (target + delta)" do
24 BeClose.new(5.0, 0.5).matches?(5.51).should be_false
26 it "should provide a useful failure message" do
28 matcher = BeClose.new(5.0, 0.5)
30 matcher.matches?(5.51)
32 matcher.failure_message.should == "expected 5.0 +/- (< 0.5), got 5.51"
34 it "should describe itself" do
35 BeClose.new(5.0, 0.5).description.should == "be close to 5.0 (within +- 0.5)"