changelog shortlog tags changeset manifest revisions annotate raw

vendor/plugins/rspec/spec/spec/matchers/be_close_spec.rb

changeset 15: 64acf98d15f4
author: moriq@moriq.com
date: Mon Mar 10 10:12:58 2008 +0900 (16 years ago)
permissions: -rw-r--r--
description: add plugins rspec
1require File.dirname(__FILE__) + '/../../spec_helper.rb'
2module Spec
3 module Matchers
4 describe BeClose do
5 it "should match when value == target" do
6 BeClose.new(5.0, 0.5).matches?(5.0).should be_true
7 end
8 it "should match when value < (target + delta)" do
9 BeClose.new(5.0, 0.5).matches?(5.49).should be_true
10 end
11 it "should match when value > (target - delta)" do
12 BeClose.new(5.0, 0.5).matches?(4.51).should be_true
13 end
14 it "should not match when value == (target - delta)" do
15 BeClose.new(5.0, 0.5).matches?(4.5).should be_false
16 end
17 it "should not match when value < (target - delta)" do
18 BeClose.new(5.0, 0.5).matches?(4.49).should be_false
19 end
20 it "should not match when value == (target + delta)" do
21 BeClose.new(5.0, 0.5).matches?(5.5).should be_false
22 end
23 it "should not match when value > (target + delta)" do
24 BeClose.new(5.0, 0.5).matches?(5.51).should be_false
25 end
26 it "should provide a useful failure message" do
27 #given
28 matcher = BeClose.new(5.0, 0.5)
29 #when
30 matcher.matches?(5.51)
31 #then
32 matcher.failure_message.should == "expected 5.0 +/- (< 0.5), got 5.51"
33 end
34 it "should describe itself" do
35 BeClose.new(5.0, 0.5).description.should == "be close to 5.0 (within +- 0.5)"
36 end
37 end
38 end
39end