assert 2.18.4 → 2.19.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -2
- data/assert.gemspec +11 -5
- data/bin/assert +1 -0
- data/lib/assert.rb +20 -6
- data/lib/assert/actual_value.rb +26 -8
- data/lib/assert/assert_runner.rb +38 -17
- data/lib/assert/assertions.rb +145 -41
- data/lib/assert/cli.rb +19 -66
- data/lib/assert/clirb.rb +55 -0
- data/lib/assert/config.rb +22 -8
- data/lib/assert/config_helpers.rb +57 -22
- data/lib/assert/context.rb +28 -47
- data/lib/assert/context/let_dsl.rb +8 -2
- data/lib/assert/context/method_missing.rb +3 -0
- data/lib/assert/context/setup_dsl.rb +24 -16
- data/lib/assert/context/subject_dsl.rb +9 -7
- data/lib/assert/context/suite_dsl.rb +5 -1
- data/lib/assert/context/test_dsl.rb +58 -19
- data/lib/assert/context_info.rb +2 -0
- data/lib/assert/default_runner.rb +2 -0
- data/lib/assert/default_suite.rb +27 -15
- data/lib/assert/default_view.rb +49 -30
- data/lib/assert/factory.rb +2 -0
- data/lib/assert/file_line.rb +8 -6
- data/lib/assert/macro.rb +3 -1
- data/lib/assert/macros/methods.rb +73 -45
- data/lib/assert/result.rb +117 -61
- data/lib/assert/runner.rb +70 -51
- data/lib/assert/stub.rb +44 -3
- data/lib/assert/suite.rb +76 -38
- data/lib/assert/test.rb +43 -44
- data/lib/assert/utils.rb +22 -11
- data/lib/assert/version.rb +3 -1
- data/lib/assert/view.rb +46 -18
- data/lib/assert/view_helpers.rb +102 -92
- data/test/helper.rb +8 -4
- data/test/support/factory.rb +40 -21
- data/test/support/inherited_stuff.rb +2 -0
- data/test/system/stub_tests.rb +182 -144
- data/test/system/test_tests.rb +88 -60
- data/test/unit/actual_value_tests.rb +103 -46
- data/test/unit/assert_tests.rb +48 -40
- data/test/unit/assertions/assert_block_tests.rb +12 -10
- data/test/unit/assertions/assert_changes_tests.rb +103 -0
- data/test/unit/assertions/assert_empty_tests.rb +16 -12
- data/test/unit/assertions/assert_equal_tests.rb +46 -24
- data/test/unit/assertions/assert_file_exists_tests.rb +17 -13
- data/test/unit/assertions/assert_includes_tests.rb +12 -10
- data/test/unit/assertions/assert_instance_of_tests.rb +16 -14
- data/test/unit/assertions/assert_is_a_tests.rb +128 -0
- data/test/unit/assertions/assert_match_tests.rb +12 -10
- data/test/unit/assertions/assert_nil_tests.rb +18 -12
- data/test/unit/assertions/assert_raises_tests.rb +34 -23
- data/test/unit/assertions/assert_respond_to_tests.rb +12 -10
- data/test/unit/assertions/assert_same_tests.rb +26 -24
- data/test/unit/assertions/assert_true_false_tests.rb +34 -24
- data/test/unit/assertions_tests.rb +25 -17
- data/test/unit/config_helpers_tests.rb +15 -8
- data/test/unit/config_tests.rb +36 -9
- data/test/unit/context/let_dsl_tests.rb +2 -0
- data/test/unit/context/setup_dsl_tests.rb +26 -14
- data/test/unit/context/subject_dsl_tests.rb +5 -3
- data/test/unit/context/suite_dsl_tests.rb +6 -4
- data/test/unit/context/test_dsl_tests.rb +43 -19
- data/test/unit/context_info_tests.rb +6 -4
- data/test/unit/context_tests.rb +112 -54
- data/test/unit/default_runner_tests.rb +2 -0
- data/test/unit/default_suite_tests.rb +12 -6
- data/test/unit/factory_tests.rb +4 -2
- data/test/unit/file_line_tests.rb +9 -7
- data/test/unit/macro_tests.rb +13 -11
- data/test/unit/result_tests.rb +49 -41
- data/test/unit/runner_tests.rb +33 -18
- data/test/unit/suite_tests.rb +42 -24
- data/test/unit/test_tests.rb +66 -73
- data/test/unit/utils_tests.rb +52 -37
- data/test/unit/view_helpers_tests.rb +23 -14
- data/test/unit/view_tests.rb +7 -5
- metadata +40 -9
- data/test/unit/assertions/assert_kind_of_tests.rb +0 -66
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/context_info"
|
3
5
|
|
@@ -6,20 +8,20 @@ require "assert/context"
|
|
6
8
|
class Assert::ContextInfo
|
7
9
|
class UnitTests < Assert::Context
|
8
10
|
desc "Assert::ContextInfo"
|
9
|
-
subject
|
11
|
+
subject{ unit_class }
|
10
12
|
|
11
|
-
let(:unit_class)
|
13
|
+
let(:unit_class){ Assert::ContextInfo }
|
12
14
|
end
|
13
15
|
|
14
16
|
class InitTests < UnitTests
|
15
17
|
desc "when init"
|
16
|
-
subject
|
18
|
+
subject{ unit_class.new(context1, nil, @caller.first) }
|
17
19
|
|
18
20
|
setup do
|
19
21
|
@caller = caller
|
20
22
|
end
|
21
23
|
|
22
|
-
let(:context1)
|
24
|
+
let(:context1){ Assert::Context }
|
23
25
|
|
24
26
|
should have_readers :called_from, :klass, :file
|
25
27
|
should have_imeths :test_name
|
data/test/unit/context_tests.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/context"
|
3
5
|
|
@@ -8,9 +10,9 @@ require "assert/utils"
|
|
8
10
|
class Assert::Context
|
9
11
|
class UnitTests < Assert::Context
|
10
12
|
desc "Assert::Context"
|
11
|
-
subject
|
13
|
+
subject{ unit_class }
|
12
14
|
|
13
|
-
let(:unit_class)
|
15
|
+
let(:unit_class){ Assert::Context }
|
14
16
|
|
15
17
|
# DSL methods
|
16
18
|
should have_imeths :description, :desc, :describe, :subject, :suite, :let
|
@@ -25,20 +27,23 @@ class Assert::Context
|
|
25
27
|
|
26
28
|
class InitTests < UnitTests
|
27
29
|
desc "when init"
|
28
|
-
subject
|
30
|
+
subject{ context_class1.new(test1, test1.config, result_callback1) }
|
29
31
|
|
30
32
|
setup do
|
31
33
|
@callback_result = nil
|
32
34
|
end
|
33
35
|
|
34
|
-
let(:test1)
|
35
|
-
let(:context_class1)
|
36
|
-
let(:test_results1)
|
37
|
-
let(:result_callback1)
|
38
|
-
proc
|
39
|
-
|
40
|
-
|
41
|
-
|
36
|
+
let(:test1){ Factory.test }
|
37
|
+
let(:context_class1){ test1.context_class }
|
38
|
+
let(:test_results1){ [] }
|
39
|
+
let(:result_callback1) do
|
40
|
+
proc do |result|
|
41
|
+
@callback_result = result
|
42
|
+
test_results1 << result
|
43
|
+
end
|
44
|
+
end
|
45
|
+
let(:halt_config1){ Assert::Config.new(halt_on_fail: true) }
|
46
|
+
let(:msg1){ Factory.string }
|
42
47
|
|
43
48
|
should have_imeths :assert, :assert_not, :refute, :assert_that
|
44
49
|
should have_imeths :pass, :ignore, :fail, :flunk, :skip
|
@@ -46,7 +51,8 @@ class Assert::Context
|
|
46
51
|
|
47
52
|
should "collect context info" do
|
48
53
|
test = @__assert_running_test__
|
49
|
-
assert_that(test.context_info.file)
|
54
|
+
assert_that(test.context_info.file)
|
55
|
+
.matches(%r{test/unit/context_tests.rb$})
|
50
56
|
assert_that(test.context_info.klass).equals(self.class)
|
51
57
|
end
|
52
58
|
|
@@ -58,7 +64,9 @@ class Assert::Context
|
|
58
64
|
with_backtrace(caller) do
|
59
65
|
assert_that(result.with_bt_set?).is_true
|
60
66
|
|
61
|
-
exp =
|
67
|
+
exp =
|
68
|
+
Assert::Result::Backtrace.to_s(exp_with_bt +
|
69
|
+
[(result.backtrace.filtered.first)])
|
62
70
|
assert_that(result.trace).equals(exp)
|
63
71
|
assert_that(result.src_line).equals(exp_with_bt.first)
|
64
72
|
end
|
@@ -69,7 +77,8 @@ class Assert::Context
|
|
69
77
|
assert_that(result.with_bt_set?).is_false
|
70
78
|
|
71
79
|
assert_that(result.trace).equals(result.src_line)
|
72
|
-
assert_that(result.src_line)
|
80
|
+
assert_that(result.src_line)
|
81
|
+
.equals(result.backtrace.filtered.first.to_s)
|
73
82
|
end
|
74
83
|
end
|
75
84
|
end
|
@@ -78,7 +87,12 @@ class Assert::Context
|
|
78
87
|
desc "skip method"
|
79
88
|
|
80
89
|
setup do
|
81
|
-
|
90
|
+
@exception =
|
91
|
+
begin
|
92
|
+
subject.skip(msg1)
|
93
|
+
rescue => ex
|
94
|
+
ex
|
95
|
+
end
|
82
96
|
@result = Factory.skip_result(@exception)
|
83
97
|
end
|
84
98
|
|
@@ -96,7 +110,12 @@ class Assert::Context
|
|
96
110
|
assert_that(@exception.backtrace.size).does_not_equal(1)
|
97
111
|
|
98
112
|
called_from = Factory.string
|
99
|
-
|
113
|
+
exception =
|
114
|
+
begin
|
115
|
+
subject.skip(msg1, called_from)
|
116
|
+
rescue => ex
|
117
|
+
ex
|
118
|
+
end
|
100
119
|
assert_that(exception.backtrace.size).equals(1)
|
101
120
|
assert_that(exception.backtrace.first).equals(called_from)
|
102
121
|
end
|
@@ -178,14 +197,20 @@ class Assert::Context
|
|
178
197
|
|
179
198
|
class HaltOnFailTests < InitTests
|
180
199
|
desc "failing when halting on fails"
|
181
|
-
subject
|
200
|
+
subject{ context_class1.new(test1, halt_config1, result_callback1) }
|
182
201
|
|
183
202
|
should "raise an exception with the failure's message" do
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
203
|
+
exception =
|
204
|
+
begin
|
205
|
+
subject.fail(msg1)
|
206
|
+
rescue => ex
|
207
|
+
ex
|
208
|
+
end
|
209
|
+
assert_that(exception).is_kind_of(Assert::Result::TestFailure)
|
210
|
+
assert_that(exception.message).equals(msg1)
|
211
|
+
|
212
|
+
result =
|
213
|
+
Assert::Result::Fail.for_test(Factory.test("something"), exception)
|
189
214
|
assert_that(result.message).equals(msg1)
|
190
215
|
end
|
191
216
|
|
@@ -197,7 +222,7 @@ class Assert::Context
|
|
197
222
|
class AssertTests < InitTests
|
198
223
|
desc "assert method"
|
199
224
|
|
200
|
-
let(:what_failed)
|
225
|
+
let(:what_failed){ Factory.string }
|
201
226
|
|
202
227
|
should "return a pass result given a `true` assertion" do
|
203
228
|
result = subject.assert(true, msg1){ what_failed }
|
@@ -211,7 +236,8 @@ class Assert::Context
|
|
211
236
|
end
|
212
237
|
|
213
238
|
should "pp the assertion value in the fail message by default" do
|
214
|
-
exp_def_what =
|
239
|
+
exp_def_what =
|
240
|
+
"Failed assert: assertion was `#{Assert::U.show(false, test1.config)}`."
|
215
241
|
result = subject.assert(false, msg1)
|
216
242
|
|
217
243
|
assert_that(result.message).equals([msg1, exp_def_what].join("\n"))
|
@@ -246,7 +272,9 @@ class Assert::Context
|
|
246
272
|
end
|
247
273
|
|
248
274
|
should "pp the assertion value in the fail message by default" do
|
249
|
-
exp_def_what =
|
275
|
+
exp_def_what =
|
276
|
+
"Failed assert_not: "\
|
277
|
+
"assertion was `#{Assert::U.show(true, test1.config)}`."
|
250
278
|
result = subject.assert_not(true, msg1)
|
251
279
|
|
252
280
|
assert_that(result.message).equals([msg1, exp_def_what].join("\n"))
|
@@ -265,32 +293,32 @@ class Assert::Context
|
|
265
293
|
desc "`assert_that` method"
|
266
294
|
|
267
295
|
setup do
|
268
|
-
Assert.stub_tap_on_call(Assert::ActualValue, :new)
|
296
|
+
Assert.stub_tap_on_call(Assert::ActualValue, :new) do |_, call|
|
269
297
|
@actual_value_new_call = call
|
270
|
-
|
298
|
+
end
|
271
299
|
end
|
272
300
|
|
273
|
-
let(:actual_value)
|
301
|
+
let(:actual_value){ Factory.string }
|
274
302
|
|
275
303
|
should "build an Assert::ActualValue" do
|
276
304
|
assert_instance_of Assert::ActualValue, subject.assert_that(actual_value)
|
277
305
|
assert_equal [actual_value], @actual_value_new_call.pargs
|
278
|
-
assert_equal({ context: subject },
|
306
|
+
assert_equal({ context: subject }, @actual_value_new_call.kargs)
|
279
307
|
end
|
280
308
|
end
|
281
309
|
|
282
310
|
class SubjectTests < InitTests
|
283
311
|
desc "subject method"
|
284
|
-
subject
|
312
|
+
subject{ context_class1.new(test1, test1.config, proc{ |result| }) }
|
285
313
|
|
286
314
|
setup do
|
287
315
|
expected = expected1
|
288
|
-
context_class1.subject
|
316
|
+
context_class1.subject{ @something = expected }
|
289
317
|
@subject = subject.subject
|
290
318
|
end
|
291
319
|
|
292
|
-
let(:context_class1)
|
293
|
-
let(:expected1)
|
320
|
+
let(:context_class1){ Factory.modes_off_context_class }
|
321
|
+
let(:expected1){ Factory.string }
|
294
322
|
|
295
323
|
should "instance evaluate the block set with the class setup method" do
|
296
324
|
assert_that(@subject).equals(expected1)
|
@@ -300,8 +328,17 @@ class Assert::Context
|
|
300
328
|
class PendingTests < InitTests
|
301
329
|
desc "`pending` method"
|
302
330
|
|
303
|
-
let(:block2)
|
304
|
-
|
331
|
+
let(:block2) do
|
332
|
+
proc do
|
333
|
+
fail # rubocop:disable Style/SignalException
|
334
|
+
pass # rubocop:disable Lint/UnreachableCode
|
335
|
+
end
|
336
|
+
end
|
337
|
+
# test nesting
|
338
|
+
let(:block1) do
|
339
|
+
block = block2
|
340
|
+
proc{ pending(&block) }
|
341
|
+
end
|
305
342
|
|
306
343
|
should "make fails skips and make passes fails" do
|
307
344
|
subject.fail "not affected"
|
@@ -324,29 +361,42 @@ class Assert::Context
|
|
324
361
|
|
325
362
|
class PendingWithHaltOnFailTests < PendingTests
|
326
363
|
desc "when halting on fails"
|
327
|
-
subject
|
364
|
+
subject{ context_class1.new(test1, halt_config1, result_callback1) }
|
328
365
|
|
329
366
|
should "make fails skips and stop the test" do
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
367
|
+
exception =
|
368
|
+
begin
|
369
|
+
subject.pending(&block1)
|
370
|
+
rescue => ex
|
371
|
+
ex
|
372
|
+
end
|
373
|
+
assert_that(exception).is_kind_of(Assert::Result::TestSkipped)
|
374
|
+
assert_that(exception.message).includes("Pending fail")
|
375
|
+
|
376
|
+
# it halted before the pending pass
|
377
|
+
assert_that(test_results1.size).equals(0)
|
335
378
|
end
|
336
379
|
end
|
337
380
|
|
338
381
|
class WithBacktraceTests < InitTests
|
339
382
|
desc "`with_backtrace` method"
|
340
383
|
|
341
|
-
let(:from_bt1)
|
342
|
-
let(:from_block1)
|
384
|
+
let(:from_bt1){ ["called_from_here", Factory.string] }
|
385
|
+
let(:from_block1) do
|
386
|
+
proc do
|
387
|
+
ignore
|
388
|
+
fail # rubocop:disable Style/SignalException
|
389
|
+
pass # rubocop:disable Lint/UnreachableCode
|
390
|
+
skip "todo"
|
391
|
+
end
|
392
|
+
end
|
343
393
|
|
344
394
|
should "alter non-error block results' bt with given bt's first line" do
|
345
395
|
subject.fail "not affected"
|
346
396
|
begin
|
347
397
|
subject.with_backtrace(from_bt1, &from_block1)
|
348
|
-
rescue Assert::Result::TestSkipped =>
|
349
|
-
test_results1 << Assert::Result::Skip.for_test(test1,
|
398
|
+
rescue Assert::Result::TestSkipped => ex
|
399
|
+
test_results1 << Assert::Result::Skip.for_test(test1, ex)
|
350
400
|
end
|
351
401
|
|
352
402
|
assert_that(test_results1.size).equals(5)
|
@@ -365,21 +415,29 @@ class Assert::Context
|
|
365
415
|
class WithNestedBacktraceTests < InitTests
|
366
416
|
desc "`with_backtrace` method nested"
|
367
417
|
|
368
|
-
let(:from_bt1)
|
369
|
-
let(:from_bt2)
|
370
|
-
let(:from_block2)
|
371
|
-
|
418
|
+
let(:from_bt1){ ["called_from_here 1", Factory.string] }
|
419
|
+
let(:from_bt2){ ["called_from_here 2", Factory.string] }
|
420
|
+
let(:from_block2) do
|
421
|
+
proc do
|
422
|
+
ignore
|
423
|
+
fail # rubocop:disable Style/SignalException
|
424
|
+
pass # rubocop:disable Lint/UnreachableCode
|
425
|
+
skip "todo"
|
426
|
+
end
|
427
|
+
end
|
428
|
+
let(:from_block1) do
|
372
429
|
from_bt = from_bt2
|
373
430
|
from_block = from_block2
|
374
|
-
proc
|
375
|
-
|
431
|
+
proc{ with_backtrace(from_bt, &from_block) }
|
432
|
+
end
|
376
433
|
|
377
|
-
should "alter non-error block results' bt with nested wbt accrued
|
434
|
+
should "alter non-error block results' bt with nested wbt accrued "\
|
435
|
+
"first lines" do
|
378
436
|
subject.fail "not affected"
|
379
437
|
begin
|
380
438
|
subject.with_backtrace(from_bt1, &from_block1)
|
381
|
-
rescue Assert::Result::TestSkipped =>
|
382
|
-
test_results1 << Assert::Result::Skip.for_test(test1,
|
439
|
+
rescue Assert::Result::TestSkipped => ex
|
440
|
+
test_results1 << Assert::Result::Skip.for_test(test1, ex)
|
383
441
|
end
|
384
442
|
|
385
443
|
assert_that(test_results1.size).equals(5)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/default_suite"
|
3
5
|
|
@@ -6,18 +8,22 @@ require "assert/suite"
|
|
6
8
|
class Assert::DefaultSuite
|
7
9
|
class UnitTests < Assert::Context
|
8
10
|
desc "Assert::DefaultSuite"
|
9
|
-
subject
|
11
|
+
subject{ unit_class }
|
10
12
|
|
11
|
-
let(:unit_class)
|
13
|
+
let(:unit_class){ Assert::DefaultSuite }
|
12
14
|
end
|
13
15
|
|
14
16
|
class InitTests < UnitTests
|
15
17
|
desc "when init"
|
16
|
-
subject
|
18
|
+
subject{ unit_class.new(config1) }
|
19
|
+
|
20
|
+
let(:ci1){ Factory.context_info(Factory.modes_off_context_class) }
|
21
|
+
let(:test1){ Factory.test(Factory.string, ci1){} }
|
22
|
+
let(:config1){ Factory.modes_off_config }
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
should have_readers :test_count, :result_count, :pass_result_count
|
25
|
+
should have_readers :fail_result_count, :error_result_count
|
26
|
+
should have_readers :skip_result_count, :ignore_result_count
|
21
27
|
|
22
28
|
should "be a Suite" do
|
23
29
|
assert_that(subject).is_kind_of(Assert::Suite)
|
data/test/unit/factory_tests.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/factory"
|
3
5
|
|
@@ -6,9 +8,9 @@ require "much-factory"
|
|
6
8
|
module Assert::Factory
|
7
9
|
class UnitTests < Assert::Context
|
8
10
|
desc "Assert::Factory"
|
9
|
-
subject
|
11
|
+
subject{ unit_class }
|
10
12
|
|
11
|
-
let(:unit_class)
|
13
|
+
let(:unit_class){ Assert::Factory }
|
12
14
|
|
13
15
|
should "include and extend MuchFactory" do
|
14
16
|
assert_that(subject).includes(MuchFactory)
|
@@ -1,22 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "assert"
|
2
4
|
require "assert/file_line"
|
3
5
|
|
4
6
|
class Assert::FileLine
|
5
7
|
class UnitTests < Assert::Context
|
6
8
|
desc "Assert::FileLine"
|
7
|
-
subject
|
9
|
+
subject{ unit_class }
|
8
10
|
|
9
|
-
let(:unit_class)
|
11
|
+
let(:unit_class){ Assert::FileLine }
|
10
12
|
|
11
|
-
let(:file1)
|
12
|
-
let(:line1)
|
13
|
+
let(:file1){ "#{Factory.path}_tests.rb" }
|
14
|
+
let(:line1){ Factory.integer.to_s }
|
13
15
|
|
14
16
|
should have_imeths :parse
|
15
17
|
|
16
18
|
should "know how to parse and init from a file line path string" do
|
17
19
|
file_line_path = [
|
18
20
|
"#{file1}:#{line1}",
|
19
|
-
"#{file1}:#{line1} #{Factory.string}"
|
21
|
+
"#{file1}:#{line1} #{Factory.string}",
|
20
22
|
].sample
|
21
23
|
file_line = subject.parse(file_line_path)
|
22
24
|
|
@@ -45,7 +47,7 @@ class Assert::FileLine
|
|
45
47
|
|
46
48
|
class InitTests < UnitTests
|
47
49
|
desc "when init"
|
48
|
-
subject
|
50
|
+
subject{ unit_class.new(file1, line1) }
|
49
51
|
|
50
52
|
should have_readers :file, :line
|
51
53
|
|
@@ -71,7 +73,7 @@ class Assert::FileLine
|
|
71
73
|
no = unit_class.new("#{Factory.path}_tests.rb", Factory.integer.to_s)
|
72
74
|
|
73
75
|
assert_that(subject).equals(yes)
|
74
|
-
assert_not_equal no,
|
76
|
+
assert_not_equal no, subject
|
75
77
|
end
|
76
78
|
end
|
77
79
|
end
|