|
414 | 414 | include Minitest::Assertions |
415 | 415 | include MinitestAssertion |
416 | 416 | rescue LoadError |
417 | | - require 'test/unit/assertions' |
418 | | - include Test::Unit::Assertions |
| 417 | + if RUBY_VERSION >= '2.2.0' |
| 418 | + # Minitest / TestUnit has been removed from ruby core. However, we are |
| 419 | + # on an old Rails version and must load the appropriate gem |
| 420 | + version = ENV.fetch('RAILS_VERSION', '4.2.4') |
| 421 | + if version >= '4.0.0' |
| 422 | + # ActiveSupport 4.0.x has the minitest '~> 4.2' gem as a dependency |
| 423 | + # This gem has no `lib/minitest.rb` file. |
| 424 | + gem 'minitest' if defined?(Kernel.gem) |
| 425 | + require 'minitest/unit' |
| 426 | + Assertions = MiniTest::Assertions |
| 427 | + elsif version >= '3.2.22' |
| 428 | + begin |
| 429 | + # Test::Unit "helpfully" sets up autoload for its `AutoRunner`. |
| 430 | + # While we do not reference it directly, when we load the `TestCase` |
| 431 | + # classes from AS (ActiveSupport), AS kindly references `AutoRunner` |
| 432 | + # for everyone. |
| 433 | + # |
| 434 | + # To handle this we need to pre-emptively load 'test/unit' and make |
| 435 | + # sure the version installed has `AutoRunner` (the 3.x line does to |
| 436 | + # date). If so, we turn the auto runner off. |
| 437 | + require 'test/unit' |
| 438 | + require 'test/unit/assertions' |
| 439 | + rescue LoadError => e |
| 440 | + raise LoadError, <<-ERR.squeeze, e.backtrace |
| 441 | + Ruby 2.2+ has removed test/unit from the core library. Rails |
| 442 | + requires this as a dependency. Please add test-unit gem to your |
| 443 | + Gemfile: `gem 'test-unit', '~> 3.0'` (#{e.message})" |
| 444 | + ERR |
| 445 | + end |
| 446 | + Assertions = Test::Unit::Assertions |
| 447 | + else |
| 448 | + raise LoadError, <<-ERR.squeeze |
| 449 | + Ruby 2.2+ doesn't support this version of Rails #{version} |
| 450 | + ERR |
| 451 | + end |
| 452 | + else |
| 453 | + require 'test/unit/assertions' |
| 454 | + include Test::Unit::Assertions |
| 455 | + end |
419 | 456 | end |
420 | 457 |
|
421 | 458 | require 'active_model/lint' |
|
0 commit comments