Merge pull request #27941 from y-yagi/prevent_multiple_values_being_set_to_run_via
Prevent multiple values being set to `run_via`
This commit is contained in:
commit
ff326e7456
@ -2,8 +2,8 @@
|
||||
|
||||
require "minitest"
|
||||
|
||||
if Minitest.respond_to?(:run_via) && !Minitest.run_via[:rails]
|
||||
Minitest.run_via[:ruby] = true
|
||||
if Minitest.respond_to?(:run_via) && !Minitest.run_via.set?
|
||||
Minitest.run_via = :ruby
|
||||
end
|
||||
|
||||
Minitest.autorun
|
||||
|
@ -11,7 +11,7 @@ def help
|
||||
def perform(*)
|
||||
$LOAD_PATH << Rails::Command.root.join("test")
|
||||
|
||||
Minitest.run_via[:rails] = true
|
||||
Minitest.run_via = :rails
|
||||
|
||||
require "active_support/testing/autorun"
|
||||
end
|
||||
|
@ -5,6 +5,6 @@ require 'rails/test_unit/minitest_plugin'
|
||||
|
||||
Rails::TestUnitReporter.executable = 'bin/test'
|
||||
|
||||
Minitest.run_via[:rails] = true
|
||||
Minitest.run_via = :rails
|
||||
|
||||
require "active_support/testing/autorun"
|
||||
|
@ -59,18 +59,18 @@ def self.plugin_rails_options(opts, options)
|
||||
|
||||
options[:color] = true
|
||||
options[:output_inline] = true
|
||||
options[:patterns] = opts.order! unless run_via[:rake]
|
||||
options[:patterns] = opts.order! unless run_via.rake?
|
||||
end
|
||||
|
||||
def self.rake_run(patterns) # :nodoc:
|
||||
run_via[:rake] = true
|
||||
self.run_via = :rake unless run_via.set?
|
||||
::Rails::TestRequirer.require_files(patterns)
|
||||
autorun
|
||||
end
|
||||
|
||||
module RunRespectingRakeTestopts
|
||||
def run(args = [])
|
||||
if run_via[:rake]
|
||||
if run_via.rake?
|
||||
args = Shellwords.split(ENV["TESTOPTS"] || "")
|
||||
end
|
||||
|
||||
@ -87,7 +87,7 @@ def self.plugin_rails_init(options)
|
||||
|
||||
# If run via `ruby` we've been passed the files to run directly, or if run
|
||||
# via `rake` then they have already been eagerly required.
|
||||
unless run_via[:ruby] || run_via[:rake]
|
||||
unless run_via.ruby? || run_via.rake?
|
||||
::Rails::TestRequirer.require_files(options[:patterns])
|
||||
end
|
||||
|
||||
@ -102,7 +102,31 @@ def self.plugin_rails_init(options)
|
||||
reporter << ::Rails::TestUnitReporter.new(options[:io], options)
|
||||
end
|
||||
|
||||
mattr_accessor(:run_via) { Hash.new }
|
||||
def self.run_via=(runner)
|
||||
if run_via.set?
|
||||
raise ArgumentError, "run_via already assigned"
|
||||
else
|
||||
run_via.runner = runner
|
||||
end
|
||||
end
|
||||
|
||||
class RunVia
|
||||
attr_accessor :runner
|
||||
alias set? runner
|
||||
|
||||
# Backwardscompatibility with Rails 5.0 generated plugin test scripts.
|
||||
alias []= runner=
|
||||
|
||||
def ruby?
|
||||
runner == :ruby
|
||||
end
|
||||
|
||||
def rake?
|
||||
runner == :rake
|
||||
end
|
||||
end
|
||||
|
||||
mattr_reader(:run_via) { RunVia.new }
|
||||
end
|
||||
|
||||
# Put Rails as the first plugin minitest initializes so other plugins
|
||||
|
@ -16,5 +16,5 @@ def self.root
|
||||
|
||||
ActiveSupport::TestCase.extend Rails::LineFiltering
|
||||
Rails::TestUnitReporter.executable = "bin/test"
|
||||
Minitest.run_via[:rails] = true
|
||||
Minitest.run_via = :rails
|
||||
require "active_support/testing/autorun"
|
||||
|
Loading…
Reference in New Issue
Block a user