relevance-test-spec 0.4.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +1 -0
- data/Manifest +29 -0
- data/README.rdoc +394 -0
- data/ROADMAP +1 -0
- data/Rakefile +62 -0
- data/TODO +3 -0
- data/bin/specrb +107 -0
- data/examples/stack.rb +38 -0
- data/examples/stack_spec.rb +119 -0
- data/lib/test/spec.rb +731 -0
- data/lib/test/spec/dox.rb +148 -0
- data/lib/test/spec/focused/collector-extensions.rb +22 -0
- data/lib/test/spec/focused/focused.rb +30 -0
- data/lib/test/spec/rails_helper.rb +26 -0
- data/lib/test/spec/rdox.rb +25 -0
- data/lib/test/spec/should-output.rb +49 -0
- data/lib/test/spec/version.rb +8 -0
- data/test-spec.gemspec +130 -0
- data/test/helper.rb +5 -0
- data/test/spec_dox.rb +39 -0
- data/test/spec_flexmock.rb +214 -0
- data/test/spec_focused.rb +75 -0
- data/test/spec_mocha.rb +118 -0
- data/test/spec_nestedcontexts.rb +26 -0
- data/test/spec_new_style.rb +82 -0
- data/test/spec_should-output.rb +26 -0
- data/test/spec_testspec.rb +575 -0
- data/test/spec_testspec_order.rb +26 -0
- data/test/test_testunit.rb +22 -0
- metadata +127 -0
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'test/spec'
|
2
|
+
|
3
|
+
context "Empty context" do
|
4
|
+
# should.not.raise
|
5
|
+
end
|
6
|
+
|
7
|
+
context "Outer context" do
|
8
|
+
context "Inner context" do
|
9
|
+
specify "is nested" do
|
10
|
+
end
|
11
|
+
specify "has multiple empty specifications" do
|
12
|
+
end
|
13
|
+
end
|
14
|
+
context "Second Inner context" do
|
15
|
+
context "Inmost context" do
|
16
|
+
specify "works too!" do
|
17
|
+
end
|
18
|
+
specify "whoo!" do
|
19
|
+
end
|
20
|
+
end
|
21
|
+
specify "is indented properly" do
|
22
|
+
end
|
23
|
+
specify "still runs in order of definition" do
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'test/spec'
|
2
|
+
|
3
|
+
describe "A new-style description" do
|
4
|
+
before do
|
5
|
+
@before = true
|
6
|
+
@a = 2
|
7
|
+
end
|
8
|
+
|
9
|
+
before(:each) do
|
10
|
+
@before_each = true
|
11
|
+
end
|
12
|
+
|
13
|
+
before(:all) do
|
14
|
+
$before_all = true
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should run before-clauses" do
|
18
|
+
$before_all.should.be true
|
19
|
+
@before.should.be true
|
20
|
+
@before_each.should.be true
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should behave like context/specify" do
|
24
|
+
(1+1).should.equal 2
|
25
|
+
end
|
26
|
+
|
27
|
+
xit "this is disabled" do
|
28
|
+
flunk
|
29
|
+
end
|
30
|
+
|
31
|
+
pit "this is pending and no assertions yet exist"
|
32
|
+
|
33
|
+
pit "this is pending with some assertions defined, but test-spec won't run it" do
|
34
|
+
flunk
|
35
|
+
end
|
36
|
+
|
37
|
+
it "this is pending because it doesn't have a block"
|
38
|
+
|
39
|
+
after do
|
40
|
+
@a.should.equal 2
|
41
|
+
@a = 3
|
42
|
+
end
|
43
|
+
|
44
|
+
after(:each) do
|
45
|
+
@a.should.equal 3
|
46
|
+
end
|
47
|
+
|
48
|
+
after(:all) do
|
49
|
+
@b = 1
|
50
|
+
end
|
51
|
+
|
52
|
+
after(:all) do
|
53
|
+
@b.should.equal 1
|
54
|
+
end
|
55
|
+
|
56
|
+
$describescope = self
|
57
|
+
it "should raise on unimplement{ed,able} before/after" do
|
58
|
+
lambda {
|
59
|
+
$describescope.before(:foo) {}
|
60
|
+
}.should.raise(ArgumentError)
|
61
|
+
lambda {
|
62
|
+
$describescope.after(:foo) {}
|
63
|
+
}.should.raise(ArgumentError)
|
64
|
+
|
65
|
+
lambda {
|
66
|
+
context "foo" do
|
67
|
+
end
|
68
|
+
}.should.raise(Test::Spec::DefinitionError)
|
69
|
+
end
|
70
|
+
|
71
|
+
describe "when nested" do
|
72
|
+
it "should work" do
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "An empty description" do
|
78
|
+
end
|
79
|
+
|
80
|
+
xdescribe "An disabled description" do
|
81
|
+
it "should not be run"
|
82
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
$: << File.dirname(__FILE__) + '/../lib/'
|
2
|
+
require 'test/spec'
|
3
|
+
require 'test/spec/should-output'
|
4
|
+
|
5
|
+
context "should.output" do
|
6
|
+
specify "works for print" do
|
7
|
+
lambda { print "foo" }.should.output "foo"
|
8
|
+
lambda { print "foo" }.should.output(/oo/)
|
9
|
+
end
|
10
|
+
|
11
|
+
specify "works for puts" do
|
12
|
+
lambda { puts "foo" }.should.output "foo\n"
|
13
|
+
lambda { puts "foo" }.should.output(/foo/)
|
14
|
+
end
|
15
|
+
|
16
|
+
specify "works with readline" do
|
17
|
+
lambda { require 'readline' }.should.not.raise(LoadError)
|
18
|
+
lambda { puts "foo" }.should.output "foo\n"
|
19
|
+
lambda { puts "foo" }.should.output(/foo/)
|
20
|
+
|
21
|
+
File.should.not.exist(File.join(Dir.tmpdir, "should_output_#{$$}"))
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
|
@@ -0,0 +1,575 @@
|
|
1
|
+
$: << File.dirname(__FILE__) + '/../lib/'
|
2
|
+
require 'test/spec'
|
3
|
+
|
4
|
+
$WARNING = ""
|
5
|
+
class Object
|
6
|
+
def warn(msg)
|
7
|
+
$WARNING << msg.to_s
|
8
|
+
super msg
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class Test::Spec::Should
|
13
|
+
def _warn
|
14
|
+
_wrap_assertion {
|
15
|
+
begin
|
16
|
+
old, $-w = $-w, nil
|
17
|
+
$WARNING = ""
|
18
|
+
self.not.raise
|
19
|
+
$WARNING.should.blaming("no warning printed").not.be.empty
|
20
|
+
ensure
|
21
|
+
$-w = old
|
22
|
+
end
|
23
|
+
}
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# Hooray for meta-testing.
|
28
|
+
module MetaTests
|
29
|
+
class ShouldFail < Test::Spec::CustomShould
|
30
|
+
def initialize
|
31
|
+
end
|
32
|
+
|
33
|
+
def assumptions(block)
|
34
|
+
block.should.raise(Test::Unit::AssertionFailedError)
|
35
|
+
end
|
36
|
+
|
37
|
+
def failure_message
|
38
|
+
"Block did not fail."
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class ShouldSucceed < Test::Spec::CustomShould
|
43
|
+
def initialize
|
44
|
+
end
|
45
|
+
|
46
|
+
def assumptions(block)
|
47
|
+
block.should.not.raise(Test::Unit::AssertionFailedError)
|
48
|
+
end
|
49
|
+
|
50
|
+
def failure_message
|
51
|
+
"Block raised Test::Unit::AssertionFailedError."
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class ShouldBeDeprecated < Test::Spec::CustomShould
|
56
|
+
def initialize
|
57
|
+
end
|
58
|
+
|
59
|
+
def assumptions(block)
|
60
|
+
block.should._warn
|
61
|
+
$WARNING.should =~ /deprecated/
|
62
|
+
end
|
63
|
+
|
64
|
+
def failure_message
|
65
|
+
"warning was not a deprecation"
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
def fail
|
71
|
+
ShouldFail.new
|
72
|
+
end
|
73
|
+
|
74
|
+
def succeed
|
75
|
+
ShouldSucceed.new
|
76
|
+
end
|
77
|
+
|
78
|
+
def deprecated
|
79
|
+
ShouldBeDeprecated.new
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
module TestShoulds
|
84
|
+
class EmptyShould < Test::Spec::CustomShould
|
85
|
+
end
|
86
|
+
|
87
|
+
class EqualString < Test::Spec::CustomShould
|
88
|
+
def matches?(other)
|
89
|
+
object == other.to_s
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class EqualString2 < Test::Spec::CustomShould
|
94
|
+
def matches?(other)
|
95
|
+
object == other.to_s
|
96
|
+
end
|
97
|
+
|
98
|
+
def failure_message
|
99
|
+
"yada yada yada"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
def empty_should(obj)
|
104
|
+
EmptyShould.new(obj)
|
105
|
+
end
|
106
|
+
|
107
|
+
def equal_string(str)
|
108
|
+
EqualString.new(str)
|
109
|
+
end
|
110
|
+
|
111
|
+
def equal_string2(str)
|
112
|
+
EqualString2.new(str)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context "test/spec" do
|
117
|
+
include MetaTests
|
118
|
+
|
119
|
+
specify "has should.satisfy" do
|
120
|
+
lambda { should.satisfy { 1 == 1 } }.should succeed
|
121
|
+
lambda { should.satisfy { 1 } }.should succeed
|
122
|
+
|
123
|
+
lambda { should.satisfy { 1 == 2 } }.should fail
|
124
|
+
lambda { should.satisfy { false } }.should fail
|
125
|
+
lambda { should.satisfy { false } }.should fail
|
126
|
+
|
127
|
+
lambda { 1.should.satisfy { |n| n % 2 == 0 } }.should fail
|
128
|
+
lambda { 2.should.satisfy { |n| n % 2 == 0 } }.should succeed
|
129
|
+
end
|
130
|
+
|
131
|
+
specify "has should.equal" do
|
132
|
+
lambda { "string1".should.equal "string1" }.should succeed
|
133
|
+
lambda { "string1".should.equal "string2" }.should fail
|
134
|
+
lambda { "1".should.equal 1 }.should fail
|
135
|
+
|
136
|
+
lambda { "string1".should == "string1" }.should succeed
|
137
|
+
lambda { "string1".should == "string2" }.should fail
|
138
|
+
lambda { "1".should == 1 }.should fail
|
139
|
+
end
|
140
|
+
|
141
|
+
specify "has should.raise" do
|
142
|
+
lambda { lambda { raise "Error" }.should.raise }.should succeed
|
143
|
+
lambda { lambda { raise "Error" }.should.raise RuntimeError }.should succeed
|
144
|
+
lambda { lambda { raise "Error" }.should.not.raise }.should fail
|
145
|
+
lambda { lambda { raise "Error" }.should.not.raise(RuntimeError) }.should fail
|
146
|
+
|
147
|
+
lambda { lambda { 1 + 1 }.should.raise }.should fail
|
148
|
+
lambda { lambda { raise "Error" }.should.raise(Interrupt) }.should fail
|
149
|
+
end
|
150
|
+
|
151
|
+
specify "has should.raise with a block" do
|
152
|
+
lambda { should.raise { raise "Error" } }.should succeed
|
153
|
+
lambda { should.raise(RuntimeError) { raise "Error" } }.should succeed
|
154
|
+
lambda { should.not.raise { raise "Error" } }.should fail
|
155
|
+
lambda { should.not.raise(RuntimeError) { raise "Error" } }.should fail
|
156
|
+
|
157
|
+
lambda { should.raise { 1 + 1 } }.should fail
|
158
|
+
lambda { should.raise(Interrupt) { raise "Error" } }.should fail
|
159
|
+
end
|
160
|
+
|
161
|
+
specify "should.raise should return the exception" do
|
162
|
+
ex = lambda { raise "foo!" }.should.raise
|
163
|
+
ex.should.be.kind_of RuntimeError
|
164
|
+
ex.message.should.match(/foo/)
|
165
|
+
end
|
166
|
+
|
167
|
+
specify "has should.be.an.instance_of" do
|
168
|
+
lambda {
|
169
|
+
lambda { "string".should.be_an_instance_of String }.should succeed
|
170
|
+
}.should.be deprecated
|
171
|
+
lambda {
|
172
|
+
lambda { "string".should.be_an_instance_of Hash }.should fail
|
173
|
+
}.should.be deprecated
|
174
|
+
|
175
|
+
lambda { "string".should.be.instance_of String }.should succeed
|
176
|
+
lambda { "string".should.be.instance_of Hash }.should fail
|
177
|
+
|
178
|
+
lambda { "string".should.be.an.instance_of String }.should succeed
|
179
|
+
lambda { "string".should.be.an.instance_of Hash }.should fail
|
180
|
+
end
|
181
|
+
|
182
|
+
specify "has should.be.nil" do
|
183
|
+
lambda { nil.should.be.nil }.should succeed
|
184
|
+
lambda { nil.should.be nil }.should succeed
|
185
|
+
lambda { nil.should.be_nil }.should.be deprecated
|
186
|
+
|
187
|
+
lambda { nil.should.not.be.nil }.should fail
|
188
|
+
lambda { nil.should.not.be nil }.should fail
|
189
|
+
lambda { lambda { nil.should.not.be_nil }.should fail }.should.be deprecated
|
190
|
+
|
191
|
+
lambda { "foo".should.be.nil }.should fail
|
192
|
+
lambda { "bar".should.be nil }.should fail
|
193
|
+
|
194
|
+
lambda { "foo".should.not.be.nil }.should succeed
|
195
|
+
lambda { "bar".should.not.be nil }.should succeed
|
196
|
+
end
|
197
|
+
|
198
|
+
specify "has should.include" do
|
199
|
+
lambda { [1,2,3].should.include 2 }.should succeed
|
200
|
+
lambda { [1,2,3].should.include 4 }.should fail
|
201
|
+
|
202
|
+
lambda { {1=>2, 3=>4}.should.include 1 }.should succeed
|
203
|
+
lambda { {1=>2, 3=>4}.should.include 2 }.should fail
|
204
|
+
end
|
205
|
+
|
206
|
+
specify "has should.be.a.kind_of" do
|
207
|
+
lambda { Array.should.be.kind_of Module }.should succeed
|
208
|
+
lambda { "string".should.be.kind_of Object }.should succeed
|
209
|
+
lambda { 1.should.be.kind_of Comparable }.should succeed
|
210
|
+
|
211
|
+
lambda { Array.should.be.a.kind_of Module }.should succeed
|
212
|
+
|
213
|
+
lambda { "string".should.be.a.kind_of Class }.should fail
|
214
|
+
lambda {
|
215
|
+
lambda { "string".should.be_a_kind_of Class }.should fail
|
216
|
+
}.should.be deprecated
|
217
|
+
|
218
|
+
lambda { Array.should.be_a_kind_of Module }.should.be deprecated
|
219
|
+
lambda { "string".should.be_a_kind_of Object }.should.be deprecated
|
220
|
+
lambda { 1.should.be_a_kind_of Comparable }.should.be deprecated
|
221
|
+
end
|
222
|
+
|
223
|
+
specify "has should.match" do
|
224
|
+
lambda { "string".should.match(/strin./) }.should succeed
|
225
|
+
lambda { "string".should.match("strin") }.should succeed
|
226
|
+
lambda { "string".should =~ /strin./ }.should succeed
|
227
|
+
lambda { "string".should =~ "strin" }.should succeed
|
228
|
+
|
229
|
+
lambda { "string".should.match(/slin./) }.should fail
|
230
|
+
lambda { "string".should.match("slin") }.should fail
|
231
|
+
lambda { "string".should =~ /slin./ }.should fail
|
232
|
+
lambda { "string".should =~ "slin" }.should fail
|
233
|
+
end
|
234
|
+
|
235
|
+
specify "has should.be" do
|
236
|
+
thing = "thing"
|
237
|
+
lambda { thing.should.be thing }.should succeed
|
238
|
+
lambda { thing.should.be "thing" }.should fail
|
239
|
+
|
240
|
+
lambda { 1.should.be(2, 3) }.should.raise(ArgumentError)
|
241
|
+
end
|
242
|
+
|
243
|
+
specify "has should.not.raise" do
|
244
|
+
lambda { lambda { 1 + 1 }.should.not.raise }.should succeed
|
245
|
+
lambda { lambda { 1 + 1 }.should.not.raise(Interrupt) }.should succeed
|
246
|
+
|
247
|
+
lambda {
|
248
|
+
begin
|
249
|
+
lambda {
|
250
|
+
raise ZeroDivisionError.new("ArgumentError")
|
251
|
+
}.should.not.raise(RuntimeError, StandardError, Comparable)
|
252
|
+
rescue ZeroDivisionError
|
253
|
+
end
|
254
|
+
}.should succeed
|
255
|
+
|
256
|
+
lambda { lambda { raise "Error" }.should.not.raise }.should fail
|
257
|
+
end
|
258
|
+
|
259
|
+
specify "has should.not.satisfy" do
|
260
|
+
lambda { should.not.satisfy { 1 == 2 } }.should succeed
|
261
|
+
lambda { should.not.satisfy { 1 == 1 } }.should fail
|
262
|
+
end
|
263
|
+
|
264
|
+
specify "has should.not.be" do
|
265
|
+
thing = "thing"
|
266
|
+
lambda { thing.should.not.be "thing" }.should succeed
|
267
|
+
lambda { thing.should.not.be thing }.should fail
|
268
|
+
|
269
|
+
lambda { thing.should.not.be thing, thing }.should.raise(ArgumentError)
|
270
|
+
end
|
271
|
+
|
272
|
+
specify "has should.not.equal" do
|
273
|
+
lambda { "string1".should.not.equal "string2" }.should succeed
|
274
|
+
lambda { "string1".should.not.equal "string1" }.should fail
|
275
|
+
end
|
276
|
+
|
277
|
+
specify "has should.not.match" do
|
278
|
+
lambda { "string".should.not.match(/sling/) }.should succeed
|
279
|
+
lambda { "string".should.not.match(/string/) }.should fail
|
280
|
+
lambda { "string".should.not.match("strin") }.should fail
|
281
|
+
|
282
|
+
lambda { "string".should.not =~ /sling/ }.should succeed
|
283
|
+
lambda { "string".should.not =~ /string/ }.should fail
|
284
|
+
lambda { "string".should.not =~ "strin" }.should fail
|
285
|
+
end
|
286
|
+
|
287
|
+
specify "has should.throw" do
|
288
|
+
lambda { lambda { throw :thing }.should.throw(:thing) }.should succeed
|
289
|
+
|
290
|
+
lambda { lambda { throw :thing2 }.should.throw(:thing) }.should fail
|
291
|
+
lambda { lambda { 1 + 1 }.should.throw(:thing) }.should fail
|
292
|
+
end
|
293
|
+
|
294
|
+
specify "has should.not.throw" do
|
295
|
+
lambda { lambda { 1 + 1 }.should.not.throw }.should succeed
|
296
|
+
lambda { lambda { throw :thing }.should.not.throw }.should fail
|
297
|
+
end
|
298
|
+
|
299
|
+
specify "has should.respond_to" do
|
300
|
+
lambda { "foo".should.respond_to :to_s }.should succeed
|
301
|
+
lambda { 5.should.respond_to :to_str }.should fail
|
302
|
+
lambda { :foo.should.respond_to :nx }.should fail
|
303
|
+
end
|
304
|
+
|
305
|
+
specify "has should.be_close" do
|
306
|
+
lambda { 1.4.should.be.close 1.4, 0 }.should succeed
|
307
|
+
lambda { 0.4.should.be.close 0.5, 0.1 }.should succeed
|
308
|
+
|
309
|
+
lambda {
|
310
|
+
lambda { 1.4.should.be_close 1.4, 0 }.should succeed
|
311
|
+
}.should.be deprecated
|
312
|
+
lambda {
|
313
|
+
lambda { 0.4.should.be_close 0.5, 0.1 }.should succeed
|
314
|
+
}.should.be deprecated
|
315
|
+
|
316
|
+
lambda {
|
317
|
+
float_thing = Object.new
|
318
|
+
def float_thing.to_f
|
319
|
+
0.2
|
320
|
+
end
|
321
|
+
float_thing.should.be.close 0.1, 0.1
|
322
|
+
}.should succeed
|
323
|
+
|
324
|
+
lambda { 0.4.should.be.close 0.5, 0.05 }.should fail
|
325
|
+
lambda { 0.4.should.be.close Object.new, 0.1 }.should fail
|
326
|
+
lambda { 0.4.should.be.close 0.5, -0.1 }.should fail
|
327
|
+
end
|
328
|
+
|
329
|
+
specify "multiple negation works" do
|
330
|
+
lambda { 1.should.equal 1 }.should succeed
|
331
|
+
lambda { 1.should.not.equal 1 }.should fail
|
332
|
+
lambda { 1.should.not.not.equal 1 }.should succeed
|
333
|
+
lambda { 1.should.not.not.not.equal 1 }.should fail
|
334
|
+
|
335
|
+
lambda { 1.should.equal 2 }.should fail
|
336
|
+
lambda { 1.should.not.equal 2 }.should succeed
|
337
|
+
lambda { 1.should.not.not.equal 2 }.should fail
|
338
|
+
lambda { 1.should.not.not.not.equal 2 }.should succeed
|
339
|
+
end
|
340
|
+
|
341
|
+
specify "has should.<predicate>" do
|
342
|
+
lambda { [].should.be.empty }.should succeed
|
343
|
+
lambda { [1,2,3].should.not.be.empty }.should succeed
|
344
|
+
|
345
|
+
lambda { [].should.not.be.empty }.should fail
|
346
|
+
lambda { [1,2,3].should.be.empty }.should fail
|
347
|
+
|
348
|
+
lambda { {1=>2, 3=>4}.should.has_key 1 }.should succeed
|
349
|
+
lambda { {1=>2, 3=>4}.should.not.has_key 2 }.should succeed
|
350
|
+
|
351
|
+
lambda { nil.should.bla }.should.raise(NoMethodError)
|
352
|
+
lambda { nil.should.not.bla }.should.raise(NoMethodError)
|
353
|
+
end
|
354
|
+
|
355
|
+
specify "has should <operator> (>, >=, <, <=, ===)" do
|
356
|
+
lambda { 2.should.be > 1 }.should succeed
|
357
|
+
lambda { 1.should.be > 2 }.should fail
|
358
|
+
|
359
|
+
lambda { 1.should.be < 2 }.should succeed
|
360
|
+
lambda { 2.should.be < 1 }.should fail
|
361
|
+
|
362
|
+
lambda { 2.should.be >= 1 }.should succeed
|
363
|
+
lambda { 2.should.be >= 2 }.should succeed
|
364
|
+
lambda { 2.should.be >= 2.1 }.should fail
|
365
|
+
|
366
|
+
lambda { 2.should.be <= 1 }.should fail
|
367
|
+
lambda { 2.should.be <= 2 }.should succeed
|
368
|
+
lambda { 2.should.be <= 2.1 }.should succeed
|
369
|
+
|
370
|
+
lambda { Array.should === [1,2,3] }.should succeed
|
371
|
+
lambda { Integer.should === [1,2,3] }.should fail
|
372
|
+
|
373
|
+
lambda { /foo/.should === "foobar" }.should succeed
|
374
|
+
lambda { "foobar".should === /foo/ }.should fail
|
375
|
+
end
|
376
|
+
|
377
|
+
$contextscope = self
|
378
|
+
specify "is robust against careless users" do
|
379
|
+
lambda {
|
380
|
+
$contextscope.specify
|
381
|
+
}.should.raise(ArgumentError)
|
382
|
+
lambda {
|
383
|
+
$contextscope.xspecify
|
384
|
+
}.should.raise(ArgumentError)
|
385
|
+
lambda {
|
386
|
+
$contextscope.xspecify "foo"
|
387
|
+
}.should.not.raise(ArgumentError) # allow empty xspecifys
|
388
|
+
lambda {
|
389
|
+
Kernel.send(:context, "foo")
|
390
|
+
}.should.raise(ArgumentError)
|
391
|
+
lambda {
|
392
|
+
context "foo" do
|
393
|
+
end
|
394
|
+
}.should.raise(Test::Spec::DefinitionError)
|
395
|
+
end
|
396
|
+
|
397
|
+
specify "should detect warnings" do
|
398
|
+
lambda { lambda { 0 }.should._warn }.should fail
|
399
|
+
lambda { lambda { warn "just a test" }.should._warn }.should succeed
|
400
|
+
end
|
401
|
+
|
402
|
+
specify "should message/blame faults" do
|
403
|
+
begin
|
404
|
+
2.should.blaming("Two is not two anymore!").equal 3
|
405
|
+
rescue Test::Unit::AssertionFailedError => e
|
406
|
+
e.message.should =~ /Two/
|
407
|
+
end
|
408
|
+
|
409
|
+
begin
|
410
|
+
2.should.messaging("Two is not two anymore!").equal 3
|
411
|
+
rescue Test::Unit::AssertionFailedError => e
|
412
|
+
e.message.should =~ /Two/
|
413
|
+
end
|
414
|
+
|
415
|
+
begin
|
416
|
+
2.should.blaming("I thought two was three").not.equal 2
|
417
|
+
rescue Test::Unit::AssertionFailedError => e
|
418
|
+
e.message.should =~ /three/
|
419
|
+
end
|
420
|
+
|
421
|
+
begin
|
422
|
+
2.should.blaming("I thought two was three").not.not.not.equal 3
|
423
|
+
rescue Test::Unit::AssertionFailedError => e
|
424
|
+
e.message.should =~ /three/
|
425
|
+
end
|
426
|
+
|
427
|
+
lambda {
|
428
|
+
lambda { raise "Error" }.should.messaging("Duh.").not.raise
|
429
|
+
}.should.raise(Test::Unit::AssertionFailedError).message.should =~ /Duh/
|
430
|
+
end
|
431
|
+
|
432
|
+
include TestShoulds
|
433
|
+
specify "should allow for custom shoulds" do
|
434
|
+
lambda { (1+1).should equal_string("2") }.should succeed
|
435
|
+
lambda { (1+2).should equal_string("2") }.should fail
|
436
|
+
|
437
|
+
lambda { (1+1).should.pass equal_string("2") }.should succeed
|
438
|
+
lambda { (1+2).should.pass equal_string("2") }.should fail
|
439
|
+
|
440
|
+
lambda { (1+1).should.be equal_string("2") }.should succeed
|
441
|
+
lambda { (1+2).should.be equal_string("2") }.should fail
|
442
|
+
|
443
|
+
lambda { (1+1).should.not equal_string("2") }.should fail
|
444
|
+
lambda { (1+2).should.not equal_string("2") }.should succeed
|
445
|
+
lambda { (1+2).should.not.not equal_string("2") }.should fail
|
446
|
+
|
447
|
+
lambda { (1+1).should.not.pass equal_string("2") }.should fail
|
448
|
+
lambda { (1+2).should.not.pass equal_string("2") }.should succeed
|
449
|
+
|
450
|
+
lambda { (1+1).should.not.be equal_string("2") }.should fail
|
451
|
+
lambda { (1+2).should.not.be equal_string("2") }.should succeed
|
452
|
+
|
453
|
+
lambda {
|
454
|
+
(1+2).should equal_string("2")
|
455
|
+
}.should.raise(Test::Unit::AssertionFailedError).message.should =~ /EqualString/
|
456
|
+
|
457
|
+
lambda { (1+1).should equal_string2("2") }.should succeed
|
458
|
+
lambda { (1+2).should equal_string2("2") }.should fail
|
459
|
+
|
460
|
+
lambda {
|
461
|
+
(1+2).should equal_string2("2")
|
462
|
+
}.should.raise(Test::Unit::AssertionFailedError).message.should =~ /yada/
|
463
|
+
|
464
|
+
lambda {
|
465
|
+
(1+2).should.blaming("foo").pass equal_string2("2")
|
466
|
+
}.should.raise(Test::Unit::AssertionFailedError).message.should =~ /foo/
|
467
|
+
|
468
|
+
lambda {
|
469
|
+
nil.should empty_should(nil)
|
470
|
+
}.should.raise(NotImplementedError)
|
471
|
+
|
472
|
+
lambda { nil.should :break, :now }.should.raise(ArgumentError)
|
473
|
+
lambda { nil.should.not :pass, :now }.should.raise(ArgumentError)
|
474
|
+
lambda { nil.should.not.not :break, :now }.should.raise(ArgumentError)
|
475
|
+
end
|
476
|
+
|
477
|
+
xspecify "disabled specification" do
|
478
|
+
flunk
|
479
|
+
end
|
480
|
+
|
481
|
+
xspecify "empty disabled specification"
|
482
|
+
|
483
|
+
pspecify "pending specification" do
|
484
|
+
flunk
|
485
|
+
end
|
486
|
+
|
487
|
+
pspecify "empty pending specification"
|
488
|
+
|
489
|
+
context "more disabled" do
|
490
|
+
xspecify "this is intentional" do
|
491
|
+
# ...
|
492
|
+
end
|
493
|
+
|
494
|
+
specify "an empty specification" do
|
495
|
+
# ...
|
496
|
+
end
|
497
|
+
|
498
|
+
xcontext "even more disabled" do
|
499
|
+
specify "we can cut out" do
|
500
|
+
# ...
|
501
|
+
end
|
502
|
+
|
503
|
+
specify "entire contexts, now" do
|
504
|
+
# ...
|
505
|
+
end
|
506
|
+
end
|
507
|
+
end
|
508
|
+
end
|
509
|
+
|
510
|
+
context "setup/teardown" do
|
511
|
+
setup do
|
512
|
+
@a = 1
|
513
|
+
@b = 2
|
514
|
+
end
|
515
|
+
|
516
|
+
setup do
|
517
|
+
@a = 2
|
518
|
+
end
|
519
|
+
|
520
|
+
teardown do
|
521
|
+
@a.should.equal 2
|
522
|
+
@a = 3
|
523
|
+
end
|
524
|
+
|
525
|
+
teardown do
|
526
|
+
@a.should.equal 3
|
527
|
+
end
|
528
|
+
|
529
|
+
specify "run in the right order" do
|
530
|
+
@a.should.equal 2
|
531
|
+
@b.should.equal 2
|
532
|
+
end
|
533
|
+
end
|
534
|
+
|
535
|
+
module ContextHelper
|
536
|
+
def foo
|
537
|
+
42
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
context "contexts" do
|
542
|
+
include ContextHelper
|
543
|
+
|
544
|
+
FOO = 42
|
545
|
+
$class = self.class
|
546
|
+
|
547
|
+
specify "are defined in class scope" do
|
548
|
+
lambda { FOO }.should.not.raise(NameError)
|
549
|
+
FOO.should.equal 42
|
550
|
+
$class.should.equal Class
|
551
|
+
end
|
552
|
+
|
553
|
+
specify "can include modules" do
|
554
|
+
lambda { foo }.should.not.raise(NameError)
|
555
|
+
foo.should.equal 42
|
556
|
+
end
|
557
|
+
end
|
558
|
+
|
559
|
+
class CustomTestUnitSubclass < Test::Unit::TestCase
|
560
|
+
def test_truth
|
561
|
+
assert true
|
562
|
+
end
|
563
|
+
end
|
564
|
+
|
565
|
+
context "contexts with subclasses", CustomTestUnitSubclass do
|
566
|
+
specify "use the supplied class as the superclass" do
|
567
|
+
self.should.be.a.kind_of CustomTestUnitSubclass
|
568
|
+
end
|
569
|
+
end
|
570
|
+
|
571
|
+
xcontext "xcontexts with subclasses", CustomTestUnitSubclass do
|
572
|
+
specify "work great!" do
|
573
|
+
self.should.be.a.kind_of CustomTestUnitSubclass
|
574
|
+
end
|
575
|
+
end
|