minitest 1.3.0 → 6.0.6
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.
- checksums.yaml +7 -0
- checksums.yaml.gz.sig +2 -0
- data/History.rdoc +1860 -0
- data/Manifest.txt +38 -8
- data/README.rdoc +763 -0
- data/Rakefile +70 -56
- data/bin/minitest +5 -0
- data/design_rationale.rb +54 -0
- data/lib/hoe/minitest.rb +30 -0
- data/lib/minitest/assertions.rb +821 -0
- data/lib/minitest/autorun.rb +5 -0
- data/lib/minitest/benchmark.rb +452 -0
- data/lib/minitest/bisect.rb +304 -0
- data/lib/minitest/complete.rb +56 -0
- data/lib/minitest/compress.rb +94 -0
- data/lib/minitest/error_on_warning.rb +11 -0
- data/lib/minitest/expectations.rb +321 -0
- data/lib/minitest/find_minimal_combination.rb +127 -0
- data/lib/minitest/hell.rb +11 -0
- data/lib/minitest/manual_plugins.rb +4 -0
- data/lib/minitest/parallel.rb +72 -0
- data/lib/minitest/path_expander.rb +432 -0
- data/lib/minitest/pride.rb +4 -0
- data/lib/minitest/pride_plugin.rb +135 -0
- data/lib/minitest/server.rb +49 -0
- data/lib/minitest/server_plugin.rb +88 -0
- data/lib/minitest/spec.rb +306 -64
- data/lib/minitest/sprint.rb +105 -0
- data/lib/minitest/sprint_plugin.rb +39 -0
- data/lib/minitest/test.rb +232 -0
- data/lib/minitest/test_task.rb +331 -0
- data/lib/minitest.rb +1232 -0
- data/test/minitest/metametameta.rb +150 -0
- data/test/minitest/test_bisect.rb +249 -0
- data/test/minitest/test_find_minimal_combination.rb +138 -0
- data/test/minitest/test_minitest_assertions.rb +1729 -0
- data/test/minitest/test_minitest_benchmark.rb +151 -0
- data/test/minitest/test_minitest_reporter.rb +437 -0
- data/test/minitest/test_minitest_spec.rb +1095 -0
- data/test/minitest/test_minitest_test.rb +1295 -0
- data/test/minitest/test_minitest_test_task.rb +57 -0
- data/test/minitest/test_path_expander.rb +229 -0
- data/test/minitest/test_server.rb +146 -0
- data.tar.gz.sig +1 -0
- metadata +235 -62
- metadata.gz.sig +0 -0
- data/.autotest +0 -15
- data/History.txt +0 -114
- data/README.txt +0 -56
- data/lib/minitest/mock.rb +0 -31
- data/lib/minitest/unit.rb +0 -482
- data/test/test_mini_mock.rb +0 -77
- data/test/test_mini_spec.rb +0 -149
- data/test/test_mini_test.rb +0 -829
data/lib/minitest/unit.rb
DELETED
|
@@ -1,482 +0,0 @@
|
|
|
1
|
-
##
|
|
2
|
-
#
|
|
3
|
-
# Totally minimal drop-in replacement for test-unit
|
|
4
|
-
#
|
|
5
|
-
# TODO: refute -> debunk, prove/rebut, show/deny... lots of possibilities
|
|
6
|
-
|
|
7
|
-
module MiniTest
|
|
8
|
-
class Assertion < Exception; end
|
|
9
|
-
class Skip < Assertion; end
|
|
10
|
-
|
|
11
|
-
file = if RUBY_VERSION =~ /^1\.9/ then # bt's expanded, but __FILE__ isn't :(
|
|
12
|
-
File.expand_path __FILE__
|
|
13
|
-
elsif __FILE__ =~ /^[^\.]/ then # assume both relative
|
|
14
|
-
require 'pathname'
|
|
15
|
-
pwd = Pathname.new Dir.pwd
|
|
16
|
-
pn = Pathname.new File.expand_path(__FILE__)
|
|
17
|
-
pn = File.join(".", pn.relative_path_from(pwd)) unless pn.relative?
|
|
18
|
-
pn.to_s
|
|
19
|
-
else # assume both are expanded
|
|
20
|
-
__FILE__
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
# './lib' in project dir, or '/usr/local/blahblah' if installed
|
|
24
|
-
MINI_DIR = File.dirname(File.dirname(file))
|
|
25
|
-
|
|
26
|
-
def self.filter_backtrace bt
|
|
27
|
-
return ["No backtrace"] unless bt
|
|
28
|
-
|
|
29
|
-
new_bt = []
|
|
30
|
-
bt.each do |line|
|
|
31
|
-
break if line.rindex(MINI_DIR, 0)
|
|
32
|
-
new_bt << line
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
new_bt = bt.reject { |line| line.rindex(MINI_DIR, 0) } if new_bt.empty?
|
|
36
|
-
new_bt = bt.dup if new_bt.empty?
|
|
37
|
-
new_bt
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
module Assertions
|
|
41
|
-
def mu_pp(obj)
|
|
42
|
-
s = obj.inspect
|
|
43
|
-
s = s.force_encoding(Encoding.default_external) if defined? Encoding
|
|
44
|
-
s
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def _assertions= n
|
|
48
|
-
@_assertions = n
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def _assertions
|
|
52
|
-
@_assertions ||= 0
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def assert test, msg = nil
|
|
56
|
-
msg ||= "Failed assertion, no message given."
|
|
57
|
-
self._assertions += 1
|
|
58
|
-
unless test then
|
|
59
|
-
msg = msg.call if Proc === msg
|
|
60
|
-
raise MiniTest::Assertion, msg
|
|
61
|
-
end
|
|
62
|
-
true
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
def assert_block msg = nil
|
|
66
|
-
msg = message(msg) { "Expected block to return true value" }
|
|
67
|
-
assert yield, msg
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def assert_empty obj, msg = nil
|
|
71
|
-
msg = message(msg) { "Expected #{obj.inspect} to be empty" }
|
|
72
|
-
assert_respond_to obj, :empty?
|
|
73
|
-
assert obj.empty?, msg
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
def assert_equal exp, act, msg = nil
|
|
77
|
-
msg = message(msg) { "Expected #{mu_pp(exp)}, not #{mu_pp(act)}" }
|
|
78
|
-
assert(exp == act, msg)
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def assert_in_delta exp, act, delta = 0.001, msg = nil
|
|
82
|
-
n = (exp - act).abs
|
|
83
|
-
msg = message(msg) { "Expected #{exp} - #{act} (#{n}) to be < #{delta}" }
|
|
84
|
-
assert delta > n, msg
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
def assert_in_epsilon a, b, epsilon = 0.001, msg = nil
|
|
88
|
-
assert_in_delta a, b, [a, b].min * epsilon, msg
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
def assert_includes collection, obj, msg = nil
|
|
92
|
-
msg = message(msg) { "Expected #{mu_pp(collection)} to include #{mu_pp(obj)}" }
|
|
93
|
-
assert_respond_to collection, :include?
|
|
94
|
-
assert collection.include?(obj), msg
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def assert_instance_of cls, obj, msg = nil
|
|
98
|
-
msg = message(msg) { "Expected #{mu_pp(obj)} to be an instance of #{cls}, not #{obj.class}" }
|
|
99
|
-
flip = (Module === obj) && ! (Module === cls) # HACK for specs
|
|
100
|
-
obj, cls = cls, obj if flip
|
|
101
|
-
assert cls === obj, msg
|
|
102
|
-
end
|
|
103
|
-
|
|
104
|
-
def assert_kind_of cls, obj, msg = nil # TODO: merge with instance_of
|
|
105
|
-
msg = message(msg) {
|
|
106
|
-
"Expected #{mu_pp(obj)} to be a kind of #{cls}, not #{obj.class}" }
|
|
107
|
-
flip = (Module === obj) && ! (Module === cls) # HACK for specs
|
|
108
|
-
obj, cls = cls, obj if flip
|
|
109
|
-
assert obj.kind_of?(cls), msg
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def assert_match exp, act, msg = nil
|
|
113
|
-
msg = message(msg) { "Expected #{mu_pp(act)} to match #{mu_pp(exp)}" }
|
|
114
|
-
assert_respond_to act, :"=~"
|
|
115
|
-
(exp = /#{exp}/) if String === exp && String === act
|
|
116
|
-
assert act =~ exp, msg
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def assert_nil obj, msg = nil
|
|
120
|
-
msg = message(msg) { "Expected #{mu_pp(obj)} to be nil" }
|
|
121
|
-
assert obj.nil?, msg
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def assert_operator o1, op, o2, msg = nil
|
|
125
|
-
msg = message(msg) { "Expected #{mu_pp(o1)} to be #{op} #{mu_pp(o2)}" }
|
|
126
|
-
assert o1.__send__(op, o2), msg
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def assert_raises *exp
|
|
130
|
-
msg = String === exp.last ? exp.pop : nil
|
|
131
|
-
should_raise = false
|
|
132
|
-
begin
|
|
133
|
-
yield
|
|
134
|
-
should_raise = true
|
|
135
|
-
rescue Exception => e
|
|
136
|
-
assert_includes(exp, e.class, exception_details(e, "<#{mu_pp(exp)}> exception expected, not"))
|
|
137
|
-
return e
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
exp = exp.first if exp.size == 1
|
|
141
|
-
flunk "#{mu_pp(exp)} expected but nothing was raised." if should_raise
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def assert_respond_to obj, meth, msg = nil
|
|
145
|
-
msg = message(msg) {
|
|
146
|
-
"Expected #{mu_pp(obj)} (#{obj.class}) to respond to ##{meth}"
|
|
147
|
-
}
|
|
148
|
-
flip = (Symbol === obj) && ! (Symbol === meth) # HACK for specs
|
|
149
|
-
obj, meth = meth, obj if flip
|
|
150
|
-
assert obj.respond_to?(meth), msg
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def assert_same exp, act, msg = nil
|
|
154
|
-
msg = message(msg) {
|
|
155
|
-
data = [mu_pp(act), act.object_id, mu_pp(exp), exp.object_id]
|
|
156
|
-
"Expected %s (0x%x) to be the same as %s (0x%x)" % data
|
|
157
|
-
}
|
|
158
|
-
assert exp.equal?(act), msg
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def assert_send send_ary, m = nil
|
|
162
|
-
recv, msg, *args = send_ary
|
|
163
|
-
m = message(m) {
|
|
164
|
-
"Expected #{mu_pp(recv)}.#{msg}(*#{mu_pp(args)}) to return true" }
|
|
165
|
-
assert recv.__send__(msg, *args), m
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
def assert_throws sym, msg = nil
|
|
169
|
-
default = "Expected #{mu_pp(sym)} to have been thrown"
|
|
170
|
-
caught = true
|
|
171
|
-
catch(sym) do
|
|
172
|
-
begin
|
|
173
|
-
yield
|
|
174
|
-
rescue ArgumentError => e # 1.9 exception
|
|
175
|
-
default += ", not #{e.message.split(/ /).last}"
|
|
176
|
-
rescue NameError => e # 1.8 exception
|
|
177
|
-
default += ", not #{e.name.inspect}"
|
|
178
|
-
end
|
|
179
|
-
caught = false
|
|
180
|
-
end
|
|
181
|
-
|
|
182
|
-
assert caught, message(msg) { default }
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
def capture_io
|
|
186
|
-
require 'stringio'
|
|
187
|
-
|
|
188
|
-
orig_stdout, orig_stderr = $stdout.dup, $stderr.dup
|
|
189
|
-
captured_stdout, captured_stderr = StringIO.new, StringIO.new
|
|
190
|
-
$stdout, $stderr = captured_stdout, captured_stderr
|
|
191
|
-
|
|
192
|
-
yield
|
|
193
|
-
|
|
194
|
-
return captured_stdout.string, captured_stderr.string
|
|
195
|
-
ensure
|
|
196
|
-
$stdout = orig_stdout
|
|
197
|
-
$stderr = orig_stderr
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
def exception_details e, msg
|
|
201
|
-
"#{msg}\nClass: <#{e.class}>\nMessage: <#{e.message.inspect}>\n---Backtrace---\n#{MiniTest::filter_backtrace(e.backtrace).join("\n")}\n---------------"
|
|
202
|
-
end
|
|
203
|
-
|
|
204
|
-
def flunk msg = nil
|
|
205
|
-
msg ||= "Epic Fail!"
|
|
206
|
-
assert false, msg
|
|
207
|
-
end
|
|
208
|
-
|
|
209
|
-
def message msg = nil, &default
|
|
210
|
-
proc {
|
|
211
|
-
if msg then
|
|
212
|
-
msg = msg.to_s unless String === msg
|
|
213
|
-
msg += '.' unless msg.empty?
|
|
214
|
-
msg += "\n#{default.call}."
|
|
215
|
-
msg.strip
|
|
216
|
-
else
|
|
217
|
-
"#{default.call}."
|
|
218
|
-
end
|
|
219
|
-
}
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
# used for counting assertions
|
|
223
|
-
def pass msg = nil
|
|
224
|
-
assert true
|
|
225
|
-
end
|
|
226
|
-
|
|
227
|
-
def refute test, msg = nil
|
|
228
|
-
msg ||= "Failed refutation, no message given"
|
|
229
|
-
not assert(! test, msg)
|
|
230
|
-
end
|
|
231
|
-
|
|
232
|
-
def refute_empty obj, msg = nil
|
|
233
|
-
msg = message(msg) { "Expected #{obj.inspect} to not be empty" }
|
|
234
|
-
assert_respond_to obj, :empty?
|
|
235
|
-
refute obj.empty?, msg
|
|
236
|
-
end
|
|
237
|
-
|
|
238
|
-
def refute_equal exp, act, msg = nil
|
|
239
|
-
msg = message(msg) { "Expected #{mu_pp(act)} to not be equal to #{mu_pp(exp)}" }
|
|
240
|
-
refute exp == act, msg
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
def refute_in_delta exp, act, delta = 0.001, msg = nil
|
|
244
|
-
n = (exp - act).abs
|
|
245
|
-
msg = message(msg) { "Expected #{exp} - #{act} (#{n}) to not be < #{delta}" }
|
|
246
|
-
refute delta > n, msg
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
def refute_in_epsilon a, b, epsilon = 0.001, msg = nil
|
|
250
|
-
refute_in_delta a, b, a * epsilon, msg
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
def refute_includes collection, obj, msg = nil
|
|
254
|
-
msg = message(msg) { "Expected #{mu_pp(collection)} to not include #{mu_pp(obj)}" }
|
|
255
|
-
assert_respond_to collection, :include?
|
|
256
|
-
refute collection.include?(obj), msg
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
def refute_instance_of cls, obj, msg = nil
|
|
260
|
-
msg = message(msg) { "Expected #{mu_pp(obj)} to not be an instance of #{cls}" }
|
|
261
|
-
flip = (Module === obj) && ! (Module === cls) # HACK for specs
|
|
262
|
-
obj, cls = cls, obj if flip
|
|
263
|
-
refute cls === obj, msg
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
def refute_kind_of cls, obj, msg = nil # TODO: merge with instance_of
|
|
267
|
-
msg = message(msg) { "Expected #{mu_pp(obj)} to not be a kind of #{cls}" }
|
|
268
|
-
flip = (Module === obj) && ! (Module === cls) # HACK for specs
|
|
269
|
-
obj, cls = cls, obj if flip
|
|
270
|
-
refute obj.kind_of?(cls), msg
|
|
271
|
-
end
|
|
272
|
-
|
|
273
|
-
def refute_match exp, act, msg = nil
|
|
274
|
-
msg = message(msg) { "Expected #{mu_pp(act)} to not match #{mu_pp(exp)}" }
|
|
275
|
-
refute act =~ exp, msg
|
|
276
|
-
end
|
|
277
|
-
|
|
278
|
-
def refute_nil obj, msg = nil
|
|
279
|
-
msg = message(msg) { "Expected #{mu_pp(obj)} to not be nil" }
|
|
280
|
-
refute obj.nil?, msg
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
def refute_operator o1, op, o2, msg = nil
|
|
284
|
-
msg = message(msg) { "Expected #{mu_pp(o1)} to not be #{op} #{mu_pp(o2)}" }
|
|
285
|
-
refute o1.__send__(op, o2), msg
|
|
286
|
-
end
|
|
287
|
-
|
|
288
|
-
def refute_respond_to obj, meth, msg = nil
|
|
289
|
-
msg = message(msg) { "Expected #{mu_pp(obj)} to not respond to #{meth}" }
|
|
290
|
-
flip = (Symbol === obj) && ! (Symbol === meth) # HACK for specs
|
|
291
|
-
obj, meth = meth, obj if flip
|
|
292
|
-
refute obj.respond_to?(meth), msg
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
def refute_same exp, act, msg = nil
|
|
296
|
-
msg = message(msg) { "Expected #{mu_pp(act)} to not be the same as #{mu_pp(exp)}" }
|
|
297
|
-
refute exp.equal?(act), msg
|
|
298
|
-
end
|
|
299
|
-
|
|
300
|
-
def skip msg = nil
|
|
301
|
-
msg ||= "Skipped, no message given"
|
|
302
|
-
raise MiniTest::Skip, msg
|
|
303
|
-
end
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
class Unit
|
|
307
|
-
VERSION = "1.3.0"
|
|
308
|
-
|
|
309
|
-
attr_accessor :report, :failures, :errors, :skips
|
|
310
|
-
attr_accessor :test_count, :assertion_count
|
|
311
|
-
|
|
312
|
-
@@installed_at_exit ||= false
|
|
313
|
-
@@out = $stdout
|
|
314
|
-
|
|
315
|
-
def self.autorun
|
|
316
|
-
at_exit {
|
|
317
|
-
exit_code = MiniTest::Unit.new.run(ARGV)
|
|
318
|
-
exit false if exit_code && exit_code != 0
|
|
319
|
-
} unless @@installed_at_exit
|
|
320
|
-
@@installed_at_exit = true
|
|
321
|
-
end
|
|
322
|
-
|
|
323
|
-
def self.output= stream
|
|
324
|
-
@@out = stream
|
|
325
|
-
end
|
|
326
|
-
|
|
327
|
-
def location e
|
|
328
|
-
e.backtrace.find { |s|
|
|
329
|
-
s !~ /in .(assert|refute|flunk|pass|fail|raise)/
|
|
330
|
-
}.sub(/:in .*$/, '')
|
|
331
|
-
end
|
|
332
|
-
|
|
333
|
-
def puke klass, meth, e
|
|
334
|
-
e = case e
|
|
335
|
-
when MiniTest::Skip then
|
|
336
|
-
@skips += 1
|
|
337
|
-
"Skipped:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
|
|
338
|
-
when MiniTest::Assertion then
|
|
339
|
-
@failures += 1
|
|
340
|
-
"Failure:\n#{meth}(#{klass}) [#{location e}]:\n#{e.message}\n"
|
|
341
|
-
else
|
|
342
|
-
@errors += 1
|
|
343
|
-
bt = MiniTest::filter_backtrace(e.backtrace).join("\n ")
|
|
344
|
-
"Error:\n#{meth}(#{klass}):\n#{e.class}: #{e.message}\n #{bt}\n"
|
|
345
|
-
end
|
|
346
|
-
@report << e
|
|
347
|
-
e[0, 1]
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
def initialize
|
|
351
|
-
@report = []
|
|
352
|
-
@errors = @failures = @skips = 0
|
|
353
|
-
@verbose = false
|
|
354
|
-
end
|
|
355
|
-
|
|
356
|
-
##
|
|
357
|
-
# Top level driver, controls all output and filtering.
|
|
358
|
-
|
|
359
|
-
def run args = []
|
|
360
|
-
@verbose = args.delete('-v')
|
|
361
|
-
|
|
362
|
-
filter = if args.first =~ /^(-n|--name)$/ then
|
|
363
|
-
args.shift
|
|
364
|
-
arg = args.shift
|
|
365
|
-
arg =~ /\/(.*)\// ? Regexp.new($1) : arg
|
|
366
|
-
else
|
|
367
|
-
/./ # anything - ^test_ already filtered by #tests
|
|
368
|
-
end
|
|
369
|
-
|
|
370
|
-
@@out.puts "Loaded suite #{$0.sub(/\.rb$/, '')}\nStarted"
|
|
371
|
-
|
|
372
|
-
start = Time.now
|
|
373
|
-
run_test_suites filter
|
|
374
|
-
|
|
375
|
-
@@out.puts
|
|
376
|
-
@@out.puts "Finished in #{'%.6f' % (Time.now - start)} seconds."
|
|
377
|
-
|
|
378
|
-
@report.each_with_index do |msg, i|
|
|
379
|
-
@@out.puts "\n%3d) %s" % [i + 1, msg]
|
|
380
|
-
end
|
|
381
|
-
|
|
382
|
-
@@out.puts
|
|
383
|
-
|
|
384
|
-
format = "%d tests, %d assertions, %d failures, %d errors, %d skips"
|
|
385
|
-
@@out.puts format % [test_count, assertion_count, failures, errors, skips]
|
|
386
|
-
|
|
387
|
-
return failures + errors if @test_count > 0 # or return nil...
|
|
388
|
-
end
|
|
389
|
-
|
|
390
|
-
def run_test_suites filter = /./
|
|
391
|
-
@test_count, @assertion_count = 0, 0
|
|
392
|
-
old_sync, @@out.sync = @@out.sync, true if @@out.respond_to? :sync=
|
|
393
|
-
TestCase.test_suites.each do |suite|
|
|
394
|
-
suite.test_methods.grep(filter).each do |test|
|
|
395
|
-
inst = suite.new test
|
|
396
|
-
inst._assertions = 0
|
|
397
|
-
@@out.print "#{suite}##{test}: " if @verbose
|
|
398
|
-
|
|
399
|
-
t = Time.now if @verbose
|
|
400
|
-
result = inst.run(self)
|
|
401
|
-
|
|
402
|
-
@@out.print "%.2f s: " % (Time.now - t) if @verbose
|
|
403
|
-
@@out.print result
|
|
404
|
-
@@out.puts if @verbose
|
|
405
|
-
@test_count += 1
|
|
406
|
-
@assertion_count += inst._assertions
|
|
407
|
-
end
|
|
408
|
-
end
|
|
409
|
-
@@out.sync = old_sync if @@out.respond_to? :sync=
|
|
410
|
-
[@test_count, @assertion_count]
|
|
411
|
-
end
|
|
412
|
-
|
|
413
|
-
class TestCase
|
|
414
|
-
attr_reader :name
|
|
415
|
-
|
|
416
|
-
def run runner
|
|
417
|
-
result = '.'
|
|
418
|
-
begin
|
|
419
|
-
@passed = nil
|
|
420
|
-
self.setup
|
|
421
|
-
self.__send__ self.name
|
|
422
|
-
@passed = true
|
|
423
|
-
rescue Exception => e
|
|
424
|
-
@passed = false
|
|
425
|
-
result = runner.puke(self.class, self.name, e)
|
|
426
|
-
ensure
|
|
427
|
-
begin
|
|
428
|
-
self.teardown
|
|
429
|
-
rescue Exception => e
|
|
430
|
-
result = runner.puke(self.class, self.name, e)
|
|
431
|
-
end
|
|
432
|
-
end
|
|
433
|
-
result
|
|
434
|
-
end
|
|
435
|
-
|
|
436
|
-
def initialize name
|
|
437
|
-
@name = name
|
|
438
|
-
@passed = nil
|
|
439
|
-
end
|
|
440
|
-
|
|
441
|
-
def self.reset
|
|
442
|
-
@@test_suites = {}
|
|
443
|
-
end
|
|
444
|
-
|
|
445
|
-
reset
|
|
446
|
-
|
|
447
|
-
def self.inherited klass
|
|
448
|
-
@@test_suites[klass] = true
|
|
449
|
-
end
|
|
450
|
-
|
|
451
|
-
def self.test_order
|
|
452
|
-
:random
|
|
453
|
-
end
|
|
454
|
-
|
|
455
|
-
def self.test_suites
|
|
456
|
-
@@test_suites.keys.sort_by { |ts| ts.name }
|
|
457
|
-
end
|
|
458
|
-
|
|
459
|
-
def self.test_methods
|
|
460
|
-
methods = public_instance_methods(true).grep(/^test/).map { |m|
|
|
461
|
-
m.to_s
|
|
462
|
-
}.sort
|
|
463
|
-
|
|
464
|
-
if self.test_order == :random then
|
|
465
|
-
max = methods.size
|
|
466
|
-
methods = methods.sort_by { rand(max) }
|
|
467
|
-
end
|
|
468
|
-
|
|
469
|
-
methods
|
|
470
|
-
end
|
|
471
|
-
|
|
472
|
-
def setup; end
|
|
473
|
-
def teardown; end
|
|
474
|
-
|
|
475
|
-
def passed?
|
|
476
|
-
@passed
|
|
477
|
-
end
|
|
478
|
-
|
|
479
|
-
include MiniTest::Assertions
|
|
480
|
-
end # class TestCase
|
|
481
|
-
end # class Test
|
|
482
|
-
end # module Mini
|
data/test/test_mini_mock.rb
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
require 'minitest/mock'
|
|
2
|
-
require 'minitest/unit'
|
|
3
|
-
|
|
4
|
-
MiniTest::Unit.autorun
|
|
5
|
-
|
|
6
|
-
class TestMiniMock < MiniTest::Unit::TestCase
|
|
7
|
-
def setup
|
|
8
|
-
@mock = MiniTest::Mock.new.expect(:foo, nil)
|
|
9
|
-
@mock.expect(:meaning_of_life, 42)
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def test_should_create_stub_method
|
|
13
|
-
assert_nil @mock.foo
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def test_should_allow_return_value_specification
|
|
17
|
-
assert_equal 42, @mock.meaning_of_life
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_should_blow_up_if_not_called
|
|
21
|
-
@mock.foo
|
|
22
|
-
|
|
23
|
-
util_verify_bad
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def test_should_not_blow_up_if_everything_called
|
|
27
|
-
@mock.foo
|
|
28
|
-
@mock.meaning_of_life
|
|
29
|
-
|
|
30
|
-
assert @mock.verify
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def test_should_allow_expectations_to_be_added_after_creation
|
|
34
|
-
@mock.expect(:bar, true)
|
|
35
|
-
assert @mock.bar
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_should_not_verify_if_new_expected_method_is_not_called
|
|
39
|
-
@mock.foo
|
|
40
|
-
@mock.meaning_of_life
|
|
41
|
-
@mock.expect(:bar, true)
|
|
42
|
-
|
|
43
|
-
util_verify_bad
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def test_should_not_verify_if_unexpected_method_is_called
|
|
47
|
-
assert_raises NoMethodError do
|
|
48
|
-
@mock.unexpected
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
def test_should_blow_up_on_wrong_number_of_arguments
|
|
53
|
-
@mock.foo
|
|
54
|
-
@mock.meaning_of_life
|
|
55
|
-
@mock.expect(:sum, 3, [1, 2])
|
|
56
|
-
|
|
57
|
-
assert_raises ArgumentError do
|
|
58
|
-
@mock.sum
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def test_should_blow_up_on_wrong_arguments
|
|
63
|
-
@mock.foo
|
|
64
|
-
@mock.meaning_of_life
|
|
65
|
-
@mock.expect(:sum, 3, [1, 2])
|
|
66
|
-
|
|
67
|
-
@mock.sum(2, 4)
|
|
68
|
-
|
|
69
|
-
util_verify_bad
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def util_verify_bad
|
|
73
|
-
assert_raises MockExpectationError do
|
|
74
|
-
@mock.verify
|
|
75
|
-
end
|
|
76
|
-
end
|
|
77
|
-
end
|
data/test/test_mini_spec.rb
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
require 'minitest/spec'
|
|
2
|
-
|
|
3
|
-
MiniTest::Unit.autorun
|
|
4
|
-
|
|
5
|
-
describe MiniTest::Spec do
|
|
6
|
-
before do
|
|
7
|
-
@assertion_count = 5
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
after do
|
|
11
|
-
self._assertions.must_equal @assertion_count
|
|
12
|
-
end
|
|
13
|
-
|
|
14
|
-
it "needs to have all methods named well" do
|
|
15
|
-
@assertion_count = 2
|
|
16
|
-
|
|
17
|
-
methods = Object.public_instance_methods.find_all { |n| n =~ /^must|^wont/ }
|
|
18
|
-
methods.map! { |m| m.to_s } if Symbol === methods.first
|
|
19
|
-
|
|
20
|
-
musts, wonts = methods.sort.partition { |m| m =~ /^must/ }
|
|
21
|
-
|
|
22
|
-
expected_musts = %w(must_be
|
|
23
|
-
must_be_close_to
|
|
24
|
-
must_be_empty
|
|
25
|
-
must_be_instance_of
|
|
26
|
-
must_be_kind_of
|
|
27
|
-
must_be_nil
|
|
28
|
-
must_be_same_as
|
|
29
|
-
must_be_within_delta
|
|
30
|
-
must_be_within_epsilon
|
|
31
|
-
must_equal
|
|
32
|
-
must_include
|
|
33
|
-
must_match
|
|
34
|
-
must_raise
|
|
35
|
-
must_respond_to
|
|
36
|
-
must_send
|
|
37
|
-
must_throw)
|
|
38
|
-
|
|
39
|
-
expected_wonts = expected_musts.map { |m| m.sub(/^must/, 'wont') }
|
|
40
|
-
expected_wonts.reject! { |m| m =~ /wont_(not|raise|throw|send)/ }
|
|
41
|
-
|
|
42
|
-
musts.must_equal expected_musts
|
|
43
|
-
wonts.must_equal expected_wonts
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it "needs to verify equality" do
|
|
47
|
-
(6 * 7).must_equal(42).must_equal true
|
|
48
|
-
proc { (6 * 9).must_equal(42) }.must_raise MiniTest::Assertion
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
it "needs to verify floats within a delta" do
|
|
52
|
-
(6.0 * 7).must_be_close_to(42.0).must_equal true
|
|
53
|
-
proc { 42.002.must_be_close_to 42.0 }.must_raise MiniTest::Assertion
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it "needs to verify types of objects" do
|
|
57
|
-
(6 * 7).must_be_instance_of(Fixnum).must_equal true
|
|
58
|
-
proc { (6 * 7).must_be_instance_of String }.must_raise MiniTest::Assertion
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
it "needs to verify kinds of objects" do
|
|
62
|
-
@assertion_count = 7
|
|
63
|
-
|
|
64
|
-
(6 * 7).must_be_kind_of(Fixnum).must_equal true
|
|
65
|
-
(6 * 7).must_be_kind_of(Numeric).must_equal true
|
|
66
|
-
proc { (6 * 7).must_be_kind_of String }.must_raise MiniTest::Assertion
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it "needs to verify regexp matches" do
|
|
70
|
-
@assertion_count = 7
|
|
71
|
-
"blah".must_match(/\w+/).must_equal true
|
|
72
|
-
proc { "blah".must_match(/\d+/) }.must_raise MiniTest::Assertion
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
it "needs to verify nil" do
|
|
76
|
-
nil.must_be_nil.must_equal true
|
|
77
|
-
proc { 42.must_be_nil }.must_raise MiniTest::Assertion
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it "needs to verify using any operator" do
|
|
81
|
-
41.must_be(:<, 42).must_equal true
|
|
82
|
-
proc { 42.must_be(:<, 41) }.must_raise MiniTest::Assertion
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it "needs to catch an expected exception" do
|
|
86
|
-
@assertion_count = 4
|
|
87
|
-
|
|
88
|
-
proc { raise "blah" }.must_raise RuntimeError
|
|
89
|
-
proc { raise MiniTest::Assertion }.must_raise MiniTest::Assertion
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
it "needs to catch an unexpected exception" do
|
|
93
|
-
@assertion_count = 4
|
|
94
|
-
|
|
95
|
-
proc {
|
|
96
|
-
proc { raise MiniTest::Assertion }.must_raise(RuntimeError)
|
|
97
|
-
}.must_raise MiniTest::Assertion
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "needs raise if an expected exception is not raised" do
|
|
101
|
-
@assertion_count = 3
|
|
102
|
-
|
|
103
|
-
proc { proc { 42 }.must_raise(RuntimeError) }.must_raise MiniTest::Assertion
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it "needs to be able to catch a MiniTest::Assertion exception" do
|
|
107
|
-
@assertion_count = 3
|
|
108
|
-
|
|
109
|
-
proc { 1.wont_equal 1 }.must_raise MiniTest::Assertion
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
it "needs to verify using respond_to" do
|
|
113
|
-
42.must_respond_to(:+).must_equal true
|
|
114
|
-
proc { 42.must_respond_to(:clear) }.must_raise MiniTest::Assertion
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
it "needs to verify identity" do
|
|
118
|
-
1.must_be_same_as(1).must_equal true
|
|
119
|
-
proc { 1.must_be_same_as 2 }.must_raise MiniTest::Assertion
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it "needs to verify throw" do
|
|
123
|
-
@assertion_count = 8
|
|
124
|
-
|
|
125
|
-
proc { throw :blah }.must_throw(:blah).must_equal true
|
|
126
|
-
proc { proc { }.must_throw(:blah) }.must_raise MiniTest::Assertion
|
|
127
|
-
proc { proc { throw :xxx }.must_throw(:blah) }.must_raise MiniTest::Assertion
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
it "needs to verify inequality" do
|
|
131
|
-
42.wont_equal(6 * 9).must_equal false
|
|
132
|
-
proc { 1.wont_equal 1 }.must_raise MiniTest::Assertion
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
it "needs to verify mismatch" do
|
|
136
|
-
"blah".wont_match(/\d+/).must_equal false
|
|
137
|
-
proc { "blah".wont_match(/\w+/) }.must_raise MiniTest::Assertion
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it "needs to verify non-nil" do
|
|
141
|
-
42.wont_be_nil.must_equal false
|
|
142
|
-
proc { nil.wont_be_nil }.must_raise MiniTest::Assertion
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
it "needs to verify non-identity" do
|
|
146
|
-
1.wont_be_same_as(2).must_equal false
|
|
147
|
-
proc { 1.wont_be_same_as 1 }.must_raise MiniTest::Assertion
|
|
148
|
-
end
|
|
149
|
-
end
|