mac_bacon 1.1.21
Sign up to get free protection for your applications and to get access to all the features.
- data/COPYING +18 -0
- data/ChangeLog +272 -0
- data/RDOX +96 -0
- data/README +324 -0
- data/Rakefile +145 -0
- data/bin/macbacon +118 -0
- data/lib/mac_bacon.rb +450 -0
- data/test/spec_bacon.rb +390 -0
- data/test/spec_mac_bacon.rb +20 -0
- data/test/spec_nontrue.rb +16 -0
- data/test/spec_should.rb +33 -0
- metadata +86 -0
data/test/spec_bacon.rb
ADDED
@@ -0,0 +1,390 @@
|
|
1
|
+
$-w,w = nil, $-w
|
2
|
+
require File.expand_path('../../lib/mac_bacon', __FILE__)
|
3
|
+
$-w = w
|
4
|
+
|
5
|
+
# Hooray for meta-testing.
|
6
|
+
module MetaTests
|
7
|
+
def succeed
|
8
|
+
lambda { |block|
|
9
|
+
block.should.not.raise Bacon::Error
|
10
|
+
true
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def fail
|
15
|
+
lambda { |block|
|
16
|
+
block.should.raise Bacon::Error
|
17
|
+
true
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
def equal_string(x)
|
22
|
+
lambda { |s|
|
23
|
+
x == s.to_s
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "Bacon" do
|
29
|
+
extend MetaTests
|
30
|
+
|
31
|
+
it "should have should.satisfy" do
|
32
|
+
lambda { should.satisfy { 1 == 1 } }.should succeed
|
33
|
+
lambda { should.satisfy { 1 } }.should succeed
|
34
|
+
|
35
|
+
lambda { should.satisfy { 1 != 1 } }.should fail
|
36
|
+
lambda { should.satisfy { false } }.should fail
|
37
|
+
lambda { should.satisfy { false } }.should fail
|
38
|
+
|
39
|
+
lambda { 1.should.satisfy { |n| n % 2 == 0 } }.should fail
|
40
|
+
lambda { 2.should.satisfy { |n| n % 2 == 0 } }.should succeed
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should have should.equal" do
|
44
|
+
lambda { "string1".should == "string1" }.should succeed
|
45
|
+
lambda { "string1".should == "string2" }.should fail
|
46
|
+
lambda { "1".should == 1 }.should fail
|
47
|
+
|
48
|
+
lambda { "string1".should.equal "string1" }.should succeed
|
49
|
+
lambda { "string1".should.equal "string2" }.should fail
|
50
|
+
lambda { "1".should.equal 1 }.should fail
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should have should.raise" do
|
54
|
+
lambda { lambda { raise "Error" }.should.raise }.should succeed
|
55
|
+
lambda { lambda { raise "Error" }.should.raise RuntimeError }.should succeed
|
56
|
+
lambda { lambda { raise "Error" }.should.not.raise }.should fail
|
57
|
+
lambda { lambda { raise "Error" }.should.not.raise(RuntimeError) }.should fail
|
58
|
+
|
59
|
+
lambda { lambda { 1 + 1 }.should.raise }.should fail
|
60
|
+
lambda {
|
61
|
+
lambda { raise "Error" }.should.raise(Interrupt)
|
62
|
+
}.should.raise
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should have should.raise with a block" do
|
66
|
+
lambda { should.raise { raise "Error" } }.should succeed
|
67
|
+
lambda { should.raise(RuntimeError) { raise "Error" } }.should succeed
|
68
|
+
lambda { should.not.raise { raise "Error" } }.should fail
|
69
|
+
lambda { should.not.raise(RuntimeError) { raise "Error" } }.should fail
|
70
|
+
|
71
|
+
lambda { should.raise { 1 + 1 } }.should fail
|
72
|
+
lambda {
|
73
|
+
should.raise(Interrupt) { raise "Error" }
|
74
|
+
}.should.raise
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should have a should.raise should return the exception" do
|
78
|
+
ex = lambda { raise "foo!" }.should.raise
|
79
|
+
ex.should.be.kind_of RuntimeError
|
80
|
+
ex.message.should =~ /foo/
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should have should.be.an.instance_of" do
|
84
|
+
lambda { "string".should.be.instance_of String }.should succeed
|
85
|
+
lambda { "string".should.be.instance_of Hash }.should fail
|
86
|
+
|
87
|
+
lambda { "string".should.be.an.instance_of String }.should succeed
|
88
|
+
lambda { "string".should.be.an.instance_of Hash }.should fail
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should have should.be.nil" do
|
92
|
+
lambda { nil.should.be.nil }.should succeed
|
93
|
+
lambda { nil.should.not.be.nil }.should fail
|
94
|
+
lambda { "foo".should.be.nil }.should fail
|
95
|
+
lambda { "foo".should.not.be.nil }.should succeed
|
96
|
+
end
|
97
|
+
|
98
|
+
it "should have should.include" do
|
99
|
+
lambda { [1,2,3].should.include 2 }.should succeed
|
100
|
+
lambda { [1,2,3].should.include 4 }.should fail
|
101
|
+
|
102
|
+
lambda { {1=>2, 3=>4}.should.include 1 }.should succeed
|
103
|
+
lambda { {1=>2, 3=>4}.should.include 2 }.should fail
|
104
|
+
end
|
105
|
+
|
106
|
+
it "should have should.be.a.kind_of" do
|
107
|
+
lambda { Array.should.be.kind_of Module }.should succeed
|
108
|
+
lambda { "string".should.be.kind_of Object }.should succeed
|
109
|
+
lambda { 1.should.be.kind_of Comparable }.should succeed
|
110
|
+
|
111
|
+
lambda { Array.should.be.a.kind_of Module }.should succeed
|
112
|
+
|
113
|
+
lambda { "string".should.be.a.kind_of Class }.should fail
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should have should.match" do
|
117
|
+
lambda { "string".should.match(/strin./) }.should succeed
|
118
|
+
lambda { "string".should =~ /strin./ }.should succeed
|
119
|
+
|
120
|
+
lambda { "string".should.match(/slin./) }.should fail
|
121
|
+
lambda { "string".should =~ /slin./ }.should fail
|
122
|
+
end
|
123
|
+
|
124
|
+
it "should have should.not.raise" do
|
125
|
+
lambda { lambda { 1 + 1 }.should.not.raise }.should succeed
|
126
|
+
lambda { lambda { 1 + 1 }.should.not.raise(Interrupt) }.should succeed
|
127
|
+
|
128
|
+
lambda {
|
129
|
+
lambda {
|
130
|
+
lambda {
|
131
|
+
Kernel.raise ZeroDivisionError.new("ArgumentError")
|
132
|
+
}.should.not.raise(RuntimeError, Comparable)
|
133
|
+
}.should.raise ZeroDivisionError
|
134
|
+
}.should succeed
|
135
|
+
|
136
|
+
lambda { lambda { raise "Error" }.should.not.raise }.should fail
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should have should.throw" do
|
140
|
+
lambda { lambda { throw :foo }.should.throw(:foo) }.should succeed
|
141
|
+
lambda { lambda { :foo }.should.throw(:foo) }.should fail
|
142
|
+
|
143
|
+
should.throw(:foo) { throw :foo }
|
144
|
+
end
|
145
|
+
|
146
|
+
it "should have should.not.satisfy" do
|
147
|
+
lambda { should.not.satisfy { 1 == 2 } }.should succeed
|
148
|
+
lambda { should.not.satisfy { 1 == 1 } }.should fail
|
149
|
+
end
|
150
|
+
|
151
|
+
it "should have should.not.equal" do
|
152
|
+
lambda { "string1".should.not == "string2" }.should succeed
|
153
|
+
lambda { "string1".should.not == "string1" }.should fail
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should have should.not.match" do
|
157
|
+
lambda { "string".should.not.match(/sling/) }.should succeed
|
158
|
+
lambda { "string".should.not.match(/string/) }.should fail
|
159
|
+
# lambda { "string".should.not.match("strin") }.should fail
|
160
|
+
|
161
|
+
lambda { "string".should.not =~ /sling/ }.should succeed
|
162
|
+
lambda { "string".should.not =~ /string/ }.should fail
|
163
|
+
# lambda { "string".should.not =~ "strin" }.should fail
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should have should.be.identical_to/same_as" do
|
167
|
+
lambda { s = "string"; s.should.be.identical_to s }.should succeed
|
168
|
+
lambda { "string".should.be.identical_to "string" }.should fail
|
169
|
+
|
170
|
+
lambda { s = "string"; s.should.be.same_as s }.should succeed
|
171
|
+
lambda { "string".should.be.same_as "string" }.should fail
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should have should.respond_to" do
|
175
|
+
lambda { "foo".should.respond_to :to_s }.should succeed
|
176
|
+
lambda { 5.should.respond_to :to_str }.should fail
|
177
|
+
lambda { :foo.should.respond_to :nx }.should fail
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should have should.be.close" do
|
181
|
+
lambda { 1.4.should.be.close 1.4, 0 }.should succeed
|
182
|
+
lambda { 0.4.should.be.close 0.5, 0.1 }.should succeed
|
183
|
+
|
184
|
+
lambda { 0.4.should.be.close 0.5, 0.05 }.should fail
|
185
|
+
lambda { 0.4.should.be.close Object.new, 0.1 }.should fail
|
186
|
+
lambda { 0.4.should.be.close 0.5, -0.1 }.should fail
|
187
|
+
end
|
188
|
+
|
189
|
+
it "should support multiple negation" do
|
190
|
+
lambda { 1.should.equal 1 }.should succeed
|
191
|
+
lambda { 1.should.not.equal 1 }.should fail
|
192
|
+
lambda { 1.should.not.not.equal 1 }.should succeed
|
193
|
+
lambda { 1.should.not.not.not.equal 1 }.should fail
|
194
|
+
|
195
|
+
lambda { 1.should.equal 2 }.should fail
|
196
|
+
lambda { 1.should.not.equal 2 }.should succeed
|
197
|
+
lambda { 1.should.not.not.equal 2 }.should fail
|
198
|
+
lambda { 1.should.not.not.not.equal 2 }.should succeed
|
199
|
+
end
|
200
|
+
|
201
|
+
it "should have should.<predicate>" do
|
202
|
+
lambda { [].should.be.empty }.should succeed
|
203
|
+
lambda { [1,2,3].should.not.be.empty }.should succeed
|
204
|
+
|
205
|
+
lambda { [].should.not.be.empty }.should fail
|
206
|
+
lambda { [1,2,3].should.be.empty }.should fail
|
207
|
+
|
208
|
+
lambda { {1=>2, 3=>4}.should.has_key 1 }.should succeed
|
209
|
+
lambda { {1=>2, 3=>4}.should.not.has_key 2 }.should succeed
|
210
|
+
|
211
|
+
lambda { nil.should.bla }.should.raise(NoMethodError)
|
212
|
+
lambda { nil.should.not.bla }.should.raise(NoMethodError)
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should have should <operator> (>, >=, <, <=, ===)" do
|
216
|
+
lambda { 2.should.be > 1 }.should succeed
|
217
|
+
lambda { 1.should.be > 2 }.should fail
|
218
|
+
|
219
|
+
lambda { 1.should.be < 2 }.should succeed
|
220
|
+
lambda { 2.should.be < 1 }.should fail
|
221
|
+
|
222
|
+
lambda { 2.should.be >= 1 }.should succeed
|
223
|
+
lambda { 2.should.be >= 2 }.should succeed
|
224
|
+
lambda { 2.should.be >= 2.1 }.should fail
|
225
|
+
|
226
|
+
lambda { 2.should.be <= 1 }.should fail
|
227
|
+
lambda { 2.should.be <= 2 }.should succeed
|
228
|
+
lambda { 2.should.be <= 2.1 }.should succeed
|
229
|
+
|
230
|
+
lambda { Array.should === [1,2,3] }.should succeed
|
231
|
+
lambda { Integer.should === [1,2,3] }.should fail
|
232
|
+
|
233
|
+
lambda { /foo/.should === "foobar" }.should succeed
|
234
|
+
lambda { "foobar".should === /foo/ }.should fail
|
235
|
+
end
|
236
|
+
|
237
|
+
it "should allow for custom shoulds" do
|
238
|
+
lambda { (1+1).should equal_string("2") }.should succeed
|
239
|
+
lambda { (1+2).should equal_string("2") }.should fail
|
240
|
+
|
241
|
+
lambda { (1+1).should.be equal_string("2") }.should succeed
|
242
|
+
lambda { (1+2).should.be equal_string("2") }.should fail
|
243
|
+
|
244
|
+
lambda { (1+1).should.not equal_string("2") }.should fail
|
245
|
+
lambda { (1+2).should.not equal_string("2") }.should succeed
|
246
|
+
lambda { (1+2).should.not.not equal_string("2") }.should fail
|
247
|
+
|
248
|
+
lambda { (1+1).should.not.be equal_string("2") }.should fail
|
249
|
+
lambda { (1+2).should.not.be equal_string("2") }.should succeed
|
250
|
+
end
|
251
|
+
|
252
|
+
it "should have should.flunk" do
|
253
|
+
lambda { should.flunk }.should fail
|
254
|
+
lambda { should.flunk "yikes" }.should fail
|
255
|
+
end
|
256
|
+
end
|
257
|
+
|
258
|
+
describe "before/after" do
|
259
|
+
before do
|
260
|
+
@a = 1
|
261
|
+
@b = 2
|
262
|
+
end
|
263
|
+
|
264
|
+
before do
|
265
|
+
@a = 2
|
266
|
+
end
|
267
|
+
|
268
|
+
after do
|
269
|
+
@a.should.equal 2
|
270
|
+
@a = 3
|
271
|
+
end
|
272
|
+
|
273
|
+
after do
|
274
|
+
@a.should.equal 3
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should run in the right order" do
|
278
|
+
@a.should.equal 2
|
279
|
+
@b.should.equal 2
|
280
|
+
end
|
281
|
+
|
282
|
+
describe "when nested" do
|
283
|
+
before do
|
284
|
+
@c = 5
|
285
|
+
end
|
286
|
+
|
287
|
+
it "should run from higher level" do
|
288
|
+
@a.should.equal 2
|
289
|
+
@b.should.equal 2
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should run at the nested level" do
|
293
|
+
@c.should.equal 5
|
294
|
+
end
|
295
|
+
|
296
|
+
before do
|
297
|
+
@a = 5
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should run in the right order" do
|
301
|
+
@a.should.equal 5
|
302
|
+
@a = 2
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
it "should not run from lower level" do
|
307
|
+
@c.should.be.nil
|
308
|
+
end
|
309
|
+
|
310
|
+
describe "when nested at a sibling level" do
|
311
|
+
it "should not run from sibling level" do
|
312
|
+
@c.should.be.nil
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
shared "a shared context" do
|
318
|
+
it "gets called where it is included" do
|
319
|
+
true.should.be.true
|
320
|
+
end
|
321
|
+
end
|
322
|
+
|
323
|
+
shared "another shared context" do
|
324
|
+
it "can access data" do
|
325
|
+
@magic.should.be.equal 42
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
describe "shared/behaves_like" do
|
330
|
+
behaves_like "a shared context"
|
331
|
+
|
332
|
+
ctx = self
|
333
|
+
it "raises NameError when the context is not found" do
|
334
|
+
lambda {
|
335
|
+
ctx.behaves_like "whoops"
|
336
|
+
}.should.raise NameError
|
337
|
+
end
|
338
|
+
|
339
|
+
behaves_like "a shared context"
|
340
|
+
|
341
|
+
before {
|
342
|
+
@magic = 42
|
343
|
+
}
|
344
|
+
behaves_like "another shared context"
|
345
|
+
end
|
346
|
+
|
347
|
+
describe "Methods" do
|
348
|
+
def the_meaning_of_life
|
349
|
+
42
|
350
|
+
end
|
351
|
+
|
352
|
+
it "should be accessible in a test" do
|
353
|
+
the_meaning_of_life.should == 42
|
354
|
+
end
|
355
|
+
|
356
|
+
describe "when in a sibling context" do
|
357
|
+
it "should be accessible in a test" do
|
358
|
+
the_meaning_of_life.should == 42
|
359
|
+
end
|
360
|
+
end
|
361
|
+
end
|
362
|
+
|
363
|
+
describe 'describe arguments' do
|
364
|
+
|
365
|
+
def check(ctx,name)
|
366
|
+
ctx.should.be.an.instance_of Bacon::Context
|
367
|
+
ctx.instance_variable_get('@name').should == name
|
368
|
+
end
|
369
|
+
|
370
|
+
it 'should work with string' do
|
371
|
+
check(describe('string') {},'string')
|
372
|
+
end
|
373
|
+
|
374
|
+
it 'should work with symbols' do
|
375
|
+
check(describe(:behaviour) {},'behaviour')
|
376
|
+
end
|
377
|
+
|
378
|
+
it 'should work with modules' do
|
379
|
+
check(describe(Bacon) {},'Bacon')
|
380
|
+
end
|
381
|
+
|
382
|
+
it 'should work with namespaced modules' do
|
383
|
+
check(describe(Bacon::Context) {},'Bacon::Context')
|
384
|
+
end
|
385
|
+
|
386
|
+
it 'should work with multiple arguments' do
|
387
|
+
check(describe(Bacon::Context, :empty) {},'Bacon::Context empty')
|
388
|
+
end
|
389
|
+
|
390
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path('../../lib/mac_bacon', __FILE__)
|
2
|
+
|
3
|
+
describe "NSRunloop aware Bacon" do
|
4
|
+
it "allows the user to postpone execution of a block for n seconds, which will halt any further execution of specs" do
|
5
|
+
started_at_1 = started_at_2 = started_at_3 = Time.now
|
6
|
+
number_of_specs_before = Bacon::Counter[:specifications]
|
7
|
+
|
8
|
+
wait 0.5 do
|
9
|
+
(Time.now - started_at_1).should.be.close(0.5, 0.5)
|
10
|
+
end
|
11
|
+
wait 1 do
|
12
|
+
(Time.now - started_at_2).should.be.close(1, 0.5)
|
13
|
+
wait 1.5 do
|
14
|
+
(Time.now - started_at_3).should.be.close(2.5, 0.5)
|
15
|
+
Bacon::Counter[:specifications].should == number_of_specs_before
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require File.expand_path('../../lib/mac_bacon', __FILE__)
|
2
|
+
|
3
|
+
$false_is_not_true = false.should.not.be.true
|
4
|
+
$nil_is_not_true = nil.should.not.be.true
|
5
|
+
|
6
|
+
describe 'A non-true value' do
|
7
|
+
it 'should pass negated tests inside specs' do
|
8
|
+
false.should.not.be.true
|
9
|
+
nil.should.not.be.true
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'should pass negated tests outside specs' do
|
13
|
+
$false_is_not_true.should.be.true
|
14
|
+
$nil_is_not_true.should.be.true
|
15
|
+
end
|
16
|
+
end
|
data/test/spec_should.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path('../../lib/mac_bacon', __FILE__)
|
2
|
+
|
3
|
+
describe "#should shortcut for #it('should')" do
|
4
|
+
|
5
|
+
should "be called" do
|
6
|
+
@called = true
|
7
|
+
@called.should.be == true
|
8
|
+
end
|
9
|
+
|
10
|
+
should "save some characters by typing should" do
|
11
|
+
lambda { should.satisfy { 1 == 1 } }.should.not.raise
|
12
|
+
end
|
13
|
+
|
14
|
+
should "save characters even on failure" do
|
15
|
+
lambda { should.satisfy { 1 == 2 } }.should.raise Bacon::Error
|
16
|
+
end
|
17
|
+
|
18
|
+
should "work nested" do
|
19
|
+
should.satisfy {1==1}
|
20
|
+
end
|
21
|
+
|
22
|
+
count = Bacon::Counter[:specifications]
|
23
|
+
should "add new specifications" do
|
24
|
+
# XXX this should +=1 but it's +=2
|
25
|
+
# What?
|
26
|
+
(count+2).should == Bacon::Counter[:specifications]
|
27
|
+
end
|
28
|
+
|
29
|
+
should "have been called" do
|
30
|
+
@called.should.be == true
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|