Re-enable spec/library for full CI runs.
[rbx.git] / mspec / spec / matchers / be_close_spec.rb
blob1e8a8a484a6da0169db173b2f9d1e99b039c15b1
1 require File.dirname(__FILE__) + '/../spec_helper'
2 require 'mspec/expectations/expectations'
3 require 'mspec/matchers/be_close'
5 # Adapted from RSpec 1.0.8
6 describe BeCloseMatcher do
7   it "matches when actual == expected" do
8     BeCloseMatcher.new(5.0, 0.5).matches?(5.0).should == true
9   end
11   it "matches when actual < (expected + tolerance)" do
12     BeCloseMatcher.new(5.0, 0.5).matches?(5.49).should == true
13   end
15   it "matches when actual > (expected - tolerance)" do
16     BeCloseMatcher.new(5.0, 0.5).matches?(4.51).should == true
17   end
19   it "does not match when actual == (expected + tolerance)" do
20     BeCloseMatcher.new(5.0, 0.5).matches?(5.5).should == false
21   end
23   it "does not match when actual == (expected - tolerance)" do
24     BeCloseMatcher.new(5.0, 0.5).matches?(4.5).should == false
25   end
27   it "does not match when actual < (expected - tolerance)" do
28     BeCloseMatcher.new(5.0, 0.5).matches?(4.49).should == false
29   end
31   it "does not match when actual > (expected + tolerance)" do
32     BeCloseMatcher.new(5.0, 0.5).matches?(5.51).should == false
33   end
35   it "provides a useful failure message" do
36     matcher = BeCloseMatcher.new(5.0, 0.5)
37     matcher.matches?(5.51)
38     matcher.failure_message.should == ["Expected 5.0", "to be within +/- 0.5 of 5.51"]
39   end
41   it "provides a useful negative failure message" do
42     matcher = BeCloseMatcher.new(5.0, 0.5)
43     matcher.matches?(5.0)
44     matcher.negative_failure_message.should == ["Expected 5.0", "not to be within +/- 0.5 of 5.0"]
45   end
46 end