<commit_before>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)
        gem 'minitest'
      else
        require 'minitest'
      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.need_auto_run = ())
        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
        require 'rubysl-test-unit' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
        require 'test/unit/assertions'
      end
      # Turn off test unit's auto runner for those using the gem
      Test::Unit::AutoRunner.need_auto_run = false if defined?(Test::Unit::AutoRunner.need_auto_run = ())
      # Constant aliased to either Minitest or TestUnit, depending on what is
      # loaded.
      Assertions = Test::Unit::Assertions
    end

    # @private<commit_msg>extract `disable_testunit_autorun` method<commit_after>require 'delegate'
require 'active_support'
require 'active_support/concern'
require 'active_support/core_ext/string'

module RSpec
  module Rails
    def self.disable_testunit_autorun
      # `Test::Unit::AutoRunner.need_auto_run=` was introduced to the test-unit
      # gem in version 2.4.9. Previous to this version `Test::Unit.run=` was
      # used. The implementation of test-unit included with Ruby has neither
      # method.
      if defined?(Test::Unit::AutoRunner.need_auto_run = ())
        Test::Unit::AutoRunner.need_auto_run = false
      elsif defined?(Test::Unit.run = ())
        Test::Unit.run = false
      end
    end
    private_class_method :disable_testunit_autorun

    if ::Rails::VERSION::STRING >= '4.1.0'
      if defined?(Kernel.gem)
        gem 'minitest'
      else
        require 'minitest'
      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'
          disable_testunit_autorun
        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
        require 'rubysl-test-unit' if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
        require 'test/unit/assertions'
      end
      # Turn off test unit's auto runner for those using the gem
      disable_testunit_autorun
      # Constant aliased to either Minitest or TestUnit, depending on what is
      # loaded.
      Assertions = Test::Unit::Assertions
    end

    # @private
{'fraction_non_alphanumeric': 0.09329123914759274, 'fraction_numerical': 0.009313338595106552, 'mean_word_length': 2.3506081438392386, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7431730', 'n_tokens_mistral': 1867, 'n_tokens_neox': 1832, 'n_words': 616}