lib/rspec/rails/adapters.rb in rspec-rails-3.1.0 vs lib/rspec/rails/adapters.rb in rspec-rails-3.2.0

- old
+ new

@@ -1,8 +1,9 @@ require 'delegate' require 'active_support' require 'active_support/concern' +require 'active_support/core_ext/string' module RSpec module Rails if ::Rails::VERSION::STRING >= '4.1.0' if defined?(Kernel.gem) @@ -12,9 +13,47 @@ end require 'minitest/assertions' # Constant aliased to either Minitest or TestUnit, depending on what is # loaded. Assertions = Minitest::Assertions + elsif RUBY_VERSION >= '2.2.0' + # Minitest / TestUnit has been removed from ruby core. However, we are + # on an old Rails version and must load the appropriate gem + if ::Rails::VERSION::STRING >= '4.0.0' + # ActiveSupport 4.0.x has the minitest '~> 4.2' gem as a dependency + # This gem has no `lib/minitest.rb` file. + gem 'minitest' if defined?(Kernel.gem) + require 'minitest/unit' + Assertions = MiniTest::Assertions + elsif ::Rails::VERSION::STRING >= '3.2.21' + # TODO: Change the above check to >= '3.2.22' once it's released + begin + # Test::Unit "helpfully" sets up autoload for its `AutoRunner`. + # While we do not reference it directly, when we load the `TestCase` + # classes from AS (ActiveSupport), AS kindly references `AutoRunner` + # for everyone. + # + # To handle this we need to pre-emptively load 'test/unit' and make + # sure the version installed has `AutoRunner` (the 3.x line does to + # date). If so, we turn the auto runner off. + require 'test/unit' + require 'test/unit/assertions' + Test::Unit::AutoRunner.need_auto_run = false if defined?(Test::Unit::AutoRunner) + rescue LoadError => e + raise LoadError, <<-ERR.squish, e.backtrace + Ruby 2.2+ has removed test/unit from the core library. Rails + requires this as a dependency. Please add test-unit gem to your + Gemfile: `gem 'test-unit', '~> 3.0'` (#{e.message})" + ERR + end + Assertions = Test::Unit::Assertions + else + abort <<-MSG.squish + Ruby 2.2+ is not supported on Rails #{::Rails::VERSION::STRING}. + Check the Rails release notes for the appropriate update with + support. + MSG + end else begin require 'test/unit/assertions' rescue LoadError # work around for Rubinius not having a std std-lib