schmurfy-bacon 1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +8 -0
- data/COPYING +18 -0
- data/README +290 -0
- data/Rakefile +119 -0
- data/bacon.gemspec +30 -0
- data/bin/bacon +118 -0
- data/lib/autotest/bacon.rb +36 -0
- data/lib/autotest/bacon_rspec.rb +2 -0
- data/lib/autotest/discover.rb +9 -0
- data/lib/bacon.rb +300 -0
- data/lib/bacon/version.rb +3 -0
- data/lib/output/better_output.rb +44 -0
- data/lib/output/knock_output.rb +16 -0
- data/lib/output/spec_dox_output.rb +23 -0
- data/lib/output/tap_output.rb +21 -0
- data/lib/output/test_unit_output.rb +19 -0
- data/test/spec_bacon.rb +390 -0
- data/test/spec_nontrue.rb +14 -0
- data/test/spec_should.rb +32 -0
- metadata +83 -0
@@ -0,0 +1,44 @@
|
|
1
|
+
|
2
|
+
require 'term/ansicolor'
|
3
|
+
|
4
|
+
Color = Term::ANSIColor
|
5
|
+
|
6
|
+
module BetterOutput
|
7
|
+
def handle_specification(name)
|
8
|
+
puts "\n#{spaces('-')}#{Color.underscore}#{name}#{Color.reset}"
|
9
|
+
yield
|
10
|
+
puts if Counter[:context_depth] == 1
|
11
|
+
end
|
12
|
+
|
13
|
+
def handle_requirement(description)
|
14
|
+
print "#{spaces} ~ #{description}"
|
15
|
+
error_type, err = yield
|
16
|
+
|
17
|
+
# goto beginning of line
|
18
|
+
print "\e[G\e[K"
|
19
|
+
|
20
|
+
case error_type
|
21
|
+
when ""
|
22
|
+
puts "#{spaces} #{Color.green}✔#{Color.reset} #{description}"
|
23
|
+
|
24
|
+
when :failed
|
25
|
+
puts "#{spaces} #{Color.red}✘#{Color.reset} #{description}"
|
26
|
+
|
27
|
+
when :error
|
28
|
+
# ❍ ☻
|
29
|
+
puts "#{spaces} #{Color.red}☁ #{description}#{Color.reset} [#{err.class}]"
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
def handle_summary
|
36
|
+
print ErrorLog if Backtraces
|
37
|
+
puts "%d specifications (%d requirements), %d failures, %d errors" %
|
38
|
+
Counter.values_at(:specifications, :requirements, :failed, :errors)
|
39
|
+
end
|
40
|
+
|
41
|
+
def spaces(str = " ")
|
42
|
+
str * 2 * (Counter[:context_depth] - 1)
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module KnockOutput
|
2
|
+
def handle_specification(name) yield end
|
3
|
+
|
4
|
+
def handle_requirement(description)
|
5
|
+
ErrorLog.replace ""
|
6
|
+
error = yield
|
7
|
+
if error.empty?
|
8
|
+
puts "ok - %s" % [description]
|
9
|
+
else
|
10
|
+
puts "not ok - %s: %s" % [description, error]
|
11
|
+
puts ErrorLog.strip.gsub(/^/, '# ') if Backtraces
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def handle_summary; end
|
16
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SpecDoxOutput
|
2
|
+
def handle_specification(name)
|
3
|
+
puts spaces + name
|
4
|
+
yield
|
5
|
+
puts if Counter[:context_depth] == 1
|
6
|
+
end
|
7
|
+
|
8
|
+
def handle_requirement(description)
|
9
|
+
print "#{spaces} - #{description}"
|
10
|
+
error = yield
|
11
|
+
puts error.empty? ? "" : " [#{error}]"
|
12
|
+
end
|
13
|
+
|
14
|
+
def handle_summary
|
15
|
+
print ErrorLog if Backtraces
|
16
|
+
puts "%d specifications (%d requirements), %d failures, %d errors" %
|
17
|
+
Counter.values_at(:specifications, :requirements, :failed, :errors)
|
18
|
+
end
|
19
|
+
|
20
|
+
def spaces
|
21
|
+
" " * (Counter[:context_depth] - 1)
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module TapOutput
|
2
|
+
def handle_specification(name) yield end
|
3
|
+
|
4
|
+
def handle_requirement(description)
|
5
|
+
ErrorLog.replace ""
|
6
|
+
error = yield
|
7
|
+
if error.empty?
|
8
|
+
puts "ok %-3d - %s" % [Counter[:specifications], description]
|
9
|
+
else
|
10
|
+
puts "not ok %d - %s: %s" %
|
11
|
+
[Counter[:specifications], description, error]
|
12
|
+
puts ErrorLog.strip.gsub(/^/, '# ') if Backtraces
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def handle_summary
|
17
|
+
puts "1..#{Counter[:specifications]}"
|
18
|
+
puts "# %d tests, %d assertions, %d failures, %d errors" %
|
19
|
+
Counter.values_at(:specifications, :requirements, :failed, :errors)
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module TestUnitOutput
|
2
|
+
def handle_specification(name) yield end
|
3
|
+
|
4
|
+
def handle_requirement(description)
|
5
|
+
error = yield
|
6
|
+
if error.empty?
|
7
|
+
print "."
|
8
|
+
else
|
9
|
+
print error[0..0]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def handle_summary
|
14
|
+
puts "", "Finished in #{Time.now - @timer} seconds."
|
15
|
+
puts ErrorLog if Backtraces
|
16
|
+
puts "%d tests, %d assertions, %d failures, %d errors" %
|
17
|
+
Counter.values_at(:specifications, :requirements, :failed, :errors)
|
18
|
+
end
|
19
|
+
end
|
data/test/spec_bacon.rb
ADDED
@@ -0,0 +1,390 @@
|
|
1
|
+
$-w,w = nil, $-w
|
2
|
+
require File.expand_path('../../lib/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
|