spec-unit 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/spec-unit/assert_helper.rb +66 -0
- data/lib/spec-unit/context_helper.rb +68 -0
- data/lib/spec-unit/should_helper.rb +181 -0
- data/lib/spec-unit.rb +3 -61
- data/test/helper.rb +55 -0
- data/test/test_assert_helper.rb +147 -0
- data/test/test_context_helper.rb +284 -0
- data/test/test_should_helper.rb +575 -0
- metadata +13 -4
- data/test/test_spec_unit.rb +0 -283
@@ -0,0 +1,575 @@
|
|
1
|
+
$: << File.dirname(__FILE__)
|
2
|
+
|
3
|
+
require 'helper'
|
4
|
+
require 'spec-unit/context_helper'
|
5
|
+
require 'spec-unit/should_helper'
|
6
|
+
|
7
|
+
module SpecUnit
|
8
|
+
module ContextHelper
|
9
|
+
module ClassMethods
|
10
|
+
def assert_has_one_assertion(test)
|
11
|
+
self.send :define_method, :specify_has_one_assertion do
|
12
|
+
assert_has_one_assertion(test)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def assert_has_x_assertions(number_of_assertions, test)
|
17
|
+
self.send :define_method, :specify_has_x_assertions do
|
18
|
+
assert_has_x_assertions(number_of_assertions, test)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def assert_test_passes_with_setup(test, &block)
|
23
|
+
self.send :define_method, :specify_passes_test_with_setup do
|
24
|
+
assert_test_passes_with_setup(test, &block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def assert_test_fails_with_setup(test, &block)
|
29
|
+
self.send :define_method, :specify_fails_test_with_setup do
|
30
|
+
assert_test_fails_with_setup(test, &block)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class TestShouldHelper < Test::Unit::TestCase
|
38
|
+
def self.tests_for( test, opts = {} )
|
39
|
+
test_name = (opts[:name] || test.to_s).sub(/should_/, '')
|
40
|
+
context "a test with should #{test_name}" do
|
41
|
+
define_method(:setup) { define_test(:test_test, &opts[:test].call(test)) }
|
42
|
+
assert_has_one_assertion(:test_test)
|
43
|
+
assert_test_passes_with_setup(:test_test, &opts[:pass])
|
44
|
+
assert_test_fails_with_setup(:test_test, &opts[:fail])
|
45
|
+
end
|
46
|
+
|
47
|
+
context "a test with should_not #{test_name}" do
|
48
|
+
negative_test = opts[:negative_test] ? opts[:negative_test][test] : opts[:test][('should_not' + test.to_s[6..-1]).to_sym]
|
49
|
+
define_method(:setup) { define_test(:test_test, &negative_test) }
|
50
|
+
assert_has_one_assertion(:test_test)
|
51
|
+
assert_test_passes_with_setup(:test_test, &opts[:fail])
|
52
|
+
assert_test_fails_with_setup(:test_test, &opts[:pass])
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def setup
|
57
|
+
@test_class = Class.new(Test::Unit::TestCase)
|
58
|
+
end
|
59
|
+
|
60
|
+
context 'a test with two shoulds' do
|
61
|
+
def setup
|
62
|
+
define_test(:test_two_shoulds) do
|
63
|
+
@object ||= 'test'
|
64
|
+
@object.should_be_a_kind_of(String)
|
65
|
+
@object.should_equal 'test'
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
assert_has_x_assertions(2, :test_two_shoulds)
|
70
|
+
assert_test_passes_with_setup(:test_two_shoulds) { @object = 'test' }
|
71
|
+
assert_test_fails_with_setup(:test_two_shoulds) { @object = 'game' }
|
72
|
+
end
|
73
|
+
|
74
|
+
context 'a test case with two tests' do
|
75
|
+
def setup
|
76
|
+
define_test(:test_one) { @object.should_be_a_kind_of(String) }
|
77
|
+
define_test(:test_two) { @object.should_equal 'test' }
|
78
|
+
end
|
79
|
+
|
80
|
+
def specify_has_two_assertions
|
81
|
+
assert_test_suite_has :assertions => 2
|
82
|
+
end
|
83
|
+
|
84
|
+
def specify_has_two_assertions_with_setup_defined
|
85
|
+
define_setup { @object = 'test' }
|
86
|
+
assert_test_suite_has :assertions => 2
|
87
|
+
end
|
88
|
+
|
89
|
+
def specify_works_when_both_test_pass
|
90
|
+
define_setup { @object = 'test' }
|
91
|
+
assert_test_suite_has :passes => true
|
92
|
+
end
|
93
|
+
|
94
|
+
def specify_works_when_first_test_passes
|
95
|
+
define_setup { @object = 'test_other_string' }
|
96
|
+
assert_test_suite_has :failures => 1, :errors => 0
|
97
|
+
end
|
98
|
+
|
99
|
+
def specify_works_when_both_tests_fail
|
100
|
+
define_setup { @object = 1 }
|
101
|
+
assert_test_suite_has :failures => 2, :errors => 0
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
tests_for :should_be_nil?,
|
106
|
+
:test => lambda { |test| lambda { @object.send(test) } },
|
107
|
+
:pass => lambda { @object = nil },
|
108
|
+
:fail => lambda { @object = 1 }
|
109
|
+
|
110
|
+
tests_for :should_be_empty?,
|
111
|
+
:test => lambda { |test| lambda { @object.send(test) } },
|
112
|
+
:pass => lambda { @object = '' },
|
113
|
+
:fail => lambda { @object = 'not empty' }
|
114
|
+
|
115
|
+
tests_for :should_have_empty?,
|
116
|
+
:test => lambda { |test| lambda { @object.send(test) } },
|
117
|
+
:pass => lambda { @object = '' },
|
118
|
+
:fail => lambda { @object = 'not empty' }
|
119
|
+
|
120
|
+
tests_for :should_equal?,
|
121
|
+
:test => lambda { |test| lambda { @object.send(test, @another_object) } },
|
122
|
+
:pass => lambda { @object = @another_object = 'this' },
|
123
|
+
:fail => lambda { @object = 'this'; @another_object = 'this' }
|
124
|
+
|
125
|
+
tests_for :==,
|
126
|
+
:test => lambda { |test| lambda { @object.should.send(test, @another_object) } },
|
127
|
+
:negative_test => lambda { |test| lambda { @object.should_not.send(test, @another_object) }},
|
128
|
+
:pass => lambda { @object, @another_object = 'this', 'this' },
|
129
|
+
:fail => lambda { @object, @another_object = 'this', 'that' }
|
130
|
+
|
131
|
+
tests_for :==,
|
132
|
+
:name => 'should_be_==',
|
133
|
+
:test => lambda { |test| lambda { @object.should_be.send(test, @another_object) } },
|
134
|
+
:negative_test => lambda { |test| lambda { @object.should_not_be.send(test, @another_object) } },
|
135
|
+
:pass => lambda { @object, @another_object = 'this', 'this' },
|
136
|
+
:fail => lambda { @object, @another_object = 'this', 'that' }
|
137
|
+
|
138
|
+
context 'a test with should_be <' do
|
139
|
+
def setup
|
140
|
+
define_test(:test_should_be_less_than) { @object.should_be < @another_object }
|
141
|
+
end
|
142
|
+
|
143
|
+
assert_has_one_assertion(:test_should_be_less_than)
|
144
|
+
|
145
|
+
def specify_passes_test_when_less_than
|
146
|
+
define_setup { @object, @another_object = 1, 2 }
|
147
|
+
assert_test_passes :test_should_be_less_than
|
148
|
+
end
|
149
|
+
|
150
|
+
def specify_fails_test_when_equal
|
151
|
+
define_setup { @object, @another_object = 1, 1 }
|
152
|
+
assert_test_fails :test_should_be_less_than
|
153
|
+
end
|
154
|
+
|
155
|
+
def specify_fails_test_when_greater_than
|
156
|
+
define_setup { @object, @another_object = 1, 0 }
|
157
|
+
assert_test_fails :test_should_be_less_than
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
context 'a test with should_not_be <' do
|
162
|
+
def setup
|
163
|
+
define_test(:test_should_not_be_less_than) { @object.should_not_be < @another_object }
|
164
|
+
end
|
165
|
+
|
166
|
+
assert_has_one_assertion(:test_should_not_be_less_than)
|
167
|
+
|
168
|
+
def specify_fails_test_when_less_than
|
169
|
+
define_setup { @object, @another_object = 1, 2 }
|
170
|
+
assert_test_fails :test_should_not_be_less_than
|
171
|
+
end
|
172
|
+
|
173
|
+
def specify_passes_test_when_equal
|
174
|
+
define_setup { @object, @another_object = 1, 1 }
|
175
|
+
assert_test_passes :test_should_not_be_less_than
|
176
|
+
end
|
177
|
+
|
178
|
+
def specify_passes_test_when_greater_than
|
179
|
+
define_setup { @object, @another_object = 1, 0 }
|
180
|
+
assert_test_passes :test_should_not_be_less_than
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
context 'a test with should_be <=' do
|
185
|
+
def setup
|
186
|
+
define_test(:test_should_be_less_than) { @object.should_be <= @another_object }
|
187
|
+
end
|
188
|
+
|
189
|
+
assert_has_one_assertion(:test_should_be_less_than)
|
190
|
+
|
191
|
+
def specify_passes_test_when_less_than
|
192
|
+
define_setup { @object, @another_object = 1, 2 }
|
193
|
+
assert_test_passes :test_should_be_less_than
|
194
|
+
end
|
195
|
+
|
196
|
+
def specify_passes_test_when_equal
|
197
|
+
define_setup { @object, @another_object = 1, 1 }
|
198
|
+
assert_test_passes :test_should_be_less_than
|
199
|
+
end
|
200
|
+
|
201
|
+
def specify_fails_test_when_greater_than
|
202
|
+
define_setup { @object, @another_object = 1, 0 }
|
203
|
+
assert_test_fails :test_should_be_less_than
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context 'a test with should_not_be <=' do
|
208
|
+
def setup
|
209
|
+
define_test(:test_should_not_be_less_than) { @object.should_not_be <= @another_object }
|
210
|
+
end
|
211
|
+
|
212
|
+
assert_has_one_assertion(:test_should_not_be_less_than)
|
213
|
+
|
214
|
+
def specify_fails_test_when_less_than
|
215
|
+
define_setup { @object, @another_object = 1, 2 }
|
216
|
+
assert_test_fails :test_should_not_be_less_than
|
217
|
+
end
|
218
|
+
|
219
|
+
def specify_fails_test_when_equal
|
220
|
+
define_setup { @object, @another_object = 1, 1 }
|
221
|
+
assert_test_fails :test_should_not_be_less_than
|
222
|
+
end
|
223
|
+
|
224
|
+
def specify_passes_test_when_greater_than
|
225
|
+
define_setup { @object, @another_object = 1, 0 }
|
226
|
+
assert_test_passes :test_should_not_be_less_than
|
227
|
+
end
|
228
|
+
end
|
229
|
+
|
230
|
+
context 'a test with should_be >' do
|
231
|
+
def setup
|
232
|
+
define_test(:test_should_be_greater_than) { @object.should_be > @another_object }
|
233
|
+
end
|
234
|
+
|
235
|
+
assert_has_one_assertion(:test_should_be_greater_than)
|
236
|
+
assert_test_passes_with_setup(:test_should_be_greater_than) { @object, @another_object = 1, 0 }
|
237
|
+
|
238
|
+
def specify_fails_test_when_less_than
|
239
|
+
define_setup { @object, @another_object = 1, 2 }
|
240
|
+
assert_test_fails :test_should_be_greater_than
|
241
|
+
end
|
242
|
+
|
243
|
+
def specify_fails_test_when_equal
|
244
|
+
define_setup { @object, @another_object = 1, 1 }
|
245
|
+
assert_test_fails :test_should_be_greater_than
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
context 'a test with should_not_be >' do
|
250
|
+
def setup
|
251
|
+
define_test(:test_should_not_be_greater_than) { @object.should_not_be > @another_object }
|
252
|
+
end
|
253
|
+
|
254
|
+
assert_has_one_assertion(:test_should_not_be_greater_than)
|
255
|
+
assert_test_fails_with_setup(:test_should_not_be_greater_than) { @object, @another_object = 1, 0 }
|
256
|
+
|
257
|
+
def specify_fails_test_when_less_than
|
258
|
+
define_setup { @object, @another_object = 1, 2 }
|
259
|
+
assert_test_passes :test_should_not_be_greater_than
|
260
|
+
end
|
261
|
+
|
262
|
+
def specify_fails_test_when_equal
|
263
|
+
define_setup { @object, @another_object = 1, 1 }
|
264
|
+
assert_test_passes :test_should_not_be_greater_than
|
265
|
+
end
|
266
|
+
end
|
267
|
+
|
268
|
+
context 'a test with should_be >=' do
|
269
|
+
def setup
|
270
|
+
define_test(:test_should_be_greater_than) { @object.should_be >= @another_object }
|
271
|
+
end
|
272
|
+
|
273
|
+
assert_has_one_assertion(:test_should_be_greater_than)
|
274
|
+
assert_test_fails_with_setup(:test_should_be_greater_than) { @object, @another_object = 1, 2 }
|
275
|
+
|
276
|
+
def specify_passes_test_when_greater_than
|
277
|
+
define_setup { @object, @another_object = 3, 2 }
|
278
|
+
assert_test_passes :test_should_be_greater_than
|
279
|
+
end
|
280
|
+
|
281
|
+
def specify_passes_test_when_equal
|
282
|
+
define_setup { @object, @another_object = 1, 1 }
|
283
|
+
assert_test_passes :test_should_be_greater_than
|
284
|
+
end
|
285
|
+
end
|
286
|
+
|
287
|
+
context 'a test with should_not_be >=' do
|
288
|
+
def setup
|
289
|
+
define_test(:test_should_not_be_greater_than) { @object.should_not_be >= @another_object }
|
290
|
+
end
|
291
|
+
|
292
|
+
assert_has_one_assertion(:test_should_not_be_greater_than)
|
293
|
+
assert_test_passes_with_setup(:test_should_not_be_greater_than) { @object, @another_object = 1, 2 }
|
294
|
+
|
295
|
+
def specify_passes_test_when_greater_than
|
296
|
+
define_setup { @object, @another_object = 3, 2 }
|
297
|
+
assert_test_fails :test_should_not_be_greater_than
|
298
|
+
end
|
299
|
+
|
300
|
+
def specify_passes_test_when_equal
|
301
|
+
define_setup { @object, @another_object = 1, 1 }
|
302
|
+
assert_test_fails :test_should_not_be_greater_than
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
tests_for :should_equal,
|
307
|
+
:test => lambda { |test| lambda { @object.send(test, @another_object) } },
|
308
|
+
:pass => lambda { @object, @another_object = 'this', 'this' },
|
309
|
+
:fail => lambda { @object, @another_object = 'this', 'that' }
|
310
|
+
|
311
|
+
tests_for :should_satisfy,
|
312
|
+
:test => lambda { |test| lambda { @object.should_satisfy { |obj| obj == @another_object } } },
|
313
|
+
:negative_test => lambda { |test| lambda { @object.should_not_satisfy { |obj| obj == @another_object } } },
|
314
|
+
:pass => lambda { @object, @another_object = 'this', 'this' },
|
315
|
+
:fail => lambda { @object, @another_object = 'this', 'that' }
|
316
|
+
|
317
|
+
context 'a test with should_be_close' do
|
318
|
+
def setup
|
319
|
+
define_test(:test_should_be_close) { @object.should_be_close @another_object, 0.05 }
|
320
|
+
end
|
321
|
+
|
322
|
+
assert_has_one_assertion(:test_should_be_close)
|
323
|
+
|
324
|
+
def specify_passes_test_when_close
|
325
|
+
define_setup { @object, @another_object = 1, 1.01 }
|
326
|
+
assert_test_passes :test_should_be_close
|
327
|
+
end
|
328
|
+
|
329
|
+
def specify_passes_test_on_edge
|
330
|
+
define_setup { @object, @another_object = 1, 1.049 }
|
331
|
+
assert_test_passes :test_should_be_close
|
332
|
+
end
|
333
|
+
|
334
|
+
def specify_passes_test_when_equal
|
335
|
+
define_setup { @object, @another_object = 1, 1 }
|
336
|
+
assert_test_passes :test_should_be_close
|
337
|
+
end
|
338
|
+
|
339
|
+
def specify_fails_test_when_not_close
|
340
|
+
define_setup { @object, @another_object = 1, 1.06 }
|
341
|
+
assert_test_fails :test_should_be_close
|
342
|
+
end
|
343
|
+
end
|
344
|
+
|
345
|
+
context 'a test with should_not_be_close' do
|
346
|
+
def setup
|
347
|
+
define_test(:test_should_not_be_close) { @object.should_not_be_close @another_object, 0.05 }
|
348
|
+
end
|
349
|
+
|
350
|
+
assert_has_one_assertion(:test_should_not_be_close)
|
351
|
+
|
352
|
+
def specify_fails_test_when_close
|
353
|
+
define_setup { @object, @another_object = 1, 1.01 }
|
354
|
+
assert_test_fails :test_should_not_be_close
|
355
|
+
end
|
356
|
+
|
357
|
+
def specify_fails_test_on_edge
|
358
|
+
define_setup { @object, @another_object = 1, 1.049 }
|
359
|
+
assert_test_fails :test_should_not_be_close
|
360
|
+
end
|
361
|
+
|
362
|
+
def specify_fails_test_when_equal
|
363
|
+
define_setup { @object, @another_object = 1, 1 }
|
364
|
+
assert_test_fails :test_should_not_be_close
|
365
|
+
end
|
366
|
+
|
367
|
+
def specify_passes_test_when_not_close
|
368
|
+
define_setup { @object, @another_object = 1, 1.06 }
|
369
|
+
assert_test_passes :test_should_not_be_close
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
tests_for :should_be,
|
374
|
+
:test => lambda { |test| lambda { @object.send(test, @another_object) } },
|
375
|
+
:pass => lambda { @object = @another_object = 'this' },
|
376
|
+
:fail => lambda { @object, @another_object = 'this', 'this' }
|
377
|
+
|
378
|
+
tests_for :should_match,
|
379
|
+
:test => lambda { |test| lambda { @object.send(test, /is/) } },
|
380
|
+
:pass => lambda { @object = 'this' },
|
381
|
+
:fail => lambda { @object = 'that' }
|
382
|
+
|
383
|
+
tests_for :should_be_an_instance_of,
|
384
|
+
:test => lambda { |test| lambda { @object.send(test, String) } },
|
385
|
+
:pass => lambda { @object = 'this' },
|
386
|
+
:fail => lambda { @object = 1 }
|
387
|
+
|
388
|
+
tests_for :should_be_a_kind_of,
|
389
|
+
:test => lambda { |test| lambda { @object.send(test, Numeric) } },
|
390
|
+
:pass => lambda { @object = 1 },
|
391
|
+
:fail => lambda { @object = '1' }
|
392
|
+
|
393
|
+
tests_for :should_respond_to,
|
394
|
+
:test => lambda { |test| lambda { @object.send(test, :length) } },
|
395
|
+
:pass => lambda { @object = 'this' },
|
396
|
+
:fail => lambda { @object = 1 }
|
397
|
+
|
398
|
+
context 'a test with should_raise and exception' do
|
399
|
+
def setup
|
400
|
+
define_test(:test_should_raise) { @object.should_raise RuntimeError }
|
401
|
+
end
|
402
|
+
|
403
|
+
assert_has_one_assertion :test_should_raise
|
404
|
+
assert_test_passes_with_setup(:test_should_raise) { @object = lambda { raise } }
|
405
|
+
assert_test_fails_with_setup(:test_should_raise) { @object = lambda {} }
|
406
|
+
|
407
|
+
def specify_test_fails_with_other_error
|
408
|
+
assert_test_fails_with_setup(:test_should_raise) { @object = lambda { raise Exception } }
|
409
|
+
end
|
410
|
+
end
|
411
|
+
|
412
|
+
context 'a test with should_not_raise and exception' do
|
413
|
+
def setup
|
414
|
+
define_test(:test_should_not_raise) { @object.should_not_raise RuntimeError }
|
415
|
+
end
|
416
|
+
|
417
|
+
assert_has_one_assertion :test_should_not_raise
|
418
|
+
assert_test_fails_with_setup(:test_should_not_raise) { @object = lambda { raise } }
|
419
|
+
assert_test_passes_with_setup(:test_should_not_raise) { @object = lambda {} }
|
420
|
+
|
421
|
+
def specify_test_passes_with_other_error
|
422
|
+
assert_test_passes_with_setup(:test_should_not_raise) { @object = lambda { raise Exception } }
|
423
|
+
end
|
424
|
+
end
|
425
|
+
|
426
|
+
tests_for :should_raise,
|
427
|
+
:test => lambda { |test| lambda { @object.send(test) } },
|
428
|
+
:pass => lambda { @object = lambda { raise } },
|
429
|
+
:fail => lambda { @object = lambda {} }
|
430
|
+
|
431
|
+
context 'a test with should_throw' do
|
432
|
+
def setup
|
433
|
+
define_test(:test_should_throw) { @object.should_throw :thrown }
|
434
|
+
end
|
435
|
+
|
436
|
+
assert_has_one_assertion :test_should_throw
|
437
|
+
assert_test_passes_with_setup(:test_should_throw) { @object = lambda { throw :thrown } }
|
438
|
+
assert_test_fails_with_setup(:test_should_throw) { @object = lambda {} }
|
439
|
+
|
440
|
+
def specify_test_fails_with_other_symbol_thrown
|
441
|
+
assert_test_fails_with_setup(:test_should_throw) { @object = lambda { throw :other } }
|
442
|
+
end
|
443
|
+
end
|
444
|
+
|
445
|
+
context 'a test with should_not_throw' do
|
446
|
+
def setup
|
447
|
+
define_test(:test_should_not_throw) { @object.should_not_throw :thrown }
|
448
|
+
end
|
449
|
+
|
450
|
+
assert_has_one_assertion :test_should_not_throw
|
451
|
+
assert_test_fails_with_setup(:test_should_not_throw) { @object = lambda { throw :thrown } }
|
452
|
+
assert_test_passes_with_setup(:test_should_not_throw) { @object = lambda {} }
|
453
|
+
|
454
|
+
def specify_test_passes_with_other_symbol_thrown
|
455
|
+
assert_test_passes_with_setup(:test_should_not_throw) { @object = lambda { throw :other } }
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
context 'a test with should_not_throw and no symbol' do
|
460
|
+
def setup
|
461
|
+
define_test(:test_should_not_throw) { @object.should_not_throw }
|
462
|
+
end
|
463
|
+
|
464
|
+
assert_has_one_assertion :test_should_not_throw
|
465
|
+
assert_test_fails_with_setup(:test_should_not_throw) { @object = lambda { throw :thrown } }
|
466
|
+
assert_test_passes_with_setup(:test_should_not_throw) { @object = lambda {} }
|
467
|
+
end
|
468
|
+
|
469
|
+
tests_for :should_include,
|
470
|
+
:test => lambda { |test| lambda { @object.send(test, 'a') } },
|
471
|
+
:pass => lambda { @object = %w( a b c ) },
|
472
|
+
:fail => lambda { @object = [1, 2, 3] }
|
473
|
+
|
474
|
+
context 'a test with should_have_things' do
|
475
|
+
def setup
|
476
|
+
define_test(:test_should_have_things) { @object.should_have(2).things }
|
477
|
+
end
|
478
|
+
|
479
|
+
assert_has_one_assertion :test_should_have_things
|
480
|
+
assert_test_passes_with_setup(:test_should_have_things) { @object = %w( a b ) }
|
481
|
+
assert_test_fails_with_setup(:test_should_have_things) { @object = %w( a ) }
|
482
|
+
|
483
|
+
def specify_fails_with_too_many_items
|
484
|
+
assert_test_fails_with_setup(:test_should_have_things) { @object = %w( a b c ) }
|
485
|
+
end
|
486
|
+
end
|
487
|
+
|
488
|
+
context 'a test with should_not_have_things' do
|
489
|
+
def setup
|
490
|
+
define_test(:test_should_not_have_things) { @object.should_not_have(2).things }
|
491
|
+
end
|
492
|
+
|
493
|
+
assert_has_one_assertion :test_should_not_have_things
|
494
|
+
assert_test_fails_with_setup(:test_should_not_have_things) { @object = %w( a b ) }
|
495
|
+
assert_test_passes_with_setup(:test_should_not_have_things) { @object = %w( a ) }
|
496
|
+
|
497
|
+
def specify_passes_with_too_many_items
|
498
|
+
assert_test_passes_with_setup(:test_should_not_have_things) { @object = %w( a b c ) }
|
499
|
+
end
|
500
|
+
end
|
501
|
+
|
502
|
+
context 'a test with should_have_at_least' do
|
503
|
+
def setup
|
504
|
+
define_test(:test_should_have_at_least) { @object.should_have_at_least(2).things }
|
505
|
+
end
|
506
|
+
|
507
|
+
assert_has_one_assertion :test_should_have_at_least
|
508
|
+
assert_test_passes_with_setup(:test_should_have_at_least) { @object = %w( a b ) }
|
509
|
+
assert_test_fails_with_setup(:test_should_have_at_least) { @object = %w( a ) }
|
510
|
+
|
511
|
+
def specify_passes_with_more_items
|
512
|
+
assert_test_passes_with_setup(:test_should_have_at_least) { @object = %w( a b c ) }
|
513
|
+
end
|
514
|
+
end
|
515
|
+
|
516
|
+
context 'a test with should_not_have_at_least' do
|
517
|
+
def setup
|
518
|
+
define_test(:test_should_not_have_at_least) { @object.should_not_have_at_least(2).things }
|
519
|
+
end
|
520
|
+
|
521
|
+
assert_has_one_assertion :test_should_not_have_at_least
|
522
|
+
assert_test_fails_with_setup(:test_should_not_have_at_least) { @object = %w( a b ) }
|
523
|
+
assert_test_passes_with_setup(:test_should_not_have_at_least) { @object = %w( a ) }
|
524
|
+
|
525
|
+
def specify_fails_with_more_items
|
526
|
+
assert_test_fails_with_setup(:test_should_not_have_at_least) { @object = %w( a b c ) }
|
527
|
+
end
|
528
|
+
end
|
529
|
+
|
530
|
+
context 'a test with should_have_at_most' do
|
531
|
+
def setup
|
532
|
+
define_test(:test_should_have_at_most) { @object.should_have_at_most(2).things }
|
533
|
+
end
|
534
|
+
|
535
|
+
assert_has_one_assertion :test_should_have_at_most
|
536
|
+
assert_test_passes_with_setup(:test_should_have_at_most) { @object = %w( a b ) }
|
537
|
+
assert_test_fails_with_setup(:test_should_have_at_most) { @object = %w( a b c) }
|
538
|
+
|
539
|
+
def specify_passes_with_more_items
|
540
|
+
assert_test_passes_with_setup(:test_should_have_at_most) { @object = %w( a ) }
|
541
|
+
end
|
542
|
+
end
|
543
|
+
|
544
|
+
context 'a test with should_not_have_at_most' do
|
545
|
+
def setup
|
546
|
+
define_test(:test_should_not_have_at_most) { @object.should_not_have_at_most(2).things }
|
547
|
+
end
|
548
|
+
|
549
|
+
assert_has_one_assertion :test_should_not_have_at_most
|
550
|
+
assert_test_fails_with_setup(:test_should_not_have_at_most) { @object = %w( a b ) }
|
551
|
+
assert_test_passes_with_setup(:test_should_not_have_at_most) { @object = %w( a b c) }
|
552
|
+
|
553
|
+
def specify_fails_with_more_items
|
554
|
+
assert_test_fails_with_setup(:test_should_not_have_at_most) { @object = %w( a ) }
|
555
|
+
end
|
556
|
+
end
|
557
|
+
|
558
|
+
def define_test test, &block
|
559
|
+
@test_class.send :define_method, test, block
|
560
|
+
end
|
561
|
+
|
562
|
+
def run_test_suite
|
563
|
+
@result = Test::Unit::TestResult.new
|
564
|
+
@test_suite = @test_class.suite
|
565
|
+
@test_suite.run(@result) {|m,n|}
|
566
|
+
end
|
567
|
+
|
568
|
+
def assert_test_suite_has(opts)
|
569
|
+
run_test_suite
|
570
|
+
assert @result.passed? if opts[:passes]
|
571
|
+
assert_equal(opts[:assertions], @result.assertion_count) if opts[:assertions]
|
572
|
+
assert_equal(opts[:failures], @result.failure_count) if opts[:failures]
|
573
|
+
assert_equal(opts[:errors], @result.error_count) if opts[:errors]
|
574
|
+
end
|
575
|
+
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
|
|
3
3
|
specification_version: 1
|
4
4
|
name: spec-unit
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version:
|
7
|
-
date: 2006-
|
6
|
+
version: 1.0.0
|
7
|
+
date: 2006-12-21 00:00:00 -05:00
|
8
8
|
summary: A library for separating Test::Unit tests into contexts.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -30,9 +30,18 @@ authors:
|
|
30
30
|
- Trotter Cashion
|
31
31
|
files:
|
32
32
|
- lib/spec-unit.rb
|
33
|
-
-
|
33
|
+
- lib/spec-unit/assert_helper.rb
|
34
|
+
- lib/spec-unit/context_helper.rb
|
35
|
+
- lib/spec-unit/should_helper.rb
|
36
|
+
- test/helper.rb
|
37
|
+
- test/test_assert_helper.rb
|
38
|
+
- test/test_context_helper.rb
|
39
|
+
- test/test_should_helper.rb
|
34
40
|
test_files:
|
35
|
-
- test/
|
41
|
+
- test/helper.rb
|
42
|
+
- test/test_assert_helper.rb
|
43
|
+
- test/test_context_helper.rb
|
44
|
+
- test/test_should_helper.rb
|
36
45
|
rdoc_options: []
|
37
46
|
|
38
47
|
extra_rdoc_files: []
|