Skip to content

Commit ffed381

Browse files
committed
extract disable_testunit_autorun method
1 parent 6092959 commit ffed381

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/rspec/rails/adapters.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55

66
module RSpec
77
module Rails
8+
def self.disable_testunit_autorun
9+
# `Test::Unit::AutoRunner.need_auto_run=` was introduced to the test-unit
10+
# gem in version 2.4.9. Previous to this version `Test::Unit.run=` was
11+
# used. The implementation of test-unit included with Ruby has neither
12+
# method.
13+
if defined?(Test::Unit::AutoRunner.need_auto_run = ())
14+
Test::Unit::AutoRunner.need_auto_run = false
15+
elsif defined?(Test::Unit.run = ())
16+
Test::Unit.run = false
17+
end
18+
end
19+
private_class_method :disable_testunit_autorun
20+
821
if ::Rails::VERSION::STRING >= '4.1.0'
922
if defined?(Kernel.gem)
1023
gem 'minitest'
@@ -37,7 +50,7 @@ module Rails
3750
# date). If so, we turn the auto runner off.
3851
require 'test/unit'
3952
require 'test/unit/assertions'
40-
Test::Unit::AutoRunner.need_auto_run = false if defined?(Test::Unit::AutoRunner.need_auto_run = ())
53+
disable_testunit_autorun
4154
rescue LoadError => e
4255
raise LoadError, <<-ERR.squish, e.backtrace
4356
Ruby 2.2+ has removed test/unit from the core library. Rails
@@ -62,7 +75,7 @@ module Rails
6275
require 'test/unit/assertions'
6376
end
6477
# Turn off test unit's auto runner for those using the gem
65-
Test::Unit::AutoRunner.need_auto_run = false if defined?(Test::Unit::AutoRunner.need_auto_run = ())
78+
disable_testunit_autorun
6679
# Constant aliased to either Minitest or TestUnit, depending on what is
6780
# loaded.
6881
Assertions = Test::Unit::Assertions

0 commit comments

Comments
 (0)