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)
9
it "should pass when actual returns true for :predicates? (present tense)" do
10
actual = stub("actual", :exists? => true)
11
actual.should be_exist
14
it "should fail when actual returns false for :predicate?" do
15
actual = stub("actual", :happy? => false)
17
actual.should be_happy
18
}.should fail_with("expected happy? to return true, got false")
21
it "should fail when actual does not respond to :predicate?" do
23
Object.new.should be_happy
24
}.should raise_error(NameError)
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
34
it "should fail when actual returns true for :sym?" do
35
actual = stub("actual", :happy? => true)
37
actual.should_not be_happy
38
}.should fail_with("expected happy? to return false, got true")
41
it "should fail when actual does not respond to :sym?" do
43
Object.new.should_not be_happy
44
}.should raise_error(NameError)
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)
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)
59
actual.should be_older_than(3)
60
}.should fail_with("expected older_than?(3) to return true, got false")
63
it "should fail when actual does not respond to :predicate?" do
65
Object.new.should be_older_than(3)
66
}.should raise_error(NameError)
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)
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)
81
actual.should_not be_older_than(3)
82
}.should fail_with("expected older_than?(3) to return false, got true")
85
it "should fail when actual does not respond to :predicate?" do
87
Object.new.should_not be_older_than(3)
88
}.should raise_error(NameError)
92
describe "should be_true" do
93
it "should pass when actual equal(true)" do
97
it "should fail when actual equal(false)" do
100
}.should fail_with("expected true, got false")
104
describe "should be_false" do
105
it "should pass when actual equal(false)" do
106
false.should be_false
109
it "should fail when actual equal(true)" do
112
}.should fail_with("expected false, got true")
116
describe "should be_nil" do
117
it "should pass when actual is nil" do
121
it "should fail when actual is not nil" do
123
:not_nil.should be_nil
124
}.should fail_with("expected nil, got :not_nil")
128
describe "should_not be_nil" do
129
it "should pass when actual is not nil" do
130
:not_nil.should_not be_nil
133
it "should fail when actual is nil" do
135
nil.should_not be_nil
136
}.should fail_with("expected not nil, got nil")
140
describe "should be <" do
141
it "should pass when < operator returns true" do
145
it "should fail when < operator returns false" do
146
lambda { 3.should be < 3 }.should fail_with("expected < 3, got 3")
150
describe "should be <=" do
151
it "should pass when <= operator returns true" do
156
it "should fail when <= operator returns false" do
157
lambda { 3.should be <= 2 }.should fail_with("expected <= 2, got 3")
161
describe "should be >=" do
162
it "should pass when >= operator returns true" do
167
it "should fail when >= operator returns false" do
168
lambda { 3.should be >= 4 }.should fail_with("expected >= 4, got 3")
172
describe "should be >" do
173
it "should pass when > operator returns true" do
177
it "should fail when > operator returns false" do
178
lambda { 3.should be > 4 }.should fail_with("expected > 4, got 3")
182
describe "should be ==" do
183
it "should pass when == operator returns true" do
187
it "should fail when == operator returns false" do
188
lambda { 3.should be == 4 }.should fail_with("expected == 4, got 3")
192
describe "should be ===" do
193
it "should pass when === operator returns true" do
194
Hash.should be === Hash.new
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])
202
describe "should be" do
203
it "should pass if actual is true or a set value" do
208
it "should fail if actual is false" do
209
lambda {false.should be}.should fail_with("expected if to be satisfied, got false")
212
it "should fail if actual is nil" do
213
lambda {nil.should be}.should fail_with("expected if to be satisfied, got nil")
217
describe "should be(value)" do
218
it "should pass if actual.equal?(value)" do
221
it "should fail if !actual.equal?(value)" do
222
lambda { 5.should be(6) }.should fail_with("expected 6, got 5")