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
11 it "matches when actual < (expected + tolerance)" do
12 BeCloseMatcher.new(5.0, 0.5).matches?(5.49).should == true
15 it "matches when actual > (expected - tolerance)" do
16 BeCloseMatcher.new(5.0, 0.5).matches?(4.51).should == true
19 it "does not match when actual == (expected + tolerance)" do
20 BeCloseMatcher.new(5.0, 0.5).matches?(5.5).should == false
23 it "does not match when actual == (expected - tolerance)" do
24 BeCloseMatcher.new(5.0, 0.5).matches?(4.5).should == false
27 it "does not match when actual < (expected - tolerance)" do
28 BeCloseMatcher.new(5.0, 0.5).matches?(4.49).should == false
31 it "does not match when actual > (expected + tolerance)" do
32 BeCloseMatcher.new(5.0, 0.5).matches?(5.51).should == false
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"]
41 it "provides a useful negative failure message" do
42 matcher = BeCloseMatcher.new(5.0, 0.5)
44 matcher.negative_failure_message.should == ["Expected 5.0", "not to be within +/- 0.5 of 5.0"]