]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/spec/spec/matchers/be_spec.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / spec / spec / matchers / be_spec.rb
1 require File.dirname(__FILE__) + '/../../spec_helper.rb'
2
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
8
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
13
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
27
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
40
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
47
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
54
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
69
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
84
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
91
92 describe "should be_true" do
93   it "should pass when actual equal(true)" do
94     true.should be_true
95   end
96
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
102 end
103
104 describe "should be_false" do
105   it "should pass when actual equal(false)" do
106     false.should be_false
107   end
108
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
114 end
115
116 describe "should be_nil" do
117   it "should pass when actual is nil" do
118     nil.should be_nil
119   end
120
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
126 end
127
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
132
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
138 end
139
140 describe "should be <" do
141   it "should pass when < operator returns true" do
142     3.should be < 4
143   end
144
145   it "should fail when < operator returns false" do
146     lambda { 3.should be < 3 }.should fail_with("expected < 3, got 3")
147   end
148 end
149
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
155
156   it "should fail when <= operator returns false" do
157     lambda { 3.should be <= 2 }.should fail_with("expected <= 2, got 3")
158   end
159 end
160
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
166
167   it "should fail when >= operator returns false" do
168     lambda { 3.should be >= 4 }.should fail_with("expected >= 4, got 3")
169   end
170 end
171
172 describe "should be >" do
173   it "should pass when > operator returns true" do
174     5.should be > 4
175   end
176
177   it "should fail when > operator returns false" do
178     lambda { 3.should be > 4 }.should fail_with("expected > 4, got 3")
179   end
180 end
181
182 describe "should be ==" do
183   it "should pass when == operator returns true" do
184     5.should be == 5
185   end
186
187   it "should fail when == operator returns false" do
188     lambda { 3.should be == 4 }.should fail_with("expected == 4, got 3")
189   end
190 end
191
192 describe "should be ===" do
193   it "should pass when === operator returns true" do
194     Hash.should be === Hash.new
195   end
196
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
200 end
201
202 describe "should be" do
203   it "should pass if actual is true or a set value" do
204     true.should be
205     1.should be
206   end
207
208   it "should fail if actual is false" do
209     lambda {false.should be}.should fail_with("expected if to be satisfied, got false")
210   end
211
212   it "should fail if actual is nil" do
213     lambda {nil.should be}.should fail_with("expected if to be satisfied, got nil")
214   end
215 end
216
217 describe "should be(value)" do
218   it "should pass if actual.equal?(value)" do
219     5.should be(5)
220   end
221   it "should fail if !actual.equal?(value)" do
222     lambda { 5.should be(6) }.should fail_with("expected 6, got 5")
223   end
224 end