minitest 5.11.3 → 5.22.3
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 +280 -4
- data/Manifest.txt +4 -0
- data/README.rdoc +104 -17
- data/Rakefile +5 -16
- data/lib/hoe/minitest.rb +0 -4
- data/lib/minitest/assertions.rb +209 -42
- data/lib/minitest/benchmark.rb +7 -7
- data/lib/minitest/compress.rb +94 -0
- data/lib/minitest/expectations.rb +72 -35
- data/lib/minitest/mock.rb +123 -34
- data/lib/minitest/pride_plugin.rb +8 -11
- data/lib/minitest/spec.rb +27 -9
- data/lib/minitest/test.rb +48 -19
- data/lib/minitest/test_task.rb +301 -0
- data/lib/minitest/unit.rb +5 -8
- data/lib/minitest.rb +247 -69
- data/test/minitest/metametameta.rb +52 -12
- data/test/minitest/test_minitest_assertions.rb +1721 -0
- data/test/minitest/test_minitest_benchmark.rb +2 -2
- data/test/minitest/test_minitest_mock.rb +289 -17
- data/test/minitest/test_minitest_reporter.rb +160 -19
- data/test/minitest/test_minitest_spec.rb +314 -155
- data/test/minitest/test_minitest_test.rb +429 -1196
- data/test/minitest/test_minitest_test_task.rb +48 -0
- data.tar.gz.sig +0 -0
- metadata +38 -23
- metadata.gz.sig +0 -0
| @@ -3,7 +3,7 @@ require "minitest/benchmark" | |
| 3 3 |  | 
| 4 4 | 
             
            ##
         | 
| 5 5 | 
             
            # Used to verify data:
         | 
| 6 | 
            -
            #  | 
| 6 | 
            +
            # https://www.wolframalpha.com/examples/RegressionAnalysis.html
         | 
| 7 7 |  | 
| 8 8 | 
             
            class TestMinitestBenchmark < Minitest::Test
         | 
| 9 9 | 
             
              def test_cls_bench_exp
         | 
| @@ -110,7 +110,7 @@ class TestMinitestBenchmark < Minitest::Test | |
| 110 110 | 
             
                assert_fit :power, x, y, 0.90, 2.6217, 1.4556
         | 
| 111 111 |  | 
| 112 112 | 
             
                # income to % of households below income amount
         | 
| 113 | 
            -
                #  | 
| 113 | 
            +
                # https://library.wolfram.com/infocenter/Conferences/6461/PowerLaws.nb
         | 
| 114 114 | 
             
                x = [15_000, 25_000, 35_000, 50_000, 75_000, 100_000]
         | 
| 115 115 | 
             
                y = [0.154, 0.283, 0.402, 0.55, 0.733, 0.843]
         | 
| 116 116 |  | 
| @@ -1,8 +1,14 @@ | |
| 1 1 | 
             
            require "minitest/autorun"
         | 
| 2 2 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
               | 
| 3 | 
            +
            def with_kwargs_env
         | 
| 4 | 
            +
              ENV["MT_KWARGS_HAC\K"] = "1"
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              yield
         | 
| 7 | 
            +
            ensure
         | 
| 8 | 
            +
              ENV.delete "MT_KWARGS_HAC\K"
         | 
| 9 | 
            +
            end
         | 
| 5 10 |  | 
| 11 | 
            +
            class TestMinitestMock < Minitest::Test
         | 
| 6 12 | 
             
              def setup
         | 
| 7 13 | 
             
                @mock = Minitest::Mock.new.expect(:foo, nil)
         | 
| 8 14 | 
             
                @mock.expect(:meaning_of_life, 42)
         | 
| @@ -51,7 +57,7 @@ class TestMinitestMock < Minitest::Test | |
| 51 57 | 
             
                  @mock.sum
         | 
| 52 58 | 
             
                end
         | 
| 53 59 |  | 
| 54 | 
            -
                assert_equal "mocked method :sum expects 2 arguments, got  | 
| 60 | 
            +
                assert_equal "mocked method :sum expects 2 arguments, got []", e.message
         | 
| 55 61 | 
             
              end
         | 
| 56 62 |  | 
| 57 63 | 
             
              def test_return_mock_does_not_raise
         | 
| @@ -64,8 +70,6 @@ class TestMinitestMock < Minitest::Test | |
| 64 70 | 
             
              end
         | 
| 65 71 |  | 
| 66 72 | 
             
              def test_mock_args_does_not_raise
         | 
| 67 | 
            -
                skip "non-opaque use of ==" if maglev?
         | 
| 68 | 
            -
             | 
| 69 73 | 
             
                arg = Minitest::Mock.new
         | 
| 70 74 | 
             
                mock = Minitest::Mock.new
         | 
| 71 75 | 
             
                mock.expect(:foo, nil, [arg])
         | 
| @@ -135,7 +139,7 @@ class TestMinitestMock < Minitest::Test | |
| 135 139 | 
             
                  @mock.expect :blah, 3, false
         | 
| 136 140 | 
             
                end
         | 
| 137 141 |  | 
| 138 | 
            -
                 | 
| 142 | 
            +
                assert_match "args must be an array", e.message
         | 
| 139 143 | 
             
              end
         | 
| 140 144 |  | 
| 141 145 | 
             
              def test_respond_appropriately
         | 
| @@ -152,7 +156,7 @@ class TestMinitestMock < Minitest::Test | |
| 152 156 |  | 
| 153 157 | 
             
                expected = "unmocked method :bar, expected one of [:foo, :meaning_of_life]"
         | 
| 154 158 |  | 
| 155 | 
            -
                 | 
| 159 | 
            +
                assert_match expected, e.message
         | 
| 156 160 | 
             
              end
         | 
| 157 161 |  | 
| 158 162 | 
             
              def test_assign_per_mock_return_values
         | 
| @@ -212,7 +216,7 @@ class TestMinitestMock < Minitest::Test | |
| 212 216 | 
             
                  mock.a
         | 
| 213 217 | 
             
                end
         | 
| 214 218 |  | 
| 215 | 
            -
                assert_equal "No more expects available for :a: []", e.message
         | 
| 219 | 
            +
                assert_equal "No more expects available for :a: [] {}", e.message
         | 
| 216 220 | 
             
              end
         | 
| 217 221 |  | 
| 218 222 | 
             
              def test_same_method_expects_are_verified_when_all_called
         | 
| @@ -254,6 +258,30 @@ class TestMinitestMock < Minitest::Test | |
| 254 258 | 
             
                assert_equal exp, e.message
         | 
| 255 259 | 
             
              end
         | 
| 256 260 |  | 
| 261 | 
            +
              def test_delegator_calls_are_propagated
         | 
| 262 | 
            +
                delegator = Object.new
         | 
| 263 | 
            +
                mock = Minitest::Mock.new delegator
         | 
| 264 | 
            +
             | 
| 265 | 
            +
                refute delegator.nil?
         | 
| 266 | 
            +
                refute mock.nil?
         | 
| 267 | 
            +
                assert_mock mock
         | 
| 268 | 
            +
              end
         | 
| 269 | 
            +
             | 
| 270 | 
            +
              def test_handles_kwargs_in_error_message
         | 
| 271 | 
            +
                mock = Minitest::Mock.new
         | 
| 272 | 
            +
             | 
| 273 | 
            +
                mock.expect :foo, nil, [], kw: true
         | 
| 274 | 
            +
                mock.expect :foo, nil, [], kw: false
         | 
| 275 | 
            +
             | 
| 276 | 
            +
                mock.foo kw: true
         | 
| 277 | 
            +
             | 
| 278 | 
            +
                e = assert_raises(MockExpectationError) { mock.verify }
         | 
| 279 | 
            +
             | 
| 280 | 
            +
                exp = "expected foo(:kw=>false) => nil, got [foo(:kw=>true) => nil]"
         | 
| 281 | 
            +
             | 
| 282 | 
            +
                assert_equal exp, e.message
         | 
| 283 | 
            +
              end
         | 
| 284 | 
            +
             | 
| 257 285 | 
             
              def test_verify_passes_when_mock_block_returns_true
         | 
| 258 286 | 
             
                mock = Minitest::Mock.new
         | 
| 259 287 | 
             
                mock.expect :foo, nil do
         | 
| @@ -272,11 +300,188 @@ class TestMinitestMock < Minitest::Test | |
| 272 300 | 
             
                  a1 == arg1 && a2 == arg2 && a3 == arg3
         | 
| 273 301 | 
             
                end
         | 
| 274 302 |  | 
| 275 | 
            -
                 | 
| 303 | 
            +
                assert_silent do
         | 
| 304 | 
            +
                  if RUBY_VERSION > "3" then
         | 
| 305 | 
            +
                    mock.foo arg1, arg2, arg3
         | 
| 306 | 
            +
                  else
         | 
| 307 | 
            +
                    mock.foo arg1, arg2, **arg3 # oddity just for ruby 2.7
         | 
| 308 | 
            +
                  end
         | 
| 309 | 
            +
                end
         | 
| 310 | 
            +
             | 
| 311 | 
            +
                assert_mock mock
         | 
| 312 | 
            +
              end
         | 
| 313 | 
            +
             | 
| 314 | 
            +
              def test_mock_block_is_passed_keyword_args__block
         | 
| 315 | 
            +
                arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
         | 
| 316 | 
            +
                mock = Minitest::Mock.new
         | 
| 317 | 
            +
                mock.expect :foo, nil do |k1:, k2:, k3:|
         | 
| 318 | 
            +
                  k1 == arg1 && k2 == arg2 && k3 == arg3
         | 
| 319 | 
            +
                end
         | 
| 320 | 
            +
             | 
| 321 | 
            +
                mock.foo(k1: arg1, k2: arg2, k3: arg3)
         | 
| 322 | 
            +
             | 
| 323 | 
            +
                assert_mock mock
         | 
| 324 | 
            +
              end
         | 
| 325 | 
            +
             | 
| 326 | 
            +
              def test_mock_block_is_passed_keyword_args__block_bad_missing
         | 
| 327 | 
            +
                arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
         | 
| 328 | 
            +
                mock = Minitest::Mock.new
         | 
| 329 | 
            +
                mock.expect :foo, nil do |k1:, k2:, k3:|
         | 
| 330 | 
            +
                  k1 == arg1 && k2 == arg2 && k3 == arg3
         | 
| 331 | 
            +
                end
         | 
| 332 | 
            +
             | 
| 333 | 
            +
                e = assert_raises ArgumentError do
         | 
| 334 | 
            +
                  mock.foo(k1: arg1, k2: arg2)
         | 
| 335 | 
            +
                end
         | 
| 336 | 
            +
             | 
| 337 | 
            +
                # basically testing ruby ... need ? for ruby < 2.7 :(
         | 
| 338 | 
            +
                assert_match(/missing keyword: :?k3/, e.message)
         | 
| 339 | 
            +
              end
         | 
| 340 | 
            +
             | 
| 341 | 
            +
              def test_mock_block_is_passed_keyword_args__block_bad_extra
         | 
| 342 | 
            +
                arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
         | 
| 343 | 
            +
                mock = Minitest::Mock.new
         | 
| 344 | 
            +
                mock.expect :foo, nil do |k1:, k2:|
         | 
| 345 | 
            +
                  k1 == arg1 && k2 == arg2 && k3 == arg3
         | 
| 346 | 
            +
                end
         | 
| 347 | 
            +
             | 
| 348 | 
            +
                e = assert_raises ArgumentError do
         | 
| 349 | 
            +
                  mock.foo(k1: arg1, k2: arg2, k3: arg3)
         | 
| 350 | 
            +
                end
         | 
| 351 | 
            +
             | 
| 352 | 
            +
                # basically testing ruby ... need ? for ruby < 2.7 :(
         | 
| 353 | 
            +
                assert_match(/unknown keyword: :?k3/, e.message)
         | 
| 354 | 
            +
              end
         | 
| 355 | 
            +
             | 
| 356 | 
            +
              def test_mock_block_is_passed_keyword_args__block_bad_value
         | 
| 357 | 
            +
                arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
         | 
| 358 | 
            +
                mock = Minitest::Mock.new
         | 
| 359 | 
            +
                mock.expect :foo, nil do |k1:, k2:, k3:|
         | 
| 360 | 
            +
                  k1 == arg1 && k2 == arg2 && k3 == arg3
         | 
| 361 | 
            +
                end
         | 
| 362 | 
            +
             | 
| 363 | 
            +
                e = assert_raises MockExpectationError do
         | 
| 364 | 
            +
                  mock.foo(k1: arg1, k2: arg2, k3: :BAD!)
         | 
| 365 | 
            +
                end
         | 
| 366 | 
            +
             | 
| 367 | 
            +
                exp = "mocked method :foo failed block w/ [] {:k1=>:bar, :k2=>[1, 2, 3], :k3=>:BAD!}"
         | 
| 368 | 
            +
                assert_equal exp, e.message
         | 
| 369 | 
            +
              end
         | 
| 370 | 
            +
             | 
| 371 | 
            +
              def test_mock_block_is_passed_keyword_args__args
         | 
| 372 | 
            +
                arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
         | 
| 373 | 
            +
                mock = Minitest::Mock.new
         | 
| 374 | 
            +
                mock.expect :foo, nil, k1: arg1, k2: arg2, k3: arg3
         | 
| 375 | 
            +
             | 
| 376 | 
            +
                mock.foo(k1: arg1, k2: arg2, k3: arg3)
         | 
| 276 377 |  | 
| 277 378 | 
             
                assert_mock mock
         | 
| 278 379 | 
             
              end
         | 
| 279 380 |  | 
| 381 | 
            +
              def test_mock_allow_all_kwargs__old_style_env
         | 
| 382 | 
            +
                with_kwargs_env do
         | 
| 383 | 
            +
                  mock = Minitest::Mock.new
         | 
| 384 | 
            +
                  mock.expect :foo, true, [Hash]
         | 
| 385 | 
            +
                  assert_equal true, mock.foo(bar: 42)
         | 
| 386 | 
            +
                end
         | 
| 387 | 
            +
              end
         | 
| 388 | 
            +
             | 
| 389 | 
            +
              def test_mock_allow_all_kwargs__old_style_env__rewrite
         | 
| 390 | 
            +
                with_kwargs_env do
         | 
| 391 | 
            +
                  mock = Minitest::Mock.new
         | 
| 392 | 
            +
                  mock.expect :foo, true, [], bar: Integer
         | 
| 393 | 
            +
                  assert_equal true, mock.foo(bar: 42)
         | 
| 394 | 
            +
                end
         | 
| 395 | 
            +
              end
         | 
| 396 | 
            +
             | 
| 397 | 
            +
              def test_mock_block_is_passed_keyword_args__args__old_style_bad
         | 
| 398 | 
            +
                arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
         | 
| 399 | 
            +
                mock = Minitest::Mock.new
         | 
| 400 | 
            +
                mock.expect :foo, nil, [{k1: arg1, k2: arg2, k3: arg3}]
         | 
| 401 | 
            +
             | 
| 402 | 
            +
                e = assert_raises ArgumentError do
         | 
| 403 | 
            +
                  mock.foo(k1: arg1, k2: arg2, k3: arg3)
         | 
| 404 | 
            +
                end
         | 
| 405 | 
            +
             | 
| 406 | 
            +
                assert_equal "mocked method :foo expects 1 arguments, got []", e.message
         | 
| 407 | 
            +
              end
         | 
| 408 | 
            +
             | 
| 409 | 
            +
              def test_mock_block_is_passed_keyword_args__args__old_style_env
         | 
| 410 | 
            +
                with_kwargs_env do
         | 
| 411 | 
            +
                  arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
         | 
| 412 | 
            +
                  mock = Minitest::Mock.new
         | 
| 413 | 
            +
                  mock.expect :foo, nil, [{k1: arg1, k2: arg2, k3: arg3}]
         | 
| 414 | 
            +
             | 
| 415 | 
            +
                  mock.foo(k1: arg1, k2: arg2, k3: arg3)
         | 
| 416 | 
            +
             | 
| 417 | 
            +
                  assert_mock mock
         | 
| 418 | 
            +
                end
         | 
| 419 | 
            +
              end
         | 
| 420 | 
            +
             | 
| 421 | 
            +
              def test_mock_block_is_passed_keyword_args__args__old_style_both
         | 
| 422 | 
            +
                with_kwargs_env do
         | 
| 423 | 
            +
                  arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
         | 
| 424 | 
            +
                  mock = Minitest::Mock.new
         | 
| 425 | 
            +
             | 
| 426 | 
            +
                  assert_output nil, /Using MT_KWARGS_HAC. yet passing kwargs/ do
         | 
| 427 | 
            +
                    mock.expect :foo, nil, [{}], k1: arg1, k2: arg2, k3: arg3
         | 
| 428 | 
            +
                  end
         | 
| 429 | 
            +
             | 
| 430 | 
            +
                  mock.foo({}, k1: arg1, k2: arg2, k3: arg3)
         | 
| 431 | 
            +
             | 
| 432 | 
            +
                  assert_mock mock
         | 
| 433 | 
            +
                end
         | 
| 434 | 
            +
              end
         | 
| 435 | 
            +
             | 
| 436 | 
            +
              def test_mock_block_is_passed_keyword_args__args_bad_missing
         | 
| 437 | 
            +
                arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
         | 
| 438 | 
            +
                mock = Minitest::Mock.new
         | 
| 439 | 
            +
                mock.expect :foo, nil, k1: arg1, k2: arg2, k3: arg3
         | 
| 440 | 
            +
             | 
| 441 | 
            +
                e = assert_raises ArgumentError do
         | 
| 442 | 
            +
                  mock.foo(k1: arg1, k2: arg2)
         | 
| 443 | 
            +
                end
         | 
| 444 | 
            +
             | 
| 445 | 
            +
                assert_equal "mocked method :foo expects 3 keyword arguments, got %p" % {k1: arg1, k2: arg2}, e.message
         | 
| 446 | 
            +
              end
         | 
| 447 | 
            +
             | 
| 448 | 
            +
              def test_mock_block_is_passed_keyword_args__args_bad_extra
         | 
| 449 | 
            +
                arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
         | 
| 450 | 
            +
                mock = Minitest::Mock.new
         | 
| 451 | 
            +
                mock.expect :foo, nil, k1: arg1, k2: arg2
         | 
| 452 | 
            +
             | 
| 453 | 
            +
                e = assert_raises ArgumentError do
         | 
| 454 | 
            +
                  mock.foo(k1: arg1, k2: arg2, k3: arg3)
         | 
| 455 | 
            +
                end
         | 
| 456 | 
            +
             | 
| 457 | 
            +
                assert_equal "mocked method :foo expects 2 keyword arguments, got %p" % {k1: arg1, k2: arg2, k3: arg3}, e.message
         | 
| 458 | 
            +
              end
         | 
| 459 | 
            +
             | 
| 460 | 
            +
              def test_mock_block_is_passed_keyword_args__args_bad_key
         | 
| 461 | 
            +
                arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
         | 
| 462 | 
            +
                mock = Minitest::Mock.new
         | 
| 463 | 
            +
                mock.expect :foo, nil, k1: arg1, k2: arg2, k3: arg3
         | 
| 464 | 
            +
             | 
| 465 | 
            +
                e = assert_raises MockExpectationError do
         | 
| 466 | 
            +
                  mock.foo(k1: arg1, k2: arg2, BAD: arg3)
         | 
| 467 | 
            +
                end
         | 
| 468 | 
            +
             | 
| 469 | 
            +
                assert_includes e.message, "unexpected keywords [:k1, :k2, :k3]"
         | 
| 470 | 
            +
                assert_includes e.message, "vs [:k1, :k2, :BAD]"
         | 
| 471 | 
            +
              end
         | 
| 472 | 
            +
             | 
| 473 | 
            +
              def test_mock_block_is_passed_keyword_args__args_bad_val
         | 
| 474 | 
            +
                arg1, arg2, arg3 = :bar, [1, 2, 3], { :a => "a" }
         | 
| 475 | 
            +
                mock = Minitest::Mock.new
         | 
| 476 | 
            +
                mock.expect :foo, nil, k1: arg1, k2: arg2, k3: arg3
         | 
| 477 | 
            +
             | 
| 478 | 
            +
                e = assert_raises MockExpectationError do
         | 
| 479 | 
            +
                  mock.foo(k1: arg1, k2: :BAD!, k3: arg3)
         | 
| 480 | 
            +
                end
         | 
| 481 | 
            +
             | 
| 482 | 
            +
                assert_match(/unexpected keyword arguments.* vs .*:k2=>:BAD!/, e.message)
         | 
| 483 | 
            +
              end
         | 
| 484 | 
            +
             | 
| 280 485 | 
             
              def test_mock_block_is_passed_function_block
         | 
| 281 486 | 
             
                mock = Minitest::Mock.new
         | 
| 282 487 | 
             
                block = proc { "bar" }
         | 
| @@ -288,6 +493,13 @@ class TestMinitestMock < Minitest::Test | |
| 288 493 | 
             
                assert_mock mock
         | 
| 289 494 | 
             
              end
         | 
| 290 495 |  | 
| 496 | 
            +
              def test_mock_forward_keyword_arguments
         | 
| 497 | 
            +
                mock = Minitest::Mock.new
         | 
| 498 | 
            +
                mock.expect(:foo, nil) { |bar:| bar == 'bar' }
         | 
| 499 | 
            +
                mock.foo(bar: 'bar')
         | 
| 500 | 
            +
                assert_mock mock
         | 
| 501 | 
            +
              end
         | 
| 502 | 
            +
             | 
| 291 503 | 
             
              def test_verify_fails_when_mock_block_returns_false
         | 
| 292 504 | 
             
                mock = Minitest::Mock.new
         | 
| 293 505 | 
             
                mock.expect :foo, nil do
         | 
| @@ -295,12 +507,12 @@ class TestMinitestMock < Minitest::Test | |
| 295 507 | 
             
                end
         | 
| 296 508 |  | 
| 297 509 | 
             
                e = assert_raises(MockExpectationError) { mock.foo }
         | 
| 298 | 
            -
                exp = "mocked method :foo failed block w/ []"
         | 
| 510 | 
            +
                exp = "mocked method :foo failed block w/ [] {}"
         | 
| 299 511 |  | 
| 300 512 | 
             
                assert_equal exp, e.message
         | 
| 301 513 | 
             
              end
         | 
| 302 514 |  | 
| 303 | 
            -
              def  | 
| 515 | 
            +
              def test_mock_block_raises_if_args_passed
         | 
| 304 516 | 
             
                mock = Minitest::Mock.new
         | 
| 305 517 |  | 
| 306 518 | 
             
                e = assert_raises(ArgumentError) do
         | 
| @@ -311,7 +523,21 @@ class TestMinitestMock < Minitest::Test | |
| 311 523 |  | 
| 312 524 | 
             
                exp = "args ignored when block given"
         | 
| 313 525 |  | 
| 314 | 
            -
                 | 
| 526 | 
            +
                assert_match exp, e.message
         | 
| 527 | 
            +
              end
         | 
| 528 | 
            +
             | 
| 529 | 
            +
              def test_mock_block_raises_if_kwargs_passed
         | 
| 530 | 
            +
                mock = Minitest::Mock.new
         | 
| 531 | 
            +
             | 
| 532 | 
            +
                e = assert_raises(ArgumentError) do
         | 
| 533 | 
            +
                  mock.expect :foo, nil, kwargs:1 do
         | 
| 534 | 
            +
                    true
         | 
| 535 | 
            +
                  end
         | 
| 536 | 
            +
                end
         | 
| 537 | 
            +
             | 
| 538 | 
            +
                exp = "kwargs ignored when block given"
         | 
| 539 | 
            +
             | 
| 540 | 
            +
                assert_match exp, e.message
         | 
| 315 541 | 
             
              end
         | 
| 316 542 |  | 
| 317 543 | 
             
              def test_mock_returns_retval_when_called_with_block
         | 
| @@ -362,7 +588,7 @@ end | |
| 362 588 | 
             
            require "minitest/metametameta"
         | 
| 363 589 |  | 
| 364 590 | 
             
            class TestMinitestStub < Minitest::Test
         | 
| 365 | 
            -
               | 
| 591 | 
            +
              # Do not parallelize since we're calling stub on class methods
         | 
| 366 592 |  | 
| 367 593 | 
             
              def setup
         | 
| 368 594 | 
             
                super
         | 
| @@ -374,7 +600,7 @@ class TestMinitestStub < Minitest::Test | |
| 374 600 |  | 
| 375 601 | 
             
              def teardown
         | 
| 376 602 | 
             
                super
         | 
| 377 | 
            -
                assert_equal @assertion_count, @tc.assertions
         | 
| 603 | 
            +
                assert_equal @assertion_count, @tc.assertions if self.passed?
         | 
| 378 604 | 
             
              end
         | 
| 379 605 |  | 
| 380 606 | 
             
              class Time
         | 
| @@ -501,7 +727,8 @@ class TestMinitestStub < Minitest::Test | |
| 501 727 | 
             
                  end
         | 
| 502 728 | 
             
                end
         | 
| 503 729 |  | 
| 504 | 
            -
                exp = / | 
| 730 | 
            +
                exp = jruby? ? /Undefined method nope_nope_nope for '#{self.class}::Time'/ :
         | 
| 731 | 
            +
                  /undefined method [`']nope_nope_nope' for( class)? [`']#{self.class}::Time'/
         | 
| 505 732 | 
             
                assert_match exp, e.message
         | 
| 506 733 | 
             
              end
         | 
| 507 734 |  | 
| @@ -520,6 +747,19 @@ class TestMinitestStub < Minitest::Test | |
| 520 747 | 
             
                @tc.assert_equal true, rs
         | 
| 521 748 | 
             
              end
         | 
| 522 749 |  | 
| 750 | 
            +
              def test_mock_with_yield_kwargs
         | 
| 751 | 
            +
                mock = Minitest::Mock.new
         | 
| 752 | 
            +
                rs = nil
         | 
| 753 | 
            +
             | 
| 754 | 
            +
                File.stub :open, true, mock, kw:42 do
         | 
| 755 | 
            +
                  File.open "foo.txt", "r" do |f, kw:|
         | 
| 756 | 
            +
                    rs = kw
         | 
| 757 | 
            +
                  end
         | 
| 758 | 
            +
                end
         | 
| 759 | 
            +
             | 
| 760 | 
            +
                @tc.assert_equal 42, rs
         | 
| 761 | 
            +
              end
         | 
| 762 | 
            +
             | 
| 523 763 | 
             
              alias test_stub_value__old test_stub_value # TODO: remove/rename
         | 
| 524 764 |  | 
| 525 765 | 
             
              ## Permutation Sets:
         | 
| @@ -593,6 +833,38 @@ class TestMinitestStub < Minitest::Test | |
| 593 833 | 
             
                end
         | 
| 594 834 | 
             
              end
         | 
| 595 835 |  | 
| 836 | 
            +
              class Keywords
         | 
| 837 | 
            +
                def self.args req, kw1:, kw2:24
         | 
| 838 | 
            +
                  [req, kw1, kw2]
         | 
| 839 | 
            +
                end
         | 
| 840 | 
            +
              end
         | 
| 841 | 
            +
             | 
| 842 | 
            +
              def test_stub_callable_keyword_args
         | 
| 843 | 
            +
                Keywords.stub :args, ->(*args, **kws) { [args, kws] } do
         | 
| 844 | 
            +
                  @tc.assert_equal [["woot"], { kw1: 42 }], Keywords.args("woot", kw1: 42)
         | 
| 845 | 
            +
                end
         | 
| 846 | 
            +
              end
         | 
| 847 | 
            +
             | 
| 848 | 
            +
              def test_stub__hash_as_last_real_arg
         | 
| 849 | 
            +
                with_kwargs_env do
         | 
| 850 | 
            +
                  token = Object.new
         | 
| 851 | 
            +
                  def token.create_with_retry u, p; raise "shouldn't see this"; end
         | 
| 852 | 
            +
             | 
| 853 | 
            +
                  controller = Object.new
         | 
| 854 | 
            +
                  controller.define_singleton_method :create do |u, p|
         | 
| 855 | 
            +
                    token.create_with_retry u, p
         | 
| 856 | 
            +
                  end
         | 
| 857 | 
            +
             | 
| 858 | 
            +
                  params = Object.new
         | 
| 859 | 
            +
                  def params.to_hash; raise "nah"; end
         | 
| 860 | 
            +
             | 
| 861 | 
            +
                  token.stub(:create_with_retry, ->(u, p) { 42 }) do
         | 
| 862 | 
            +
                    act = controller.create :u, params
         | 
| 863 | 
            +
                    @tc.assert_equal 42, act
         | 
| 864 | 
            +
                  end
         | 
| 865 | 
            +
                end
         | 
| 866 | 
            +
              end
         | 
| 867 | 
            +
             | 
| 596 868 | 
             
              def test_stub_callable_block_5 # from tenderlove
         | 
| 597 869 | 
             
                @assertion_count += 1
         | 
| 598 870 | 
             
                Foo.stub5 :blocking, Bar.new do
         | 
| @@ -811,8 +1083,8 @@ class TestMinitestStub < Minitest::Test | |
| 811 1083 | 
             
                    end
         | 
| 812 1084 | 
             
                  end
         | 
| 813 1085 | 
             
                end
         | 
| 814 | 
            -
                exp =  | 
| 815 | 
            -
                 | 
| 1086 | 
            +
                exp = /undefined method [`']write' for nil/
         | 
| 1087 | 
            +
                assert_match exp, e.message
         | 
| 816 1088 | 
             
              end
         | 
| 817 1089 |  | 
| 818 1090 | 
             
              def test_stub_value_block_args_6
         | 
| @@ -1,5 +1,6 @@ | |
| 1 1 | 
             
            require "minitest/autorun"
         | 
| 2 2 | 
             
            require "minitest/metametameta"
         | 
| 3 | 
            +
            require "forwardable"
         | 
| 3 4 |  | 
| 4 5 | 
             
            class Runnable
         | 
| 5 6 | 
             
              def woot
         | 
| @@ -12,30 +13,24 @@ class TestMinitestReporter < MetaMetaMetaTestCase | |
| 12 13 | 
             
              attr_accessor :r, :io
         | 
| 13 14 |  | 
| 14 15 | 
             
              def new_composite_reporter
         | 
| 16 | 
            +
                # Ruby bug in older versions of 2.2 & 2.3 on all platforms
         | 
| 17 | 
            +
                # Latest Windows builds were 2.2.6 and 2.3.3.  Latest Ruby releases were
         | 
| 18 | 
            +
                # 2.2.10 and 2.3.8.
         | 
| 19 | 
            +
                skip if windows? && RUBY_VERSION < '2.4'
         | 
| 15 20 | 
             
                reporter = Minitest::CompositeReporter.new
         | 
| 16 21 | 
             
                reporter << Minitest::SummaryReporter.new(self.io)
         | 
| 17 22 | 
             
                reporter << Minitest::ProgressReporter.new(self.io)
         | 
| 18 23 |  | 
| 19 | 
            -
                 | 
| 20 | 
            -
             | 
| 21 | 
            -
                 | 
| 22 | 
            -
             | 
| 23 | 
            -
                def reporter.results
         | 
| 24 | 
            -
                  first.results
         | 
| 25 | 
            -
                end
         | 
| 26 | 
            -
             | 
| 27 | 
            -
                def reporter.count
         | 
| 28 | 
            -
                  first.count
         | 
| 29 | 
            -
                end
         | 
| 30 | 
            -
             | 
| 31 | 
            -
                def reporter.assertions
         | 
| 32 | 
            -
                  first.assertions
         | 
| 33 | 
            -
                end
         | 
| 24 | 
            +
                # eg reporter.results -> reporters.first.results
         | 
| 25 | 
            +
                reporter.extend Forwardable
         | 
| 26 | 
            +
                reporter.delegate :first => :reporters
         | 
| 27 | 
            +
                reporter.delegate %i[results count assertions options to_s] => :first
         | 
| 34 28 |  | 
| 35 29 | 
             
                reporter
         | 
| 36 30 | 
             
              end
         | 
| 37 31 |  | 
| 38 32 | 
             
              def setup
         | 
| 33 | 
            +
                super
         | 
| 39 34 | 
             
                self.io = StringIO.new("")
         | 
| 40 35 | 
             
                self.r  = new_composite_reporter
         | 
| 41 36 | 
             
              end
         | 
| @@ -53,6 +48,25 @@ class TestMinitestReporter < MetaMetaMetaTestCase | |
| 53 48 | 
             
                @et
         | 
| 54 49 | 
             
              end
         | 
| 55 50 |  | 
| 51 | 
            +
              def system_stack_error_test
         | 
| 52 | 
            +
                unless defined? @sse then
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  ex = SystemStackError.new
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                  pre  = ("a".."c").to_a
         | 
| 57 | 
            +
                  mid  = ("aa".."ad").to_a * 67
         | 
| 58 | 
            +
                  post = ("d".."f").to_a
         | 
| 59 | 
            +
                  ary  = pre + mid + post
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                  ex.set_backtrace ary
         | 
| 62 | 
            +
             | 
| 63 | 
            +
                  @sse = Minitest::Test.new(:woot)
         | 
| 64 | 
            +
                  @sse.failures << Minitest::UnexpectedError.new(ex)
         | 
| 65 | 
            +
                  @sse = Minitest::Result.from @sse
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
                @sse
         | 
| 68 | 
            +
              end
         | 
| 69 | 
            +
             | 
| 56 70 | 
             
              def fail_test
         | 
| 57 71 | 
             
                unless defined? @ft then
         | 
| 58 72 | 
             
                  @ft = Minitest::Test.new(:woot)
         | 
| @@ -70,6 +84,12 @@ class TestMinitestReporter < MetaMetaMetaTestCase | |
| 70 84 | 
             
                @pt ||= Minitest::Result.from Minitest::Test.new(:woot)
         | 
| 71 85 | 
             
              end
         | 
| 72 86 |  | 
| 87 | 
            +
              def passing_test_with_metadata
         | 
| 88 | 
            +
                test = Minitest::Test.new(:woot)
         | 
| 89 | 
            +
                test.metadata[:meta] = :data
         | 
| 90 | 
            +
                @pt ||= Minitest::Result.from test
         | 
| 91 | 
            +
              end
         | 
| 92 | 
            +
             | 
| 73 93 | 
             
              def skip_test
         | 
| 74 94 | 
             
                unless defined? @st then
         | 
| 75 95 | 
             
                  @st = Minitest::Test.new(:woot)
         | 
| @@ -86,7 +106,25 @@ class TestMinitestReporter < MetaMetaMetaTestCase | |
| 86 106 | 
             
              def test_to_s
         | 
| 87 107 | 
             
                r.record passing_test
         | 
| 88 108 | 
             
                r.record fail_test
         | 
| 89 | 
            -
                assert_match "woot", r. | 
| 109 | 
            +
                assert_match "woot", r.to_s
         | 
| 110 | 
            +
              end
         | 
| 111 | 
            +
             | 
| 112 | 
            +
              def test_options_skip_F
         | 
| 113 | 
            +
                r.options[:skip] = "F"
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                r.record passing_test
         | 
| 116 | 
            +
                r.record fail_test
         | 
| 117 | 
            +
             | 
| 118 | 
            +
                refute_match "woot", r.to_s
         | 
| 119 | 
            +
              end
         | 
| 120 | 
            +
             | 
| 121 | 
            +
              def test_options_skip_E
         | 
| 122 | 
            +
                r.options[:skip] = "E"
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                r.record passing_test
         | 
| 125 | 
            +
                r.record error_test
         | 
| 126 | 
            +
             | 
| 127 | 
            +
                refute_match "RuntimeError: no", r.to_s
         | 
| 90 128 | 
             
              end
         | 
| 91 129 |  | 
| 92 130 | 
             
              def test_passed_eh_empty
         | 
| @@ -126,7 +164,7 @@ class TestMinitestReporter < MetaMetaMetaTestCase | |
| 126 164 | 
             
              end
         | 
| 127 165 |  | 
| 128 166 | 
             
              def test_passed_eh_skipped_verbose
         | 
| 129 | 
            -
                r. | 
| 167 | 
            +
                r.options[:verbose] = true
         | 
| 130 168 |  | 
| 131 169 | 
             
                r.start
         | 
| 132 170 | 
             
                r.results << skip_test
         | 
| @@ -153,6 +191,29 @@ class TestMinitestReporter < MetaMetaMetaTestCase | |
| 153 191 | 
             
                assert_equal 0, r.assertions
         | 
| 154 192 | 
             
              end
         | 
| 155 193 |  | 
| 194 | 
            +
              def test_record_pass_with_metadata
         | 
| 195 | 
            +
                reporter = self.r
         | 
| 196 | 
            +
             | 
| 197 | 
            +
                def reporter.metadata
         | 
| 198 | 
            +
                  @metadata
         | 
| 199 | 
            +
                end
         | 
| 200 | 
            +
             | 
| 201 | 
            +
                def reporter.record result
         | 
| 202 | 
            +
                  super
         | 
| 203 | 
            +
                  @metadata = result.metadata if result.metadata?
         | 
| 204 | 
            +
                end
         | 
| 205 | 
            +
             | 
| 206 | 
            +
                r.record passing_test_with_metadata
         | 
| 207 | 
            +
             | 
| 208 | 
            +
                exp = { :meta => :data }
         | 
| 209 | 
            +
                assert_equal exp, reporter.metadata
         | 
| 210 | 
            +
             | 
| 211 | 
            +
                assert_equal ".", io.string
         | 
| 212 | 
            +
                assert_empty r.results
         | 
| 213 | 
            +
                assert_equal 1, r.count
         | 
| 214 | 
            +
                assert_equal 0, r.assertions
         | 
| 215 | 
            +
              end
         | 
| 216 | 
            +
             | 
| 156 217 | 
             
              def test_record_fail
         | 
| 157 218 | 
             
                fail_test = self.fail_test
         | 
| 158 219 | 
             
                r.record fail_test
         | 
| @@ -263,8 +324,44 @@ class TestMinitestReporter < MetaMetaMetaTestCase | |
| 263 324 | 
             
                    1) Error:
         | 
| 264 325 | 
             
                  Minitest::Test#woot:
         | 
| 265 326 | 
             
                  RuntimeError: no
         | 
| 266 | 
            -
                      FILE:LINE:in  | 
| 267 | 
            -
                      FILE:LINE:in  | 
| 327 | 
            +
                      FILE:LINE:in 'error_test'
         | 
| 328 | 
            +
                      FILE:LINE:in 'test_report_error'
         | 
| 329 | 
            +
             | 
| 330 | 
            +
                  1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
         | 
| 331 | 
            +
                EOM
         | 
| 332 | 
            +
             | 
| 333 | 
            +
                assert_equal exp, normalize_output(io.string)
         | 
| 334 | 
            +
              end
         | 
| 335 | 
            +
             | 
| 336 | 
            +
              def test_report_error__sse
         | 
| 337 | 
            +
                r.start
         | 
| 338 | 
            +
                r.record system_stack_error_test
         | 
| 339 | 
            +
                r.report
         | 
| 340 | 
            +
             | 
| 341 | 
            +
                exp = clean <<-EOM
         | 
| 342 | 
            +
                  Run options:
         | 
| 343 | 
            +
             | 
| 344 | 
            +
                  # Running:
         | 
| 345 | 
            +
             | 
| 346 | 
            +
                  E
         | 
| 347 | 
            +
             | 
| 348 | 
            +
                  Finished in 0.00
         | 
| 349 | 
            +
             | 
| 350 | 
            +
                    1) Error:
         | 
| 351 | 
            +
                  Minitest::Test#woot:
         | 
| 352 | 
            +
                  SystemStackError: 274 -> 12
         | 
| 353 | 
            +
                      a
         | 
| 354 | 
            +
                      b
         | 
| 355 | 
            +
                      c
         | 
| 356 | 
            +
                       +->> 67 cycles of 4 lines:
         | 
| 357 | 
            +
                       | aa
         | 
| 358 | 
            +
                       | ab
         | 
| 359 | 
            +
                       | ac
         | 
| 360 | 
            +
                       | ad
         | 
| 361 | 
            +
                       +-<<
         | 
| 362 | 
            +
                      d
         | 
| 363 | 
            +
                      e
         | 
| 364 | 
            +
                      f
         | 
| 268 365 |  | 
| 269 366 | 
             
                  1 runs, 0 assertions, 0 failures, 1 errors, 0 skips
         | 
| 270 367 | 
             
                EOM
         | 
| @@ -296,4 +393,48 @@ class TestMinitestReporter < MetaMetaMetaTestCase | |
| 296 393 |  | 
| 297 394 | 
             
                assert_equal exp, normalize_output(io.string)
         | 
| 298 395 | 
             
              end
         | 
| 396 | 
            +
             | 
| 397 | 
            +
              def test_report_failure_uses_backtrace_filter
         | 
| 398 | 
            +
                filter = Minitest::BacktraceFilter.new
         | 
| 399 | 
            +
                def filter.filter _bt
         | 
| 400 | 
            +
                  ["foo.rb:123:in 'foo'"]
         | 
| 401 | 
            +
                end
         | 
| 402 | 
            +
             | 
| 403 | 
            +
                with_backtrace_filter filter do
         | 
| 404 | 
            +
                  r.start
         | 
| 405 | 
            +
                  r.record fail_test
         | 
| 406 | 
            +
                  r.report
         | 
| 407 | 
            +
                end
         | 
| 408 | 
            +
             | 
| 409 | 
            +
                exp = "Minitest::Test#woot [foo.rb:123]"
         | 
| 410 | 
            +
             | 
| 411 | 
            +
                assert_includes io.string, exp
         | 
| 412 | 
            +
              end
         | 
| 413 | 
            +
             | 
| 414 | 
            +
              def test_report_failure_uses_backtrace_filter_complex_sorbet
         | 
| 415 | 
            +
                backtrace = <<~EOBT
         | 
| 416 | 
            +
                  /Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/assertions.rb:183:in 'assert'
         | 
| 417 | 
            +
                  example_test.rb:9:in 'assert_false'
         | 
| 418 | 
            +
                  /Users/user/.gem/ruby/3.2.2/gems/sorbet-runtime-0.5.11068/lib/types/private/methods/call_validation.rb:256:in 'bind_call'
         | 
| 419 | 
            +
                  /Users/user/.gem/ruby/3.2.2/gems/sorbet-runtime-0.5.11068/lib/types/private/methods/call_validation.rb:256:in 'validate_call'
         | 
| 420 | 
            +
                  /Users/user/.gem/ruby/3.2.2/gems/sorbet-runtime-0.5.11068/lib/types/private/methods/_methods.rb:275:in 'block in _on_method_added'
         | 
| 421 | 
            +
                  example_test.rb:25:in 'test_something'
         | 
| 422 | 
            +
                  /Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/test.rb:94:in 'block (3 levels) in run'
         | 
| 423 | 
            +
                  /Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/test.rb:191:in 'capture_exceptions'
         | 
| 424 | 
            +
                  /Users/user/.gem/ruby/3.2.2/gems/minitest-5.20.0/lib/minitest/test.rb:89:in 'block (2 levels) in run'
         | 
| 425 | 
            +
                  ... so many lines ...
         | 
| 426 | 
            +
                EOBT
         | 
| 427 | 
            +
             | 
| 428 | 
            +
                filter = Minitest::BacktraceFilter.new %r%lib/minitest|gems/sorbet%
         | 
| 429 | 
            +
             | 
| 430 | 
            +
                with_backtrace_filter filter do
         | 
| 431 | 
            +
                  begin
         | 
| 432 | 
            +
                    assert_equal 1, 2
         | 
| 433 | 
            +
                  rescue Minitest::Assertion => e
         | 
| 434 | 
            +
                    e.set_backtrace backtrace.lines.map(&:chomp)
         | 
| 435 | 
            +
             | 
| 436 | 
            +
                    assert_match "example_test.rb:25", e.location
         | 
| 437 | 
            +
                  end
         | 
| 438 | 
            +
                end
         | 
| 439 | 
            +
              end
         | 
| 299 440 | 
             
            end
         |