summaryrefslogtreecommitdiff
path: root/spec/mspec/spec/matchers/be_close_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/mspec/spec/matchers/be_close_spec.rb')
-rw-r--r--spec/mspec/spec/matchers/be_close_spec.rb46
1 files changed, 46 insertions, 0 deletions
diff --git a/spec/mspec/spec/matchers/be_close_spec.rb b/spec/mspec/spec/matchers/be_close_spec.rb
new file mode 100644
index 0000000000..3ced61dc7a
--- /dev/null
+++ b/spec/mspec/spec/matchers/be_close_spec.rb
@@ -0,0 +1,46 @@
+require 'spec_helper'
+require 'mspec/expectations/expectations'
+require 'mspec/matchers'
+
+# Adapted from RSpec 1.0.8
+describe BeCloseMatcher do
+ it "matches when actual == expected" do
+ BeCloseMatcher.new(5.0, 0.5).matches?(5.0).should == true
+ end
+
+ it "matches when actual < (expected + tolerance)" do
+ BeCloseMatcher.new(5.0, 0.5).matches?(5.49).should == true
+ end
+
+ it "matches when actual > (expected - tolerance)" do
+ BeCloseMatcher.new(5.0, 0.5).matches?(4.51).should == true
+ end
+
+ it "does not match when actual == (expected + tolerance)" do
+ BeCloseMatcher.new(5.0, 0.5).matches?(5.5).should == false
+ end
+
+ it "does not match when actual == (expected - tolerance)" do
+ BeCloseMatcher.new(5.0, 0.5).matches?(4.5).should == false
+ end
+
+ it "does not match when actual < (expected - tolerance)" do
+ BeCloseMatcher.new(5.0, 0.5).matches?(4.49).should == false
+ end
+
+ it "does not match when actual > (expected + tolerance)" do
+ BeCloseMatcher.new(5.0, 0.5).matches?(5.51).should == false
+ end
+
+ it "provides a useful failure message" do
+ matcher = BeCloseMatcher.new(5.0, 0.5)
+ matcher.matches?(5.5)
+ matcher.failure_message.should == ["Expected 5.0", "to be within +/- 0.5 of 5.5"]
+ end
+
+ it "provides a useful negative failure message" do
+ matcher = BeCloseMatcher.new(5.0, 0.5)
+ matcher.matches?(5.0)
+ matcher.negative_failure_message.should == ["Expected 5.0", "not to be within +/- 0.5 of 5.0"]
+ end
+end