test-unit 3.3.0 → 3.3.1
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
- data/doc/text/news.md +13 -0
- data/lib/test/unit/assertions.rb +48 -41
- data/lib/test/unit/version.rb +1 -1
- data/test/test-assertions.rb +3 -1
- metadata +36 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93aaef767a30d0882b6048299d858f799ea416bfdccc9daef7d2686b5a913f98
|
4
|
+
data.tar.gz: 00a5b7f5ccfe50603d4d1b926424b3d8336c21b3126e0dc324b17f156a48ef6a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a8edd6f065bf74bd4ead4dc49c6a96a635c92cfec4f7089202e658361a715d003b2c0422b58f8e97a84f7fa4ec90b137343e4737ef81741c32cb53c1191c182b
|
7
|
+
data.tar.gz: be3541d1116d75979c82060d17278e40397adc8df4dea96b982fc5b61583749b975d1cdfcfbc634dc1f4045c8d7994575897e38ccc78c785049ea6673d973f67
|
data/doc/text/news.md
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
# News
|
2
2
|
|
3
|
+
## 3.3.1 - 2019-03-27 {#version-3-3-1}
|
4
|
+
|
5
|
+
### Improvements
|
6
|
+
|
7
|
+
* Added support for `Test::Unit::AssertionFailedError#user_message`
|
8
|
+
for not only `assert_equal` and `assert_raise` but also all
|
9
|
+
assertions.
|
10
|
+
[GitHub#162][Reported by xgraffm]
|
11
|
+
|
12
|
+
### Thanks
|
13
|
+
|
14
|
+
* xgraffm
|
15
|
+
|
3
16
|
## 3.3.0 - 2019-01-23 {#version-3-3-0}
|
4
17
|
|
5
18
|
### Improvements
|
data/lib/test/unit/assertions.rb
CHANGED
@@ -32,9 +32,9 @@ module Test
|
|
32
32
|
#
|
33
33
|
# @example Example Custom Assertion
|
34
34
|
#
|
35
|
-
# def deny(boolean, message
|
36
|
-
# message = build_message
|
37
|
-
# assert_block
|
35
|
+
# def deny(boolean, message=nil)
|
36
|
+
# message = build_message(message, '<?> is not false or nil.', boolean)
|
37
|
+
# assert_block(message) do
|
38
38
|
# not boolean
|
39
39
|
# end
|
40
40
|
# end
|
@@ -52,7 +52,11 @@ module Test
|
|
52
52
|
def assert_block(message="assert_block failed.")
|
53
53
|
_wrap_assertion do
|
54
54
|
if (! yield)
|
55
|
-
|
55
|
+
options = {}
|
56
|
+
if message.respond_to?(:user_message)
|
57
|
+
options[:user_message] = message.user_message
|
58
|
+
end
|
59
|
+
raise AssertionFailedError.new(message.to_s, options)
|
56
60
|
end
|
57
61
|
end
|
58
62
|
end
|
@@ -239,7 +243,7 @@ EOT
|
|
239
243
|
begin
|
240
244
|
assert_block(full_message) { expected == actual }
|
241
245
|
rescue AssertionFailedError => failure
|
242
|
-
_set_failed_information(failure, expected, actual
|
246
|
+
_set_failed_information(failure, expected, actual)
|
243
247
|
raise failure # For JRuby. :<
|
244
248
|
end
|
245
249
|
end
|
@@ -275,8 +279,7 @@ EOT
|
|
275
279
|
assert_exception_helper.expected?(actual_exception)
|
276
280
|
end
|
277
281
|
rescue AssertionFailedError => failure
|
278
|
-
_set_failed_information(failure, expected, actual_exception
|
279
|
-
message)
|
282
|
+
_set_failed_information(failure, expected, actual_exception)
|
280
283
|
raise failure # For JRuby. :<
|
281
284
|
end
|
282
285
|
end
|
@@ -319,7 +322,7 @@ EOT
|
|
319
322
|
# assert_instance_of(String, 'foo') # -> pass
|
320
323
|
# assert_instance_of([Fixnum, NilClass], 100) # -> pass
|
321
324
|
# assert_instance_of([Numeric, NilClass], 100) # -> fail
|
322
|
-
def assert_instance_of(klass, object, message=
|
325
|
+
def assert_instance_of(klass, object, message=nil)
|
323
326
|
_wrap_assertion do
|
324
327
|
if klass.is_a?(Array)
|
325
328
|
klasses = klass
|
@@ -355,7 +358,7 @@ EOT
|
|
355
358
|
# assert_not_instance_of([Numeric, NilClass], 100) # -> fail
|
356
359
|
#
|
357
360
|
# @since 3.0.0
|
358
|
-
def assert_not_instance_of(klass, object, message=
|
361
|
+
def assert_not_instance_of(klass, object, message=nil)
|
359
362
|
_wrap_assertion do
|
360
363
|
if klass.is_a?(Array)
|
361
364
|
klasses = klass
|
@@ -390,7 +393,7 @@ EOT
|
|
390
393
|
#
|
391
394
|
# @example
|
392
395
|
# assert_nil [1, 2].uniq!
|
393
|
-
def assert_nil(object, message=
|
396
|
+
def assert_nil(object, message=nil)
|
394
397
|
full_message = build_message(message, <<EOT, object)
|
395
398
|
<?> was expected to be nil.
|
396
399
|
EOT
|
@@ -406,7 +409,7 @@ EOT
|
|
406
409
|
# assert_kind_of(Object, 'foo') # -> pass
|
407
410
|
# assert_kind_of([Fixnum, NilClass], 100) # -> pass
|
408
411
|
# assert_kind_of([Fixnum, NilClass], "string") # -> fail
|
409
|
-
def assert_kind_of(klass, object, message=
|
412
|
+
def assert_kind_of(klass, object, message=nil)
|
410
413
|
_wrap_assertion do
|
411
414
|
if klass.is_a?(Array)
|
412
415
|
klasses = klass
|
@@ -444,7 +447,7 @@ EOT
|
|
444
447
|
# assert_not_kind_of([Fixnum, NilClass], 100) # -> fail
|
445
448
|
#
|
446
449
|
# @since 3.0.0
|
447
|
-
def assert_not_kind_of(klass, object, message=
|
450
|
+
def assert_not_kind_of(klass, object, message=nil)
|
448
451
|
_wrap_assertion do
|
449
452
|
if klass.is_a?(Array)
|
450
453
|
klasses = klass
|
@@ -479,7 +482,7 @@ EOT
|
|
479
482
|
#
|
480
483
|
# @example
|
481
484
|
# assert_respond_to 'bugbear', :slice
|
482
|
-
def assert_respond_to(object, method, message=
|
485
|
+
def assert_respond_to(object, method, message=nil)
|
483
486
|
_wrap_assertion do
|
484
487
|
full_message = build_message(message,
|
485
488
|
"<?>.kind_of\\?(Symbol) or\n" +
|
@@ -502,7 +505,7 @@ EOT
|
|
502
505
|
# @example
|
503
506
|
# assert_not_respond_to('bugbear', :nonexistence) # -> pass
|
504
507
|
# assert_not_respond_to('bugbear', :size) # -> fail
|
505
|
-
def assert_not_respond_to(object, method, message=
|
508
|
+
def assert_not_respond_to(object, method, message=nil)
|
506
509
|
_wrap_assertion do
|
507
510
|
full_message = build_message(message,
|
508
511
|
"<?>.kind_of\\?(Symbol) or\n" +
|
@@ -529,7 +532,7 @@ EOT
|
|
529
532
|
#
|
530
533
|
# @example
|
531
534
|
# assert_match(/\d+/, 'five, 6, seven')
|
532
|
-
def assert_match(pattern, string, message=
|
535
|
+
def assert_match(pattern, string, message=nil)
|
533
536
|
_wrap_assertion do
|
534
537
|
pattern = case(pattern)
|
535
538
|
when String
|
@@ -551,7 +554,7 @@ EOT
|
|
551
554
|
# @example
|
552
555
|
# o = Object.new
|
553
556
|
# assert_same o, o
|
554
|
-
def assert_same(expected, actual, message=
|
557
|
+
def assert_same(expected, actual, message=nil)
|
555
558
|
full_message = build_message(message, <<EOT, expected, expected.__id__, actual, actual.__id__)
|
556
559
|
<?>
|
557
560
|
with id <?> was expected to be equal\\? to
|
@@ -568,7 +571,7 @@ EOT
|
|
568
571
|
#
|
569
572
|
# @example
|
570
573
|
# assert_operator 5, :>=, 4
|
571
|
-
def assert_operator(object1, operator, object2, message=
|
574
|
+
def assert_operator(object1, operator, object2, message=nil)
|
572
575
|
_wrap_assertion do
|
573
576
|
full_message = build_message(nil, "<?>\ngiven as the operator for #assert_operator must be a Symbol or #respond_to\\?(:to_str).", operator)
|
574
577
|
assert_block(full_message){operator.kind_of?(Symbol) || operator.respond_to?(:to_str)}
|
@@ -591,7 +594,7 @@ EOT
|
|
591
594
|
# assert_not_operator(5, :>, 4) # => fail
|
592
595
|
#
|
593
596
|
# @since 3.0.0
|
594
|
-
def assert_not_operator(object1, operator, object2, message=
|
597
|
+
def assert_not_operator(object1, operator, object2, message=nil)
|
595
598
|
_wrap_assertion do
|
596
599
|
full_message = build_message(nil, "<?>\ngiven as the operator for #assert_not_operator must be a Symbol or #respond_to\\?(:to_str).", operator)
|
597
600
|
assert_block(full_message){operator.kind_of?(Symbol) || operator.respond_to?(:to_str)}
|
@@ -653,7 +656,7 @@ EOT
|
|
653
656
|
#
|
654
657
|
# @example
|
655
658
|
# assert_not_same Object.new, Object.new
|
656
|
-
def assert_not_same(expected, actual, message=
|
659
|
+
def assert_not_same(expected, actual, message=nil)
|
657
660
|
full_message = build_message(message, <<EOT, expected, expected.__id__, actual, actual.__id__)
|
658
661
|
<?>
|
659
662
|
with id <?> was expected to not be equal\\? to
|
@@ -673,7 +676,7 @@ EOT
|
|
673
676
|
#
|
674
677
|
# @example
|
675
678
|
# assert_not_equal 'some string', 5
|
676
|
-
def assert_not_equal(expected, actual, message=
|
679
|
+
def assert_not_equal(expected, actual, message=nil)
|
677
680
|
full_message = build_message(message,
|
678
681
|
"<?> was expected to be != to\n<?>.",
|
679
682
|
expected, actual)
|
@@ -690,7 +693,7 @@ EOT
|
|
690
693
|
#
|
691
694
|
# @example
|
692
695
|
# assert_not_nil '1 two 3'.sub!(/two/, '2')
|
693
|
-
def assert_not_nil(object, message=
|
696
|
+
def assert_not_nil(object, message=nil)
|
694
697
|
full_message = build_message(message,
|
695
698
|
"<?> was expected to not be nil.",
|
696
699
|
object)
|
@@ -708,7 +711,7 @@ EOT
|
|
708
711
|
# @example
|
709
712
|
# assert_not_match(/two/, 'one 2 three') # -> pass
|
710
713
|
# assert_not_match(/three/, 'one 2 three') # -> fail
|
711
|
-
def assert_not_match(regexp, string, message=
|
714
|
+
def assert_not_match(regexp, string, message=nil)
|
712
715
|
_wrap_assertion do
|
713
716
|
assert_instance_of(Regexp, regexp,
|
714
717
|
"<REGEXP> in assert_not_match(<REGEXP>, ...) " +
|
@@ -792,7 +795,7 @@ EOT
|
|
792
795
|
# assert_throw(:done) do
|
793
796
|
# throw(:done)
|
794
797
|
# end
|
795
|
-
def assert_throw(expected_object, message=
|
798
|
+
def assert_throw(expected_object, message=nil, &proc)
|
796
799
|
_wrap_assertion do
|
797
800
|
begin
|
798
801
|
catch([]) {}
|
@@ -838,7 +841,7 @@ EOT
|
|
838
841
|
# assert_nothing_thrown do
|
839
842
|
# [1, 2].uniq
|
840
843
|
# end
|
841
|
-
def assert_nothing_thrown(message=
|
844
|
+
def assert_nothing_thrown(message=nil, &proc)
|
842
845
|
_wrap_assertion do
|
843
846
|
assert(block_given?, "Should have passed a block to assert_nothing_thrown")
|
844
847
|
begin
|
@@ -1617,11 +1620,12 @@ EOT
|
|
1617
1620
|
alias_method :refute_empty, :assert_not_empty
|
1618
1621
|
|
1619
1622
|
##
|
1620
|
-
# Builds a failure message. +
|
1621
|
-
# +arguments+ replaces the '?'s positionally in
|
1622
|
-
|
1623
|
+
# Builds a failure message. +user_message+ is added before the
|
1624
|
+
# +template+ and +arguments+ replaces the '?'s positionally in
|
1625
|
+
# the template.
|
1626
|
+
def build_message(user_message, template=nil, *arguments)
|
1623
1627
|
template &&= template.chomp
|
1624
|
-
return AssertionMessage.new(
|
1628
|
+
return AssertionMessage.new(user_message, template, arguments)
|
1625
1629
|
end
|
1626
1630
|
|
1627
1631
|
private
|
@@ -1688,12 +1692,11 @@ EOT
|
|
1688
1692
|
end
|
1689
1693
|
end
|
1690
1694
|
|
1691
|
-
def _set_failed_information(failure, expected, actual
|
1695
|
+
def _set_failed_information(failure, expected, actual)
|
1692
1696
|
failure.expected = expected
|
1693
1697
|
failure.actual = actual
|
1694
1698
|
failure.inspected_expected = AssertionMessage.convert(expected)
|
1695
1699
|
failure.inspected_actual = AssertionMessage.convert(actual)
|
1696
|
-
failure.user_message = user_message
|
1697
1700
|
end
|
1698
1701
|
|
1699
1702
|
class AssertionMessage
|
@@ -2071,8 +2074,8 @@ EOT
|
|
2071
2074
|
|
2072
2075
|
include Util::BacktraceFilter
|
2073
2076
|
|
2074
|
-
def initialize(
|
2075
|
-
@
|
2077
|
+
def initialize(user_message, template_string, parameters)
|
2078
|
+
@user_message = user_message
|
2076
2079
|
@template_string = template_string
|
2077
2080
|
@parameters = parameters
|
2078
2081
|
end
|
@@ -2085,24 +2088,28 @@ EOT
|
|
2085
2088
|
@template ||= Template.create(@template_string)
|
2086
2089
|
end
|
2087
2090
|
|
2088
|
-
def
|
2089
|
-
|
2091
|
+
def user_message
|
2092
|
+
return nil unless @user_message
|
2093
|
+
message = @user_message
|
2094
|
+
message = message.call if message.respond_to?(:call)
|
2095
|
+
message.to_s
|
2090
2096
|
end
|
2091
2097
|
|
2092
2098
|
def to_s
|
2093
2099
|
message_parts = []
|
2094
|
-
|
2095
|
-
|
2096
|
-
|
2097
|
-
head = head.to_s
|
2098
|
-
unless(head.empty?)
|
2099
|
-
message_parts << add_period(head)
|
2100
|
-
end
|
2100
|
+
head = user_message
|
2101
|
+
if head and not head.empty?
|
2102
|
+
message_parts << add_period(head)
|
2101
2103
|
end
|
2102
2104
|
tail = template.result(@parameters.collect{|e| convert(e)})
|
2103
2105
|
message_parts << tail unless(tail.empty?)
|
2104
2106
|
message_parts.join("\n")
|
2105
2107
|
end
|
2108
|
+
|
2109
|
+
private
|
2110
|
+
def add_period(string)
|
2111
|
+
(string =~ /\.\Z/ ? string : string + '.')
|
2112
|
+
end
|
2106
2113
|
end
|
2107
2114
|
|
2108
2115
|
class AssertExceptionHelper
|
data/lib/test/unit/version.rb
CHANGED
data/test/test-assertions.rb
CHANGED
@@ -32,6 +32,7 @@ module Test
|
|
32
32
|
return_value = yield
|
33
33
|
failed = false
|
34
34
|
rescue AssertionFailedError => error
|
35
|
+
return_value = error
|
35
36
|
actual_message = error.message
|
36
37
|
end
|
37
38
|
@catch_assertions = false
|
@@ -1168,9 +1169,10 @@ EOM
|
|
1168
1169
|
assert_true(1)
|
1169
1170
|
end
|
1170
1171
|
|
1171
|
-
check_fail("message.\n<true> expected but was\n<nil>") do
|
1172
|
+
exception = check_fail("message.\n<true> expected but was\n<nil>") do
|
1172
1173
|
assert_true(nil, "message")
|
1173
1174
|
end
|
1175
|
+
assert_equal("message", exception.user_message)
|
1174
1176
|
end
|
1175
1177
|
|
1176
1178
|
def test_assert_false
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: test-unit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.3.
|
4
|
+
version: 3.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kouhei Sutou
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2019-
|
12
|
+
date: 2019-03-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: power_assert
|
@@ -231,48 +231,49 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
231
231
|
- !ruby/object:Gem::Version
|
232
232
|
version: '0'
|
233
233
|
requirements: []
|
234
|
-
|
234
|
+
rubyforge_project:
|
235
|
+
rubygems_version: 2.7.6
|
235
236
|
signing_key:
|
236
237
|
specification_version: 4
|
237
238
|
summary: An xUnit family unit testing framework for Ruby.
|
238
239
|
test_files:
|
239
|
-
- test/
|
240
|
-
- test/testunit-test-util.rb
|
241
|
-
- test/test-priority.rb
|
242
|
-
- test/test-test-suite.rb
|
243
|
-
- test/test-error.rb
|
244
|
-
- test/test-notification.rb
|
240
|
+
- test/test-code-snippet.rb
|
245
241
|
- test/test-fault-location-detector.rb
|
246
|
-
- test/test-
|
247
|
-
- test/test-
|
248
|
-
- test/
|
249
|
-
- test/util/test_backtracefilter.rb
|
250
|
-
- test/util/test_procwrapper.rb
|
251
|
-
- test/util/test_observable.rb
|
252
|
-
- test/util/test-method-owner-finder.rb
|
242
|
+
- test/test-attribute.rb
|
243
|
+
- test/test-priority.rb
|
244
|
+
- test/test-color-scheme.rb
|
253
245
|
- test/test-failure.rb
|
254
|
-
- test/test-pending.rb
|
255
|
-
- test/test-test-case.rb
|
256
|
-
- test/test-attribute-matcher.rb
|
257
|
-
- test/test-omission.rb
|
258
246
|
- test/test-color.rb
|
259
247
|
- test/ui/test_testrunmediator.rb
|
260
|
-
- test/test-
|
261
|
-
- test/test-
|
262
|
-
- test/test-
|
263
|
-
- test/
|
264
|
-
- test/
|
265
|
-
- test/
|
266
|
-
- test/
|
267
|
-
- test/test-color-scheme.rb
|
268
|
-
- test/test-assertions.rb
|
269
|
-
- test/fixtures/plus.csv
|
270
|
-
- test/fixtures/header-label.csv
|
248
|
+
- test/test-attribute-matcher.rb
|
249
|
+
- test/test-test-suite.rb
|
250
|
+
- test/test-test-suite-creator.rb
|
251
|
+
- test/test-diff.rb
|
252
|
+
- test/test-emacs-runner.rb
|
253
|
+
- test/test-data.rb
|
254
|
+
- test/fixtures/header.csv
|
271
255
|
- test/fixtures/header.tsv
|
272
256
|
- test/fixtures/no-header.tsv
|
273
|
-
- test/fixtures/
|
274
|
-
- test/fixtures/header-label.tsv
|
257
|
+
- test/fixtures/plus.csv
|
275
258
|
- test/fixtures/no-header.csv
|
276
|
-
- test/
|
259
|
+
- test/fixtures/header-label.tsv
|
260
|
+
- test/fixtures/header-label.csv
|
261
|
+
- test/test-assertions.rb
|
277
262
|
- test/test-test-result.rb
|
278
|
-
- test/test-
|
263
|
+
- test/testunit-test-util.rb
|
264
|
+
- test/collector/test-load.rb
|
265
|
+
- test/collector/test_dir.rb
|
266
|
+
- test/collector/test_objectspace.rb
|
267
|
+
- test/collector/test-descendant.rb
|
268
|
+
- test/test-error.rb
|
269
|
+
- test/run-test.rb
|
270
|
+
- test/test-pending.rb
|
271
|
+
- test/test-fixture.rb
|
272
|
+
- test/util/test-output.rb
|
273
|
+
- test/util/test-method-owner-finder.rb
|
274
|
+
- test/util/test_observable.rb
|
275
|
+
- test/util/test_procwrapper.rb
|
276
|
+
- test/util/test_backtracefilter.rb
|
277
|
+
- test/test-notification.rb
|
278
|
+
- test/test-omission.rb
|
279
|
+
- test/test-test-case.rb
|