minitest 5.16.2 → 6.0.5

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.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/History.rdoc +373 -1
  4. data/Manifest.txt +16 -4
  5. data/README.rdoc +48 -118
  6. data/Rakefile +17 -2
  7. data/bin/minitest +5 -0
  8. data/design_rationale.rb +21 -19
  9. data/lib/hoe/minitest.rb +4 -2
  10. data/lib/minitest/assertions.rb +142 -124
  11. data/lib/minitest/autorun.rb +3 -11
  12. data/lib/minitest/benchmark.rb +9 -12
  13. data/lib/minitest/bisect.rb +304 -0
  14. data/lib/minitest/complete.rb +56 -0
  15. data/lib/minitest/compress.rb +94 -0
  16. data/lib/minitest/error_on_warning.rb +11 -0
  17. data/lib/minitest/expectations.rb +18 -0
  18. data/lib/minitest/find_minimal_combination.rb +127 -0
  19. data/lib/minitest/hell.rb +1 -1
  20. data/lib/minitest/manual_plugins.rb +4 -0
  21. data/lib/minitest/parallel.rb +10 -8
  22. data/lib/minitest/path_expander.rb +432 -0
  23. data/lib/minitest/pride.rb +2 -2
  24. data/lib/minitest/pride_plugin.rb +17 -24
  25. data/lib/minitest/server.rb +49 -0
  26. data/lib/minitest/server_plugin.rb +88 -0
  27. data/lib/minitest/spec.rb +27 -46
  28. data/lib/minitest/sprint.rb +105 -0
  29. data/lib/minitest/sprint_plugin.rb +39 -0
  30. data/lib/minitest/test.rb +32 -52
  31. data/lib/minitest/test_task.rb +68 -42
  32. data/lib/minitest.rb +361 -215
  33. data/test/minitest/metametameta.rb +33 -19
  34. data/test/minitest/test_bisect.rb +249 -0
  35. data/test/minitest/test_find_minimal_combination.rb +138 -0
  36. data/test/minitest/test_minitest_assertions.rb +311 -173
  37. data/test/minitest/test_minitest_benchmark.rb +15 -1
  38. data/test/minitest/test_minitest_reporter.rb +148 -23
  39. data/test/minitest/test_minitest_spec.rb +157 -132
  40. data/test/minitest/test_minitest_test.rb +270 -204
  41. data/test/minitest/test_minitest_test_task.rb +18 -7
  42. data/test/minitest/test_path_expander.rb +229 -0
  43. data/test/minitest/test_server.rb +146 -0
  44. data.tar.gz.sig +2 -2
  45. metadata +97 -37
  46. metadata.gz.sig +0 -0
  47. data/.autotest +0 -34
  48. data/lib/minitest/mock.rb +0 -323
  49. data/lib/minitest/unit.rb +0 -42
  50. data/test/minitest/test_minitest_mock.rb +0 -1139
data/.autotest DELETED
@@ -1,34 +0,0 @@
1
- # -*- ruby -*-
2
-
3
- require 'autotest/restart'
4
- require 'autotest/rcov' if ENV['RCOV']
5
-
6
- Autotest.add_hook :initialize do |at|
7
- at.testlib = 'minitest/autorun'
8
-
9
- bench_tests = %w(TestMinitestBenchmark)
10
- mock_tests = %w(TestMinitestMock TestMinitestStub)
11
- spec_tests = %w(TestMinitestReporter TestMetaStatic TestMeta
12
- TestSpecInTestCase)
13
- unit_tests = %w(TestMinitestGuard TestMinitestRunnable
14
- TestMinitestRunner TestMinitestTest TestMinitestUnit
15
- TestMinitestUnitInherited TestMinitestUnitOrder
16
- TestMinitestUnitRecording TestMinitestUnitTestCase)
17
-
18
- {
19
- bench_tests => "test/minitest/test_minitest_benchmark.rb",
20
- mock_tests => "test/minitest/test_minitest_mock.rb",
21
- spec_tests => "test/minitest/test_minitest_reporter.rb",
22
- unit_tests => "test/minitest/test_minitest_unit.rb",
23
- }.each do |klasses, file|
24
- klasses.each do |klass|
25
- at.extra_class_map[klass] = file
26
- end
27
- end
28
-
29
- at.add_exception 'coverage.info'
30
- at.add_exception 'coverage'
31
- end
32
-
33
- # require 'autotest/rcov'
34
- # Autotest::RCov.command = 'rcov_info'
data/lib/minitest/mock.rb DELETED
@@ -1,323 +0,0 @@
1
- class MockExpectationError < StandardError; end # :nodoc:
2
-
3
- module Minitest # :nodoc:
4
-
5
- ##
6
- # A simple and clean mock object framework.
7
- #
8
- # All mock objects are an instance of Mock
9
-
10
- class Mock
11
- alias :__respond_to? :respond_to?
12
-
13
- overridden_methods = %w[
14
- ===
15
- class
16
- inspect
17
- instance_eval
18
- instance_variables
19
- object_id
20
- public_send
21
- respond_to_missing?
22
- send
23
- to_s
24
- ]
25
-
26
- instance_methods.each do |m|
27
- undef_method m unless overridden_methods.include?(m.to_s) || m =~ /^__/
28
- end
29
-
30
- overridden_methods.map(&:to_sym).each do |method_id|
31
- define_method method_id do |*args, **kwargs, &b|
32
- if @expected_calls.key? method_id then
33
- if kwargs.empty? then # FIX: drop this after 2.7 dead
34
- method_missing(method_id, *args, &b)
35
- else
36
- method_missing(method_id, *args, **kwargs, &b)
37
- end
38
- else
39
- if kwargs.empty? then # FIX: drop this after 2.7 dead
40
- super(*args, &b)
41
- else
42
- super(*args, **kwargs, &b)
43
- end
44
- end
45
- end
46
- end
47
-
48
- def initialize delegator = nil # :nodoc:
49
- @delegator = delegator
50
- @expected_calls = Hash.new { |calls, name| calls[name] = [] }
51
- @actual_calls = Hash.new { |calls, name| calls[name] = [] }
52
- end
53
-
54
- @@KW_WARNED = false # :nodoc:
55
-
56
- ##
57
- # Expect that method +name+ is called, optionally with +args+ (and
58
- # +kwargs+ or a +blk+, and returns +retval+.
59
- #
60
- # @mock.expect(:meaning_of_life, 42)
61
- # @mock.meaning_of_life # => 42
62
- #
63
- # @mock.expect(:do_something_with, true, [some_obj, true])
64
- # @mock.do_something_with(some_obj, true) # => true
65
- #
66
- # @mock.expect(:do_something_else, true) do |a1, a2|
67
- # a1 == "buggs" && a2 == :bunny
68
- # end
69
- #
70
- # +args+ is compared to the expected args using case equality (ie, the
71
- # '===' operator), allowing for less specific expectations.
72
- #
73
- # @mock.expect(:uses_any_string, true, [String])
74
- # @mock.uses_any_string("foo") # => true
75
- # @mock.verify # => true
76
- #
77
- # @mock.expect(:uses_one_string, true, ["foo"])
78
- # @mock.uses_one_string("bar") # => raises MockExpectationError
79
- #
80
- # If a method will be called multiple times, specify a new expect for each one.
81
- # They will be used in the order you define them.
82
- #
83
- # @mock.expect(:ordinal_increment, 'first')
84
- # @mock.expect(:ordinal_increment, 'second')
85
- #
86
- # @mock.ordinal_increment # => 'first'
87
- # @mock.ordinal_increment # => 'second'
88
- # @mock.ordinal_increment # => raises MockExpectationError "No more expects available for :ordinal_increment"
89
- #
90
-
91
- def expect name, retval, args = [], **kwargs, &blk
92
- name = name.to_sym
93
-
94
- if block_given?
95
- raise ArgumentError, "args ignored when block given" unless args.empty?
96
- raise ArgumentError, "kwargs ignored when block given" unless kwargs.empty?
97
- @expected_calls[name] << { :retval => retval, :block => blk }
98
- else
99
- raise ArgumentError, "args must be an array" unless Array === args
100
-
101
- if ENV["MT_KWARGS_HAC\K"] && (Hash === args.last ||
102
- Hash == args.last) then
103
- if kwargs.empty? then
104
- kwargs = args.pop
105
- else
106
- unless @@KW_WARNED then
107
- from = caller.first
108
- warn "Using MT_KWARGS_HAC\K yet passing kwargs. From #{from}"
109
- @@KW_WARNED = true
110
- end
111
- end
112
- end
113
-
114
- @expected_calls[name] <<
115
- { :retval => retval, :args => args, :kwargs => kwargs }
116
- end
117
- self
118
- end
119
-
120
- def __call name, data # :nodoc:
121
- case data
122
- when Hash then
123
- args = data[:args].inspect[1..-2]
124
- kwargs = data[:kwargs]
125
- if kwargs && !kwargs.empty? then
126
- args << ", " unless args.empty?
127
- args << kwargs.inspect[1..-2]
128
- end
129
- "#{name}(#{args}) => #{data[:retval].inspect}"
130
- else
131
- data.map { |d| __call name, d }.join ", "
132
- end
133
- end
134
-
135
- ##
136
- # Verify that all methods were called as expected. Raises
137
- # +MockExpectationError+ if the mock object was not called as
138
- # expected.
139
-
140
- def verify
141
- @expected_calls.each do |name, expected|
142
- actual = @actual_calls.fetch(name, nil)
143
- raise MockExpectationError, "expected #{__call name, expected[0]}" unless actual
144
- raise MockExpectationError, "expected #{__call name, expected[actual.size]}, got [#{__call name, actual}]" if
145
- actual.size < expected.size
146
- end
147
- true
148
- end
149
-
150
- def method_missing sym, *args, **kwargs, &block # :nodoc:
151
- unless @expected_calls.key?(sym) then
152
- if @delegator && @delegator.respond_to?(sym)
153
- return @delegator.public_send(sym, *args, **kwargs, &block)
154
- else
155
- raise NoMethodError, "unmocked method %p, expected one of %p" %
156
- [sym, @expected_calls.keys.sort_by(&:to_s)]
157
- end
158
- end
159
-
160
- index = @actual_calls[sym].length
161
- expected_call = @expected_calls[sym][index]
162
-
163
- unless expected_call then
164
- raise MockExpectationError, "No more expects available for %p: %p %p" %
165
- [sym, args, kwargs]
166
- end
167
-
168
- expected_args, expected_kwargs, retval, val_block =
169
- expected_call.values_at(:args, :kwargs, :retval, :block)
170
-
171
- expected_kwargs = kwargs.map { |ak, av| [ak, Object] }.to_h if
172
- Hash == expected_kwargs
173
-
174
- if val_block then
175
- # keep "verify" happy
176
- @actual_calls[sym] << expected_call
177
-
178
- raise MockExpectationError, "mocked method %p failed block w/ %p %p" %
179
- [sym, args, kwargs] unless val_block.call(*args, **kwargs, &block)
180
-
181
- return retval
182
- end
183
-
184
- if expected_args.size != args.size then
185
- raise ArgumentError, "mocked method %p expects %d arguments, got %p" %
186
- [sym, expected_args.size, args]
187
- end
188
-
189
- if expected_kwargs.size != kwargs.size then
190
- raise ArgumentError, "mocked method %p expects %d keyword arguments, got %p" %
191
- [sym, expected_kwargs.size, kwargs]
192
- end
193
-
194
- zipped_args = expected_args.zip(args)
195
- fully_matched = zipped_args.all? { |mod, a|
196
- mod === a or mod == a
197
- }
198
-
199
- unless fully_matched then
200
- fmt = "mocked method %p called with unexpected arguments %p"
201
- raise MockExpectationError, fmt % [sym, args]
202
- end
203
-
204
- unless expected_kwargs.keys.sort == kwargs.keys.sort then
205
- fmt = "mocked method %p called with unexpected keywords %p vs %p"
206
- raise MockExpectationError, fmt % [sym, expected_kwargs.keys, kwargs.keys]
207
- end
208
-
209
- zipped_kwargs = expected_kwargs.map { |ek, ev|
210
- av = kwargs[ek]
211
- [ek, [ev, av]]
212
- }.to_h
213
-
214
- fully_matched = zipped_kwargs.all? { |ek, (ev, av)|
215
- ev === av or ev == av
216
- }
217
-
218
- unless fully_matched then
219
- fmt = "mocked method %p called with unexpected keyword arguments %p vs %p"
220
- raise MockExpectationError, fmt % [sym, expected_kwargs, kwargs]
221
- end
222
-
223
- @actual_calls[sym] << {
224
- :retval => retval,
225
- :args => zipped_args.map { |e, a| e === a ? e : a },
226
- :kwargs => zipped_kwargs.map { |k, (e, a)| [k, e === a ? e : a] }.to_h,
227
- }
228
-
229
- retval
230
- end
231
-
232
- def respond_to? sym, include_private = false # :nodoc:
233
- return true if @expected_calls.key? sym.to_sym
234
- return true if @delegator && @delegator.respond_to?(sym, include_private)
235
- __respond_to?(sym, include_private)
236
- end
237
- end
238
- end
239
-
240
- module Minitest::Assertions
241
- ##
242
- # Assert that the mock verifies correctly.
243
-
244
- def assert_mock mock
245
- assert mock.verify
246
- end
247
- end
248
-
249
- ##
250
- # Object extensions for Minitest::Mock.
251
-
252
- class Object
253
-
254
- ##
255
- # Add a temporary stubbed method replacing +name+ for the duration
256
- # of the +block+. If +val_or_callable+ responds to #call, then it
257
- # returns the result of calling it, otherwise returns the value
258
- # as-is. If stubbed method yields a block, +block_args+ will be
259
- # passed along. Cleans up the stub at the end of the +block+. The
260
- # method +name+ must exist before stubbing.
261
- #
262
- # def test_stale_eh
263
- # obj_under_test = Something.new
264
- # refute obj_under_test.stale?
265
- #
266
- # Time.stub :now, Time.at(0) do
267
- # assert obj_under_test.stale?
268
- # end
269
- # end
270
- #--
271
- # NOTE: keyword args in callables are NOT checked for correctness
272
- # against the existing method. Too many edge cases to be worth it.
273
-
274
- def stub name, val_or_callable, *block_args, **block_kwargs, &block
275
- new_name = "__minitest_stub__#{name}"
276
-
277
- metaclass = class << self; self; end
278
-
279
- if respond_to? name and not methods.map(&:to_s).include? name.to_s then
280
- metaclass.send :define_method, name do |*args, **kwargs|
281
- super(*args, **kwargs)
282
- end
283
- end
284
-
285
- metaclass.send :alias_method, new_name, name
286
-
287
- if ENV["MT_KWARGS_HAC\K"] then
288
- metaclass.send :define_method, name do |*args, &blk|
289
- if val_or_callable.respond_to? :call then
290
- val_or_callable.call(*args, &blk)
291
- else
292
- blk.call(*block_args, **block_kwargs) if blk
293
- val_or_callable
294
- end
295
- end
296
- else
297
- metaclass.send :define_method, name do |*args, **kwargs, &blk|
298
- if val_or_callable.respond_to? :call then
299
- if kwargs.empty? then # FIX: drop this after 2.7 dead
300
- val_or_callable.call(*args, &blk)
301
- else
302
- val_or_callable.call(*args, **kwargs, &blk)
303
- end
304
- else
305
- if blk then
306
- if block_kwargs.empty? then # FIX: drop this after 2.7 dead
307
- blk.call(*block_args)
308
- else
309
- blk.call(*block_args, **block_kwargs)
310
- end
311
- end
312
- val_or_callable
313
- end
314
- end
315
- end
316
-
317
- block[self]
318
- ensure
319
- metaclass.send :undef_method, name
320
- metaclass.send :alias_method, name, new_name
321
- metaclass.send :undef_method, new_name
322
- end
323
- end
data/lib/minitest/unit.rb DELETED
@@ -1,42 +0,0 @@
1
- unless defined?(Minitest) then
2
- # all of this crap is just to avoid circular requires and is only
3
- # needed if a user requires "minitest/unit" directly instead of
4
- # "minitest/autorun", so we also warn
5
-
6
- from = caller.reject { |s| s =~ /rubygems/ }.join("\n ")
7
- warn "Warning: you should require 'minitest/autorun' instead."
8
- warn %(Warning: or add 'gem "minitest"' before 'require "minitest/autorun"')
9
- warn "From:\n #{from}"
10
-
11
- module Minitest # :nodoc:
12
- end
13
- MiniTest = Minitest # :nodoc: # prevents minitest.rb from requiring back to us
14
- require "minitest"
15
- end
16
-
17
- MiniTest = Minitest unless defined?(MiniTest)
18
-
19
- module Minitest
20
- class Unit # :nodoc:
21
- VERSION = Minitest::VERSION
22
- class TestCase < Minitest::Test # :nodoc:
23
- def self.inherited klass # :nodoc:
24
- from = caller.first
25
- warn "MiniTest::Unit::TestCase is now Minitest::Test. From #{from}"
26
- super
27
- end
28
- end
29
-
30
- def self.autorun # :nodoc:
31
- from = caller.first
32
- warn "MiniTest::Unit.autorun is now Minitest.autorun. From #{from}"
33
- Minitest.autorun
34
- end
35
-
36
- def self.after_tests &b # :nodoc:
37
- from = caller.first
38
- warn "MiniTest::Unit.after_tests is now Minitest.after_run. From #{from}"
39
- Minitest.after_run(&b)
40
- end
41
- end
42
- end