minitest 5.25.1 → 5.27.0
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +76 -0
- data/README.rdoc +25 -15
- data/Rakefile +18 -2
- data/design_rationale.rb +21 -19
- data/lib/hoe/minitest.rb +2 -1
- data/lib/minitest/assertions.rb +21 -26
- data/lib/minitest/autorun.rb +4 -4
- data/lib/minitest/benchmark.rb +2 -2
- data/lib/minitest/expectations.rb +2 -2
- data/lib/minitest/hell.rb +1 -1
- data/lib/minitest/manual_plugins.rb +1 -1
- data/lib/minitest/mock.rb +27 -29
- data/lib/minitest/parallel.rb +2 -0
- data/lib/minitest/pride.rb +1 -1
- data/lib/minitest/pride_plugin.rb +2 -2
- data/lib/minitest/spec.rb +17 -13
- data/lib/minitest/test.rb +5 -4
- data/lib/minitest/test_task.rb +28 -11
- data/lib/minitest/unit.rb +1 -1
- data/lib/minitest.rb +50 -34
- data/test/minitest/test_minitest_assertions.rb +19 -62
- data/test/minitest/test_minitest_mock.rb +77 -15
- data/test/minitest/test_minitest_reporter.rb +17 -16
- data/test/minitest/test_minitest_spec.rb +42 -28
- data/test/minitest/test_minitest_test.rb +20 -2
- data.tar.gz.sig +0 -0
- metadata +32 -22
- metadata.gz.sig +3 -1
data/lib/minitest/test.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
require_relative "../minitest" unless defined? Minitest::Runnable
|
|
2
2
|
|
|
3
3
|
module Minitest
|
|
4
4
|
##
|
|
@@ -8,9 +8,9 @@ module Minitest
|
|
|
8
8
|
# See Minitest::Assertions
|
|
9
9
|
|
|
10
10
|
class Test < Runnable
|
|
11
|
-
|
|
12
|
-
include Minitest::Assertions
|
|
11
|
+
require_relative "assertions"
|
|
13
12
|
include Minitest::Reportable
|
|
13
|
+
include Minitest::Assertions
|
|
14
14
|
|
|
15
15
|
def class_name # :nodoc:
|
|
16
16
|
self.class.name # for Minitest::Reportable
|
|
@@ -58,6 +58,7 @@ module Minitest
|
|
|
58
58
|
# tests are awesome.
|
|
59
59
|
|
|
60
60
|
def self.parallelize_me!
|
|
61
|
+
return unless Minitest.parallel_executor
|
|
61
62
|
include Minitest::Parallel::Test
|
|
62
63
|
extend Minitest::Parallel::Test::ClassMethods
|
|
63
64
|
end
|
|
@@ -234,4 +235,4 @@ module Minitest
|
|
|
234
235
|
end # Test
|
|
235
236
|
end
|
|
236
237
|
|
|
237
|
-
|
|
238
|
+
require_relative "unit" if ENV["MT_COMPAT"] # compatibility layer only
|
data/lib/minitest/test_task.rb
CHANGED
|
@@ -44,8 +44,16 @@ module Minitest # :nodoc:
|
|
|
44
44
|
WINDOWS = RbConfig::CONFIG["host_os"] =~ /mswin|mingw/ # :nodoc:
|
|
45
45
|
|
|
46
46
|
##
|
|
47
|
-
# Create several test-oriented tasks under +name
|
|
48
|
-
# optional block to customize variables.
|
|
47
|
+
# Create several test-oriented tasks under +name+ (default:
|
|
48
|
+
# "test"). Takes an optional block to customize variables.
|
|
49
|
+
# Examples:
|
|
50
|
+
#
|
|
51
|
+
# Minitest::TestTask.create # named "test", all defaults
|
|
52
|
+
#
|
|
53
|
+
# Minitest::TestTask.create do |t|
|
|
54
|
+
# t.warning = false # my tests are noisy
|
|
55
|
+
# t.framework = %(require_relative "./test/helper.rb")
|
|
56
|
+
# end
|
|
49
57
|
|
|
50
58
|
def self.create name = :test, &block
|
|
51
59
|
task = new name
|
|
@@ -69,9 +77,18 @@ module Minitest # :nodoc:
|
|
|
69
77
|
|
|
70
78
|
##
|
|
71
79
|
# The code to load the framework. Defaults to requiring
|
|
72
|
-
# minitest/autorun
|
|
80
|
+
# minitest/autorun.
|
|
81
|
+
#
|
|
82
|
+
# If you have a test helper file that requires minitest/autorun
|
|
83
|
+
# and anything else your project standardizes on, then you'll
|
|
84
|
+
# probably want to change this to:
|
|
85
|
+
#
|
|
86
|
+
# Minitest::TestTask.create do |t|
|
|
87
|
+
# t.framework = %(require_relative "./test/helper.rb")
|
|
88
|
+
# end
|
|
73
89
|
#
|
|
74
|
-
#
|
|
90
|
+
# or something similar. NOTE: if you do this, then helper must
|
|
91
|
+
# require "minitest/autorun" at the top to start the tests.
|
|
75
92
|
|
|
76
93
|
attr_accessor :framework
|
|
77
94
|
|
|
@@ -100,6 +117,11 @@ module Minitest # :nodoc:
|
|
|
100
117
|
|
|
101
118
|
##
|
|
102
119
|
# Optional: Additional ruby to run before the test framework is loaded.
|
|
120
|
+
# Example:
|
|
121
|
+
#
|
|
122
|
+
# Minitest::TestTask.create "test:cov" do |t|
|
|
123
|
+
# t.test_prelude = %(require "simplecov")
|
|
124
|
+
# end
|
|
103
125
|
|
|
104
126
|
attr_accessor :test_prelude
|
|
105
127
|
|
|
@@ -281,13 +303,8 @@ module Minitest # :nodoc:
|
|
|
281
303
|
end
|
|
282
304
|
|
|
283
305
|
class Work < Queue # :nodoc:
|
|
284
|
-
def initialize jobs
|
|
285
|
-
super
|
|
286
|
-
|
|
287
|
-
jobs.each do |job|
|
|
288
|
-
self << job
|
|
289
|
-
end
|
|
290
|
-
|
|
306
|
+
def initialize jobs # :nodoc:
|
|
307
|
+
super
|
|
291
308
|
close
|
|
292
309
|
end
|
|
293
310
|
end
|
data/lib/minitest/unit.rb
CHANGED
|
@@ -11,7 +11,7 @@ unless defined?(Minitest) then
|
|
|
11
11
|
module Minitest # :nodoc:
|
|
12
12
|
end
|
|
13
13
|
MiniTest = Minitest # :nodoc: # prevents minitest.rb from requiring back to us
|
|
14
|
-
|
|
14
|
+
require_relative "../minitest"
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
MiniTest = Minitest unless defined?(MiniTest)
|
data/lib/minitest.rb
CHANGED
|
@@ -6,10 +6,11 @@ require_relative "minitest/parallel"
|
|
|
6
6
|
require_relative "minitest/compress"
|
|
7
7
|
|
|
8
8
|
##
|
|
9
|
-
#
|
|
9
|
+
# The top-level namespace for Minitest. Also the location of the main
|
|
10
|
+
# runtime. See +Minitest.run+ for more information.
|
|
10
11
|
|
|
11
12
|
module Minitest
|
|
12
|
-
VERSION = "5.
|
|
13
|
+
VERSION = "5.26.2" # :nodoc:
|
|
13
14
|
|
|
14
15
|
@@installed_at_exit ||= false
|
|
15
16
|
@@after_run = []
|
|
@@ -35,7 +36,7 @@ module Minitest
|
|
|
35
36
|
warn "DEPRECATED: use MT_CPU instead of N for parallel test runs" if ENV["N"] && ENV["N"].to_i > 0
|
|
36
37
|
n_threads = (ENV["MT_CPU"] || ENV["N"] || Etc.nprocessors).to_i
|
|
37
38
|
|
|
38
|
-
self.parallel_executor = Parallel::Executor.new n_threads
|
|
39
|
+
self.parallel_executor = Parallel::Executor.new n_threads if n_threads > 1
|
|
39
40
|
|
|
40
41
|
##
|
|
41
42
|
# Filter object for backtraces.
|
|
@@ -67,8 +68,7 @@ module Minitest
|
|
|
67
68
|
# Registers Minitest to run at process exit
|
|
68
69
|
|
|
69
70
|
def self.autorun
|
|
70
|
-
Warning[:deprecated] = true
|
|
71
|
-
Object.const_defined?(:Warning) && Warning.respond_to?(:[]=)
|
|
71
|
+
Warning[:deprecated] = true
|
|
72
72
|
|
|
73
73
|
at_exit {
|
|
74
74
|
next if $! and not ($!.kind_of? SystemExit and $!.success?)
|
|
@@ -146,26 +146,32 @@ module Minitest
|
|
|
146
146
|
orig_args = args.dup
|
|
147
147
|
|
|
148
148
|
OptionParser.new do |opts|
|
|
149
|
-
opts.
|
|
149
|
+
opts.program_name = "minitest"
|
|
150
150
|
opts.version = Minitest::VERSION
|
|
151
151
|
|
|
152
|
+
opts.banner = [
|
|
153
|
+
"Usage: rake test [A=options] (see Minitest::TestTask for more options)",
|
|
154
|
+
"minitest [paths] [options] (with minitest-sprint gem)",
|
|
155
|
+
"ruby path/to/test.rb [options]\n\n",
|
|
156
|
+
].join "\n or: "
|
|
157
|
+
|
|
152
158
|
opts.on "-h", "--help", "Display this help." do
|
|
153
159
|
puts opts
|
|
154
160
|
exit
|
|
155
161
|
end
|
|
156
162
|
|
|
157
|
-
opts.on "--no-plugins", "Bypass minitest plugin auto-loading (or
|
|
163
|
+
opts.on "--no-plugins", "Bypass minitest plugin auto-loading (or env: MT_NO_PLUGINS=1)."
|
|
158
164
|
|
|
159
|
-
desc = "Sets random seed. Also via env
|
|
165
|
+
desc = "Sets random seed. Also via env, eg: SEED=42"
|
|
160
166
|
opts.on "-s", "--seed SEED", Integer, desc do |m|
|
|
161
|
-
options[:seed] = m
|
|
167
|
+
options[:seed] = m
|
|
162
168
|
end
|
|
163
169
|
|
|
164
|
-
opts.on "-v", "--verbose", "Verbose.
|
|
170
|
+
opts.on "-v", "--verbose", "Verbose. Print each name as they run." do
|
|
165
171
|
options[:verbose] = true
|
|
166
172
|
end
|
|
167
173
|
|
|
168
|
-
opts.on "-q", "--quiet", "Quiet. Show no
|
|
174
|
+
opts.on "-q", "--quiet", "Quiet. Show no dots while processing files." do
|
|
169
175
|
options[:quiet] = true
|
|
170
176
|
end
|
|
171
177
|
|
|
@@ -173,7 +179,7 @@ module Minitest
|
|
|
173
179
|
options[:show_skips] = true
|
|
174
180
|
end
|
|
175
181
|
|
|
176
|
-
opts.on "-n", "--name PATTERN", "
|
|
182
|
+
opts.on "-n", "--name PATTERN", "Include /regexp/ or string for run." do |a|
|
|
177
183
|
options[:filter] = a
|
|
178
184
|
end
|
|
179
185
|
|
|
@@ -181,21 +187,28 @@ module Minitest
|
|
|
181
187
|
options[:exclude] = a
|
|
182
188
|
end
|
|
183
189
|
|
|
190
|
+
# part of my unofficial embedded gem "makeoptparseworkwell"
|
|
191
|
+
def opts.topdict(name) = (name.length > 1 ? top.long : top.short)
|
|
192
|
+
def opts.alias(from, to) = (dict = topdict(from) ; dict[to] = dict[from])
|
|
193
|
+
|
|
194
|
+
# these will work but won't show up in --help output:
|
|
195
|
+
opts.alias "name", "include"
|
|
196
|
+
opts.alias "n", "i"
|
|
197
|
+
opts.alias "e", "x"
|
|
198
|
+
|
|
184
199
|
opts.on "-S", "--skip CODES", String, "Skip reporting of certain types of results (eg E)." do |s|
|
|
185
200
|
options[:skip] = s.chars.to_a
|
|
186
201
|
end
|
|
187
202
|
|
|
188
|
-
ruby27plus = ::Warning.respond_to? :[]=
|
|
189
|
-
|
|
190
203
|
opts.on "-W[error]", String, "Turn Ruby warnings into errors" do |s|
|
|
191
204
|
options[:Werror] = true
|
|
192
205
|
case s
|
|
193
206
|
when "error", "all", nil then
|
|
194
|
-
|
|
207
|
+
require_relative "minitest/error_on_warning"
|
|
195
208
|
$VERBOSE = true
|
|
196
|
-
::Warning[:deprecated] = true
|
|
209
|
+
::Warning[:deprecated] = true
|
|
197
210
|
else
|
|
198
|
-
::Warning[s.to_sym] = true
|
|
211
|
+
::Warning[s.to_sym] = true # check validity of category
|
|
199
212
|
end
|
|
200
213
|
end
|
|
201
214
|
|
|
@@ -258,12 +271,13 @@ module Minitest
|
|
|
258
271
|
# Minitest.process_args
|
|
259
272
|
# Minitest.init_plugins
|
|
260
273
|
# Minitest.__run(reporter, options)
|
|
261
|
-
# Runnable.runnables.each
|
|
274
|
+
# Runnable.runnables.each |runnable_klass|
|
|
262
275
|
# runnable_klass.run(reporter, options)
|
|
263
|
-
#
|
|
264
|
-
#
|
|
265
|
-
#
|
|
266
|
-
#
|
|
276
|
+
# filtered_methods = runnable_methods.select {...}.reject {...}
|
|
277
|
+
# filtered_methods.each |runnable_method|
|
|
278
|
+
# runnable_klass.run_one_method(self, runnable_method, reporter)
|
|
279
|
+
# Minitest.run_one_method(runnable_klass, runnable_method)
|
|
280
|
+
# runnable_klass.new(runnable_method).run
|
|
267
281
|
|
|
268
282
|
def self.run args = []
|
|
269
283
|
self.load_plugins unless args.delete("--no-plugins") || ENV["MT_NO_PLUGINS"]
|
|
@@ -285,18 +299,19 @@ module Minitest
|
|
|
285
299
|
reporter.start
|
|
286
300
|
begin
|
|
287
301
|
__run reporter, options
|
|
302
|
+
finished = true
|
|
288
303
|
rescue Interrupt
|
|
289
304
|
warn "Interrupted. Exiting..."
|
|
290
305
|
end
|
|
291
|
-
self.parallel_executor.shutdown
|
|
306
|
+
self.parallel_executor.shutdown if parallel_executor.respond_to? :shutdown
|
|
292
307
|
|
|
293
308
|
# might have been removed/replaced during init_plugins:
|
|
294
309
|
summary = reporter.reporters.grep(SummaryReporter).first
|
|
295
310
|
|
|
296
311
|
reporter.report
|
|
297
312
|
|
|
298
|
-
return empty_run! options if summary && summary.count == 0
|
|
299
|
-
reporter.passed?
|
|
313
|
+
return empty_run! options if finished && summary && summary.count == 0
|
|
314
|
+
finished and reporter.passed?
|
|
300
315
|
end
|
|
301
316
|
|
|
302
317
|
def self.empty_run! options # :nodoc:
|
|
@@ -408,6 +423,7 @@ module Minitest
|
|
|
408
423
|
pos = Regexp.new $1 if pos.kind_of?(String) && pos =~ %r%/(.*)/%
|
|
409
424
|
neg = Regexp.new $1 if neg.kind_of?(String) && neg =~ %r%/(.*)/%
|
|
410
425
|
|
|
426
|
+
# at most 1-2% slower than a 1-pass version, stop optimizing this
|
|
411
427
|
filtered_methods = self.runnable_methods
|
|
412
428
|
.select { |m| !pos || pos === m || pos === "#{self}##{m}" }
|
|
413
429
|
.reject { |m| neg && (neg === m || neg === "#{self}##{m}") }
|
|
@@ -571,7 +587,7 @@ module Minitest
|
|
|
571
587
|
def skipped?
|
|
572
588
|
raise NotImplementedError, "subclass responsibility"
|
|
573
589
|
end
|
|
574
|
-
end
|
|
590
|
+
end # Runnable
|
|
575
591
|
|
|
576
592
|
##
|
|
577
593
|
# Shared code for anything that can get passed to a Reporter. See
|
|
@@ -623,7 +639,7 @@ module Minitest
|
|
|
623
639
|
def error?
|
|
624
640
|
self.failures.any? UnexpectedError
|
|
625
641
|
end
|
|
626
|
-
end
|
|
642
|
+
end # Reportable
|
|
627
643
|
|
|
628
644
|
##
|
|
629
645
|
# This represents a test result in a clean way that can be
|
|
@@ -677,7 +693,7 @@ module Minitest
|
|
|
677
693
|
"#{failure.result_label}:\n#{self.location}:\n#{failure.message}\n"
|
|
678
694
|
}.join "\n"
|
|
679
695
|
end
|
|
680
|
-
end
|
|
696
|
+
end # Result
|
|
681
697
|
|
|
682
698
|
##
|
|
683
699
|
# Defines the API for Reporters. Subclass this and override whatever
|
|
@@ -727,7 +743,7 @@ module Minitest
|
|
|
727
743
|
def synchronize &block # :nodoc:
|
|
728
744
|
@mutex.synchronize(&block)
|
|
729
745
|
end
|
|
730
|
-
end
|
|
746
|
+
end # AbstractReportera
|
|
731
747
|
|
|
732
748
|
class Reporter < AbstractReporter # :nodoc:
|
|
733
749
|
##
|
|
@@ -882,7 +898,7 @@ module Minitest
|
|
|
882
898
|
self.warnings = aggregate[UnexpectedWarning].size
|
|
883
899
|
self.skips = aggregate[Skip].size
|
|
884
900
|
end
|
|
885
|
-
end
|
|
901
|
+
end # StatisticsReporter
|
|
886
902
|
|
|
887
903
|
##
|
|
888
904
|
# A reporter that prints the header, summary, and failure details at
|
|
@@ -960,7 +976,7 @@ module Minitest
|
|
|
960
976
|
"%d runs, %d assertions, %d failures, %d errors, %d skips%s" %
|
|
961
977
|
[count, assertions, failures, errors, skips, extra.join]
|
|
962
978
|
end
|
|
963
|
-
end
|
|
979
|
+
end # SummaryReporter
|
|
964
980
|
|
|
965
981
|
##
|
|
966
982
|
# Dispatch to multiple reporters as one.
|
|
@@ -1011,7 +1027,7 @@ module Minitest
|
|
|
1011
1027
|
def report # :nodoc:
|
|
1012
1028
|
self.reporters.each(&:report)
|
|
1013
1029
|
end
|
|
1014
|
-
end
|
|
1030
|
+
end # CompositeReporter
|
|
1015
1031
|
|
|
1016
1032
|
##
|
|
1017
1033
|
# Represents run failures.
|
|
@@ -1078,7 +1094,7 @@ module Minitest
|
|
|
1078
1094
|
self.error.backtrace
|
|
1079
1095
|
end
|
|
1080
1096
|
|
|
1081
|
-
BASE_RE = %r%#{Dir.pwd}/% # :nodoc:
|
|
1097
|
+
BASE_RE = %r%#{Regexp.escape Dir.pwd}/% # :nodoc:
|
|
1082
1098
|
|
|
1083
1099
|
def message # :nodoc:
|
|
1084
1100
|
bt = Minitest.filter_backtrace(self.backtrace).join("\n ")
|
|
@@ -1231,4 +1247,4 @@ module Minitest
|
|
|
1231
1247
|
# :startdoc:
|
|
1232
1248
|
end
|
|
1233
1249
|
|
|
1234
|
-
|
|
1250
|
+
require_relative "minitest/test"
|
|
@@ -142,8 +142,7 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
142
142
|
exp[1] = Object.new
|
|
143
143
|
act[1] = Object.new
|
|
144
144
|
act_obj = act[1]
|
|
145
|
-
|
|
146
|
-
act_obj.define_singleton_method(:inspect) { "#<Object:0xXXXXXX>" }
|
|
145
|
+
def act_obj.inspect = "#<Object:0xXXXXXX>"
|
|
147
146
|
msg = <<~EOM.chomp % [act]
|
|
148
147
|
No visible difference in the Hash#inspect output.
|
|
149
148
|
You should look at the implementation of #== on Hash or its members.
|
|
@@ -292,7 +291,7 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
292
291
|
@tc.assert_equal nil, nil
|
|
293
292
|
end
|
|
294
293
|
else
|
|
295
|
-
err_re =
|
|
294
|
+
err_re = /.*?test_minitest_\w+.rb:\d+: warning: DEPRECATED: Use assert_nil if expecting nil. This will fail in Minitest 6./
|
|
296
295
|
err_re = "" if $-w.nil?
|
|
297
296
|
|
|
298
297
|
assert_deprecation err_re do
|
|
@@ -318,13 +317,13 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
318
317
|
end
|
|
319
318
|
|
|
320
319
|
def test_assert_equal_string_both_escaped_unescaped_newlines
|
|
321
|
-
msg = <<~EOM
|
|
320
|
+
msg = <<~'EOM' # NOTE: single quotes on heredoc
|
|
322
321
|
--- expected
|
|
323
322
|
+++ actual
|
|
324
323
|
@@ -1,2 +1 @@
|
|
325
|
-
-"A
|
|
324
|
+
-"A\n
|
|
326
325
|
-B"
|
|
327
|
-
+"A\\
|
|
326
|
+
+"A\n\\nB"
|
|
328
327
|
EOM
|
|
329
328
|
|
|
330
329
|
assert_triggered msg do
|
|
@@ -1074,48 +1073,24 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1074
1073
|
end
|
|
1075
1074
|
|
|
1076
1075
|
def test_assert_pattern
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
"(eval):1: warning: One-line pattern matching is experimental, and the behavior may change in future versions of Ruby!\n"
|
|
1081
|
-
else
|
|
1082
|
-
""
|
|
1083
|
-
end
|
|
1084
|
-
assert_output nil, exp do
|
|
1085
|
-
eval "[1,2,3] => [Integer, Integer, Integer]" # eval to escape parser for ruby<3
|
|
1086
|
-
end
|
|
1087
|
-
end
|
|
1088
|
-
else
|
|
1089
|
-
@assertion_count = 0
|
|
1090
|
-
|
|
1091
|
-
assert_raises NotImplementedError do
|
|
1092
|
-
@tc.assert_pattern do
|
|
1093
|
-
# do nothing
|
|
1094
|
-
end
|
|
1076
|
+
@tc.assert_pattern do
|
|
1077
|
+
assert_output nil, "" do
|
|
1078
|
+
[1,2,3] => [Integer, Integer, Integer]
|
|
1095
1079
|
end
|
|
1096
1080
|
end
|
|
1097
1081
|
end
|
|
1098
1082
|
|
|
1099
1083
|
def test_assert_pattern_traps_nomatchingpatternerror
|
|
1100
|
-
|
|
1101
|
-
exp = if RUBY_VERSION.start_with? "3.0" then
|
|
1102
|
-
"[1, 2, 3]" # terrible error message!
|
|
1103
|
-
else
|
|
1104
|
-
/length mismatch/
|
|
1105
|
-
end
|
|
1084
|
+
exp = /length mismatch/
|
|
1106
1085
|
|
|
1107
1086
|
assert_triggered exp do
|
|
1108
1087
|
@tc.assert_pattern do
|
|
1109
|
-
|
|
1110
|
-
eval "[1,2,3] => [Integer, Integer]" # eval to escape parser for ruby<3
|
|
1111
|
-
end
|
|
1088
|
+
[1,2,3] => [Integer, Integer]
|
|
1112
1089
|
end
|
|
1113
1090
|
end
|
|
1114
1091
|
end
|
|
1115
1092
|
|
|
1116
1093
|
def test_assert_pattern_raises_other_exceptions
|
|
1117
|
-
skip unless RUBY_VERSION >= "3.0"
|
|
1118
|
-
|
|
1119
1094
|
@assertion_count = 0
|
|
1120
1095
|
|
|
1121
1096
|
assert_raises RuntimeError do
|
|
@@ -1126,8 +1101,6 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1126
1101
|
end
|
|
1127
1102
|
|
|
1128
1103
|
def test_assert_pattern_with_no_block
|
|
1129
|
-
skip unless RUBY_VERSION >= "3.0"
|
|
1130
|
-
|
|
1131
1104
|
assert_triggered "assert_pattern requires a block to capture errors." do
|
|
1132
1105
|
@tc.assert_pattern
|
|
1133
1106
|
end
|
|
@@ -1280,12 +1253,16 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1280
1253
|
end
|
|
1281
1254
|
|
|
1282
1255
|
def test_refute_in_epsilon_triggered
|
|
1283
|
-
assert_triggered "Expected |10000 -
|
|
1284
|
-
@tc.refute_in_epsilon 10_000,
|
|
1256
|
+
assert_triggered "Expected |10000 - 9991| (9) to not be <= 9.991." do
|
|
1257
|
+
@tc.refute_in_epsilon 10_000, 9991
|
|
1285
1258
|
flunk
|
|
1286
1259
|
end
|
|
1287
1260
|
end
|
|
1288
1261
|
|
|
1262
|
+
def test_refute_in_epsilon_minimum
|
|
1263
|
+
@tc.refute_in_epsilon 10_000, 9990
|
|
1264
|
+
end
|
|
1265
|
+
|
|
1289
1266
|
def test_refute_includes
|
|
1290
1267
|
@assertion_count = 2
|
|
1291
1268
|
|
|
@@ -1382,38 +1359,20 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1382
1359
|
end
|
|
1383
1360
|
|
|
1384
1361
|
def test_refute_pattern
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
capture_io do # 3.0 is noisy
|
|
1388
|
-
eval "[1,2,3] => [Integer, Integer, String]"
|
|
1389
|
-
end
|
|
1390
|
-
end
|
|
1391
|
-
else
|
|
1392
|
-
@assertion_count = 0
|
|
1393
|
-
|
|
1394
|
-
assert_raises NotImplementedError do
|
|
1395
|
-
@tc.refute_pattern do
|
|
1396
|
-
eval "[1,2,3] => [Integer, Integer, String]"
|
|
1397
|
-
end
|
|
1398
|
-
end
|
|
1362
|
+
@tc.refute_pattern do
|
|
1363
|
+
[1,2,3] => [Integer, Integer, String]
|
|
1399
1364
|
end
|
|
1400
1365
|
end
|
|
1401
1366
|
|
|
1402
1367
|
def test_refute_pattern_expects_nomatchingpatternerror
|
|
1403
|
-
skip unless RUBY_VERSION > "3"
|
|
1404
|
-
|
|
1405
1368
|
assert_triggered(/NoMatchingPatternError expected, but nothing was raised./) do
|
|
1406
1369
|
@tc.refute_pattern do
|
|
1407
|
-
|
|
1408
|
-
eval "[1,2,3] => [Integer, Integer, Integer]"
|
|
1409
|
-
end
|
|
1370
|
+
[1,2,3] => [Integer, Integer, Integer]
|
|
1410
1371
|
end
|
|
1411
1372
|
end
|
|
1412
1373
|
end
|
|
1413
1374
|
|
|
1414
1375
|
def test_refute_pattern_raises_other_exceptions
|
|
1415
|
-
skip unless RUBY_VERSION >= "3.0"
|
|
1416
|
-
|
|
1417
1376
|
@assertion_count = 0
|
|
1418
1377
|
|
|
1419
1378
|
assert_raises RuntimeError do
|
|
@@ -1424,8 +1383,6 @@ class TestMinitestAssertions < Minitest::Test
|
|
|
1424
1383
|
end
|
|
1425
1384
|
|
|
1426
1385
|
def test_refute_pattern_with_no_block
|
|
1427
|
-
skip unless RUBY_VERSION >= "3.0"
|
|
1428
|
-
|
|
1429
1386
|
assert_triggered "refute_pattern requires a block to capture errors." do
|
|
1430
1387
|
@tc.refute_pattern
|
|
1431
1388
|
end
|
|
@@ -26,7 +26,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
26
26
|
def test_blow_up_if_not_called
|
|
27
27
|
@mock.foo
|
|
28
28
|
|
|
29
|
-
util_verify_bad "
|
|
29
|
+
util_verify_bad "Expected meaning_of_life() => 42"
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def test_not_blow_up_if_everything_called
|
|
@@ -46,7 +46,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
46
46
|
@mock.meaning_of_life
|
|
47
47
|
@mock.expect :bar, true
|
|
48
48
|
|
|
49
|
-
util_verify_bad "
|
|
49
|
+
util_verify_bad "Expected bar() => true"
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def test_blow_up_on_wrong_number_of_arguments
|
|
@@ -184,6 +184,73 @@ class TestMinitestMock < Minitest::Test
|
|
|
184
184
|
assert @mock == 1, "didn't mock :=="
|
|
185
185
|
end
|
|
186
186
|
|
|
187
|
+
def test_assert_mock__pass
|
|
188
|
+
mock = Minitest::Mock.new
|
|
189
|
+
mock.expect :loose_expectation, true, [Integer]
|
|
190
|
+
mock.loose_expectation 1
|
|
191
|
+
|
|
192
|
+
result = assert_mock mock
|
|
193
|
+
|
|
194
|
+
assert_equal true, result
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
def assert_bad_mock klass, msg
|
|
198
|
+
mock = Minitest::Mock.new
|
|
199
|
+
mock.expect :foo, nil, [:bar]
|
|
200
|
+
mock.expect :foo, nil, [:baz]
|
|
201
|
+
|
|
202
|
+
mock.foo :bar
|
|
203
|
+
|
|
204
|
+
e = assert_raises klass do
|
|
205
|
+
yield mock
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
assert_equal msg, e.message
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def test_verify__error
|
|
212
|
+
exp = "Expected foo(:baz) => nil, got [foo(:bar) => nil]"
|
|
213
|
+
assert_bad_mock MockExpectationError, exp do |mock|
|
|
214
|
+
mock.verify
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
def test_assert_mock__fail
|
|
219
|
+
exp = "Expected foo(:baz) => nil, got [foo(:bar) => nil]."
|
|
220
|
+
assert_bad_mock Minitest::Assertion, exp do |mock|
|
|
221
|
+
assert_mock mock
|
|
222
|
+
end
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
def test_assert_mock__fail_msg
|
|
226
|
+
exp = "BLAH.\nExpected foo(:baz) => nil, got [foo(:bar) => nil]."
|
|
227
|
+
assert_bad_mock Minitest::Assertion, exp do |mock|
|
|
228
|
+
assert_mock mock, "BLAH"
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
def test_assert_mock__fail_exp
|
|
233
|
+
exp = "Expected foo(:baz) => nil, got [foo(:bar) => nil]."
|
|
234
|
+
assert_bad_mock Minitest::Assertion, exp do |mock|
|
|
235
|
+
describe "X" do
|
|
236
|
+
it "y" do
|
|
237
|
+
_(mock).must_verify
|
|
238
|
+
end
|
|
239
|
+
end.new(:blah).send(:test_0001_y)
|
|
240
|
+
end
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def test_assert_mock__fail_exp_msg
|
|
244
|
+
exp = "BLAH.\nExpected foo(:baz) => nil, got [foo(:bar) => nil]."
|
|
245
|
+
assert_bad_mock Minitest::Assertion, exp do |mock|
|
|
246
|
+
describe "X" do
|
|
247
|
+
it "y" do
|
|
248
|
+
_(mock).must_verify "BLAH"
|
|
249
|
+
end
|
|
250
|
+
end.new(:blah).send(:test_0001_y)
|
|
251
|
+
end
|
|
252
|
+
end
|
|
253
|
+
|
|
187
254
|
def test_verify_allows_called_args_to_be_loosely_specified
|
|
188
255
|
mock = Minitest::Mock.new
|
|
189
256
|
mock.expect :loose_expectation, true, [Integer]
|
|
@@ -238,7 +305,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
238
305
|
|
|
239
306
|
e = assert_raises(MockExpectationError) { mock.verify }
|
|
240
307
|
|
|
241
|
-
exp = "
|
|
308
|
+
exp = "Expected foo(:baz) => nil, got [foo(:bar) => nil]"
|
|
242
309
|
|
|
243
310
|
assert_equal exp, e.message
|
|
244
311
|
end
|
|
@@ -252,7 +319,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
252
319
|
|
|
253
320
|
e = assert_raises(MockExpectationError) { mock.verify }
|
|
254
321
|
|
|
255
|
-
exp = "
|
|
322
|
+
exp = "Expected foo(:bar) => nil, got [foo(:bar) => nil]"
|
|
256
323
|
|
|
257
324
|
assert_equal exp, e.message
|
|
258
325
|
end
|
|
@@ -276,7 +343,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
276
343
|
|
|
277
344
|
e = assert_raises(MockExpectationError) { mock.verify }
|
|
278
345
|
|
|
279
|
-
exp = "
|
|
346
|
+
exp = "Expected foo(%p) => nil, got [foo(%p) => nil]" \
|
|
280
347
|
% [{ :kw => false }, { :kw => true }]
|
|
281
348
|
|
|
282
349
|
assert_equal exp.delete("{}"), e.message
|
|
@@ -301,11 +368,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
301
368
|
end
|
|
302
369
|
|
|
303
370
|
assert_silent do
|
|
304
|
-
|
|
305
|
-
mock.foo arg1, arg2, arg3
|
|
306
|
-
else
|
|
307
|
-
mock.foo arg1, arg2, **arg3 # oddity just for ruby 2.7
|
|
308
|
-
end
|
|
371
|
+
mock.foo arg1, arg2, arg3
|
|
309
372
|
end
|
|
310
373
|
|
|
311
374
|
assert_mock mock
|
|
@@ -334,8 +397,8 @@ class TestMinitestMock < Minitest::Test
|
|
|
334
397
|
mock.foo k1: arg1, k2: arg2
|
|
335
398
|
end
|
|
336
399
|
|
|
337
|
-
# basically testing ruby
|
|
338
|
-
assert_match(/missing keyword:
|
|
400
|
+
# basically testing ruby
|
|
401
|
+
assert_match(/missing keyword: :k3/, e.message)
|
|
339
402
|
end
|
|
340
403
|
|
|
341
404
|
def test_mock_block_is_passed_keyword_args__block_bad_extra
|
|
@@ -349,8 +412,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
349
412
|
mock.foo k1: arg1, k2: arg2, k3: arg3
|
|
350
413
|
end
|
|
351
414
|
|
|
352
|
-
|
|
353
|
-
assert_match(/unknown keyword: :?k3/, e.message)
|
|
415
|
+
assert_match(/unknown keyword: :k3/, e.message)
|
|
354
416
|
end
|
|
355
417
|
|
|
356
418
|
def test_mock_block_is_passed_keyword_args__block_bad_value
|
|
@@ -589,7 +651,7 @@ class TestMinitestMock < Minitest::Test
|
|
|
589
651
|
|
|
590
652
|
end
|
|
591
653
|
|
|
592
|
-
|
|
654
|
+
require_relative "metametameta"
|
|
593
655
|
|
|
594
656
|
class TestMinitestStub < Minitest::Test
|
|
595
657
|
# Do not parallelize since we're calling stub on class methods
|