test-unit 3.4.2 → 3.4.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b0ea1c609f04e687f6b9c2bbc5d02efc79b1cf02516ddd36ff73a2cb974a2b0
4
- data.tar.gz: 5110042334219485a6e99963685c6a51497509da5ec833516c0fa7a7a6eb0294
3
+ metadata.gz: '096e65b8d56779e795090f5e56e10a10bcef4f666f45702da71acb1e0e0e769e'
4
+ data.tar.gz: 31402966d552fe2c7cd960185929963e7358296e9ff5727be4c7a72781d070b7
5
5
  SHA512:
6
- metadata.gz: 7201589c5975139093ac4618f696ba4f40448f9d4da7e2d437545d3f105563aed379d382ce57fe09ac5b27aa41af235019befaf2a8d96d5dcc6d6609cc13798e
7
- data.tar.gz: e65b33f3f9560ad8581987617520b03ccdd63d59d5354546663fc0898209b3bbcebdc471c2afca5c2112897d34ad6d933f7ef416f2d6ccaad805f45b0a17a24b
6
+ metadata.gz: e46ad14d93dadac17224d10ab58617acc4dfaae61f06067c400308d9c1b3ad060201e88a7fd097d94d93c053a1d5bed0a9f56e765bb573fe960c7086251a891c
7
+ data.tar.gz: cfa5f1b593e993ff2643cab4989428817fdae1258a357797b2e42d0d563022351349eb3648056305df8ddb6f5e9847a1084646f2edec93b7a1c519bba96c9d11
data/doc/text/news.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # News
2
2
 
3
+ ## 3.4.3 - 2021-06-04 {#version-3-4-3}
4
+
5
+ ### Improvements
6
+
7
+ * Stopped to change result value of `Test::Unit::TestCase#include`.
8
+
9
+ * Added `assert_all?`.
10
+
11
+ * Added support for `assert_raise_with_message`.
12
+
3
13
  ## 3.4.2 - 2021-05-30 {#version-3-4-2}
4
14
 
5
15
  ### Improvements
@@ -289,6 +289,71 @@ EOT
289
289
  # Just for minitest compatibility. :<
290
290
  alias_method :assert_raises, :assert_raise
291
291
 
292
+ # Passes if the block raises `expected_exception` with
293
+ # `expected_message`. `expected_message` can be a `String` or
294
+ # `Regexp`.
295
+ #
296
+ # @example Pass pattern: String
297
+ # assert_raise_with_message(RuntimeError, "Boom!!!") do
298
+ # raise "Boom!!!"
299
+ # end # -> pass
300
+ #
301
+ # @example Pass pattern: Regexp
302
+ # assert_raise_with_message(RuntimeError, /!!!/) do
303
+ # raise "Boom!!!"
304
+ # end # -> pass
305
+ #
306
+ # @example Failure pattern: Exception class isn't matched
307
+ # assert_raise_with_message(RuntimeError, "Boom!!!") do
308
+ # raise ArgumentError, "Boom!!!"
309
+ # end # -> failure
310
+ #
311
+ # @example Failure pattern: Exception message isn't matched
312
+ # assert_raise_with_message(RuntimeError, "Boom!!!") do
313
+ # raise "Hello"
314
+ # end # -> failure
315
+ #
316
+ # @since 3.4.3
317
+ def assert_raise_with_message(expected_exception_class,
318
+ expected_message,
319
+ message=nil,
320
+ &block)
321
+ assert_expected_exception = Proc.new do |*_args|
322
+ _message, assert_exception_helper, actual_exception = _args
323
+ diff = AssertionMessage.delayed_diff([
324
+ expected_exception_class,
325
+ expected_message,
326
+ ],
327
+ [
328
+ actual_exception.class,
329
+ actual_exception.message,
330
+ ])
331
+ full_message = build_message(message,
332
+ "<?>(<?>) exception expected but was\n" +
333
+ "<?>(<?>).?",
334
+ expected_exception_class,
335
+ expected_message,
336
+ actual_exception.class,
337
+ actual_exception.message,
338
+ diff)
339
+ begin
340
+ assert_block(full_message) do
341
+ assert_exception_helper.expected?(actual_exception) and
342
+ expected_message === actual_exception.message
343
+ end
344
+ rescue AssertionFailedError => failure
345
+ _set_failed_information(failure,
346
+ expected_exception_class,
347
+ actual_exception)
348
+ raise failure # For JRuby. :<
349
+ end
350
+ actual_exception
351
+ end
352
+ args = [expected_exception_class]
353
+ args << message if message
354
+ _assert_raise(assert_expected_exception, *args, &block)
355
+ end
356
+
292
357
  ##
293
358
  # Passes if the block raises one of the given
294
359
  # exceptions or sub exceptions of the given exceptions.
@@ -1612,6 +1677,53 @@ EOT
1612
1677
  # @since 3.0.0
1613
1678
  alias_method :refute_empty, :assert_not_empty
1614
1679
 
1680
+ # @overload assert_all?(collection, message=nil, &block)
1681
+ #
1682
+ # Asserts that all `block.call(item)` where `item` is each
1683
+ # item in `collection` are not false nor nil.
1684
+ #
1685
+ # If `collection` is empty, this assertion is always passed
1686
+ # with any `block`.
1687
+ #
1688
+ # @example Pass patterns
1689
+ # assert_all?([1, 2, 3]) {|item| item > 0} # => pass
1690
+ # assert_all?([1, 2, 3], &:positive?) # => pass
1691
+ # assert_all?([]) {|item| false} # => pass
1692
+ #
1693
+ # @example Failure pattern
1694
+ # assert_all?([0, 1, 2], &:zero?) # => failure
1695
+ #
1696
+ # @param [#each] collection The check target.
1697
+ # @param [String] message The additional user message. It is
1698
+ # showed when the assertion is failed.
1699
+ # @yield [Object] Give each item in `collection` to the block.
1700
+ # @yieldreturn [Object] The checked object.
1701
+ # @return [void]
1702
+ #
1703
+ # @since 3.4.3
1704
+ def assert_all?(collection, message=nil)
1705
+ _wrap_assertion do
1706
+ failed = false
1707
+ result = {}
1708
+ collection.each do |item|
1709
+ element_result = yield(item)
1710
+ failed = true unless element_result
1711
+ result[item] = element_result
1712
+ end
1713
+ format = <<-FORMAT
1714
+ <?> was expected to be all true values with the given block but was
1715
+ <?>
1716
+ FORMAT
1717
+ full_message = build_message(message,
1718
+ format,
1719
+ collection,
1720
+ result)
1721
+ assert_block(full_message) do
1722
+ not failed
1723
+ end
1724
+ end
1725
+ end
1726
+
1615
1727
  ##
1616
1728
  # Builds a failure message. `user_message` is added before the
1617
1729
  # `template` and `arguments` replaces the '?'s positionally in
@@ -131,12 +131,13 @@ module Test
131
131
  end
132
132
 
133
133
  def include(*modules, &block) # :nodoc:
134
- super
134
+ result = super
135
135
  modules.each do |mod|
136
136
  mod.public_instance_methods(false).each do |method_name|
137
137
  AutoRunnerLoader.check(self, method_name.to_s)
138
138
  end
139
139
  end
140
+ result
140
141
  end
141
142
 
142
143
  @@added_method_names = {}
@@ -1,5 +1,5 @@
1
1
  module Test
2
2
  module Unit
3
- VERSION = "3.4.2"
3
+ VERSION = "3.4.3"
4
4
  end
5
5
  end
@@ -98,7 +98,8 @@ module Test
98
98
 
99
99
  def check_fail_exception(expected_message, options={}, &proc)
100
100
  normalizer = lambda do |actual_message|
101
- actual_message.gsub(/^(?:<internal:core> )?[^:\n]+:\d+:.+\n/, "")
101
+ actual_message.gsub(/^(?:[a-zA-Z]:|<internal:core> )?[^:\n]+:\d+:.+\n/,
102
+ "")
102
103
  end
103
104
  check_assertions(true,
104
105
  options.merge(:expected_message => expected_message,
@@ -1606,6 +1607,66 @@ MESSAGE
1606
1607
  end
1607
1608
  end
1608
1609
 
1610
+ class TestAssertRaiseWithMessage < Test::Unit::TestCase
1611
+ include AssertionCheckable
1612
+
1613
+ def test_pass_string
1614
+ check_nothing_fails(true) do
1615
+ assert_raise_with_message(RuntimeError, "Boom!!!") do
1616
+ raise "Boom!!!"
1617
+ end
1618
+ end
1619
+ end
1620
+
1621
+ def test_pass_regexp
1622
+ check_nothing_fails(true) do
1623
+ assert_raise_with_message(RuntimeError, /!!!/) do
1624
+ raise "Boom!!!"
1625
+ end
1626
+ end
1627
+ end
1628
+
1629
+ def test_pass_message
1630
+ check_nothing_fails(true) do
1631
+ assert_raise_with_message(RuntimeError, "Boom!!!", "message") do
1632
+ raise "Boom!!!"
1633
+ end
1634
+ end
1635
+ end
1636
+
1637
+ def test_fail_unmatch_class
1638
+ expected_message = <<-MESSAGE.chomp
1639
+ message.
1640
+ <LoadError>(<"Boom!!!">) exception expected but was
1641
+ <RuntimeError>(<"Boom!!!">).
1642
+
1643
+ diff:
1644
+ - [LoadError, "Boom!!!"]
1645
+ ? ^^^^
1646
+ + [RuntimeError, "Boom!!!"]
1647
+ ? ^^^^^^^
1648
+ MESSAGE
1649
+ check_fail(expected_message) do
1650
+ assert_raise_with_message(LoadError, "Boom!!!", "message") do
1651
+ raise "Boom!!!"
1652
+ end
1653
+ end
1654
+ end
1655
+
1656
+ def test_fail_unmatch_message
1657
+ expected_message = <<-MESSAGE.chomp
1658
+ message.
1659
+ <RuntimeError>(</Hello/>) exception expected but was
1660
+ <RuntimeError>(<"Boom!!!">).
1661
+ MESSAGE
1662
+ check_fail(expected_message) do
1663
+ assert_raise_with_message(RuntimeError, /Hello/, "message") do
1664
+ raise "Boom!!!"
1665
+ end
1666
+ end
1667
+ end
1668
+ end
1669
+
1609
1670
  class TestAssertInDelta < TestCase
1610
1671
  include AssertionCheckable
1611
1672
 
@@ -2169,6 +2230,39 @@ EOM
2169
2230
  end
2170
2231
  end
2171
2232
 
2233
+ class TestAssertAll < Test::Unit::TestCase
2234
+ include AssertionCheckable
2235
+
2236
+ def test_pass
2237
+ check_nothing_fails do
2238
+ assert_all?([1, 2]) {|item| item > 0}
2239
+ end
2240
+ end
2241
+
2242
+ def test_pass_message
2243
+ check_nothing_fails do
2244
+ assert_all?([1, 2], "positive") {|item| item > 0}
2245
+ end
2246
+ end
2247
+
2248
+ def test_pass_empty
2249
+ check_nothing_fails do
2250
+ assert_all?([]) {|item| false}
2251
+ end
2252
+ end
2253
+
2254
+ def test_fail
2255
+ expected_message = <<-EOM
2256
+ message.
2257
+ <[0, 1]> was expected to be all true values with the given block but was
2258
+ <{0=>true, 1=>false}>
2259
+ EOM
2260
+ check_fail(expected_message.chomp) do
2261
+ assert_all?([0, 1], "message", &:zero?)
2262
+ end
2263
+ end
2264
+ end
2265
+
2172
2266
  class TestTemplate < Test::Unit::TestCase
2173
2267
  def test_incompatible_encoding_by_diff
2174
2268
  need_encoding
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.4.2
4
+ version: 3.4.3
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: 2021-05-29 00:00:00.000000000 Z
12
+ date: 2021-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: power_assert