Upgraded Rails and RSpec
[monkeycharger.git] / vendor / plugins / rspec / spec / spec / matchers / be_spec.rb
blob84653873c6a946de379b3ddb611be0113b074b47
1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
3 describe "should be_predicate" do  
4   it "should pass when actual returns true for :predicate?" do
5     actual = stub("actual", :happy? => true)
6     actual.should be_happy
7   end
9   it "should pass when actual returns true for :predicates? (present tense)" do
10     actual = stub("actual", :exists? => true)
11     actual.should be_exist
12   end
14   it "should fail when actual returns false for :predicate?" do
15     actual = stub("actual", :happy? => false)
16     lambda {
17       actual.should be_happy
18     }.should fail_with("expected happy? to return true, got false")
19   end
20   
21   it "should fail when actual does not respond to :predicate?" do
22     lambda {
23       Object.new.should be_happy
24     }.should raise_error(NameError)
25   end
26 end
28 describe "should_not be_predicate" do
29   it "should pass when actual returns false for :sym?" do
30     actual = stub("actual", :happy? => false)
31     actual.should_not be_happy
32   end
33   
34   it "should fail when actual returns true for :sym?" do
35     actual = stub("actual", :happy? => true)
36     lambda {
37       actual.should_not be_happy
38     }.should fail_with("expected happy? to return false, got true")
39   end
41   it "should fail when actual does not respond to :sym?" do
42     lambda {
43       Object.new.should_not be_happy
44     }.should raise_error(NameError)
45   end
46 end
48 describe "should be_predicate(*args)" do
49   it "should pass when actual returns true for :predicate?(*args)" do
50     actual = mock("actual")
51     actual.should_receive(:older_than?).with(3).and_return(true)
52     actual.should be_older_than(3)
53   end
55   it "should fail when actual returns false for :predicate?(*args)" do
56     actual = mock("actual")
57     actual.should_receive(:older_than?).with(3).and_return(false)
58     lambda {
59       actual.should be_older_than(3)
60     }.should fail_with("expected older_than?(3) to return true, got false")
61   end
62   
63   it "should fail when actual does not respond to :predicate?" do
64     lambda {
65       Object.new.should be_older_than(3)
66     }.should raise_error(NameError)
67   end
68 end
70 describe "should_not be_predicate(*args)" do
71   it "should pass when actual returns false for :predicate?(*args)" do
72     actual = mock("actual")
73     actual.should_receive(:older_than?).with(3).and_return(false)
74     actual.should_not be_older_than(3)
75   end
76   
77   it "should fail when actual returns true for :predicate?(*args)" do
78     actual = mock("actual")
79     actual.should_receive(:older_than?).with(3).and_return(true)
80     lambda {
81       actual.should_not be_older_than(3)
82     }.should fail_with("expected older_than?(3) to return false, got true")
83   end
85   it "should fail when actual does not respond to :predicate?" do
86     lambda {
87       Object.new.should_not be_older_than(3)
88     }.should raise_error(NameError)
89   end
90 end
92 describe "should be_true" do
93   it "should pass when actual equal(true)" do
94     true.should be_true
95   end
97   it "should fail when actual equal(false)" do
98     lambda {
99       false.should be_true
100     }.should fail_with("expected true, got false")
101   end
104 describe "should be_false" do
105   it "should pass when actual equal(false)" do
106     false.should be_false
107   end
109   it "should fail when actual equal(true)" do
110     lambda {
111       true.should be_false
112     }.should fail_with("expected false, got true")
113   end
116 describe "should be_nil" do
117   it "should pass when actual is nil" do
118     nil.should be_nil
119   end
121   it "should fail when actual is not nil" do
122     lambda {
123       :not_nil.should be_nil
124     }.should fail_with("expected nil, got :not_nil")
125   end
128 describe "should_not be_nil" do
129   it "should pass when actual is not nil" do
130     :not_nil.should_not be_nil
131   end
133   it "should fail when actual is nil" do
134     lambda {
135       nil.should_not be_nil
136     }.should fail_with("expected not nil, got nil")
137   end
140 describe "should be <" do
141   it "should pass when < operator returns true" do
142     3.should be < 4
143   end
145   it "should fail when < operator returns false" do
146     lambda { 3.should be < 3 }.should fail_with("expected < 3, got 3")
147   end
150 describe "should be <=" do
151   it "should pass when <= operator returns true" do
152     3.should be <= 4
153     4.should be <= 4
154   end
156   it "should fail when <= operator returns false" do
157     lambda { 3.should be <= 2 }.should fail_with("expected <= 2, got 3")
158   end
161 describe "should be >=" do
162   it "should pass when >= operator returns true" do
163     4.should be >= 4
164     5.should be >= 4
165   end
167   it "should fail when >= operator returns false" do
168     lambda { 3.should be >= 4 }.should fail_with("expected >= 4, got 3")
169   end
172 describe "should be >" do
173   it "should pass when > operator returns true" do
174     5.should be > 4
175   end
177   it "should fail when > operator returns false" do
178     lambda { 3.should be > 4 }.should fail_with("expected > 4, got 3")
179   end
182 describe "should be ==" do
183   it "should pass when == operator returns true" do
184     5.should be == 5
185   end
187   it "should fail when == operator returns false" do
188     lambda { 3.should be == 4 }.should fail_with("expected == 4, got 3")
189   end
192 describe "should be ===" do
193   it "should pass when === operator returns true" do
194     Hash.should be === Hash.new
195   end
197   it "should fail when === operator returns false" do
198     lambda { Hash.should be === "not a hash" }.should fail_with(%[expected === "not a hash", got Hash])
199   end
202 describe "should be(value)" do
203   it "should pass if actual.equal?(value)" do
204     5.should be(5)
205   end
206   it "should fail if !actual.equal?(value)" do
207     lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
208   end