diff options
author | Kasper Timm Hansen <kaspth@gmail.com> | 2017-02-20 22:20:14 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-20 22:20:14 +0100 |
commit | ff326e745614593530ee64b67ac21bf14e3d41b3 (patch) | |
tree | 8974d1f3a6fd4edde32865e9b37f30056e826c40 /railties/lib/rails/test_unit | |
parent | 507c9970ab2d9e8296d605bc94843e2aa62aa5fd (diff) | |
parent | f38a660a60ecc5e2f0e0f91e07a18344598cff5e (diff) | |
download | rails-ff326e745614593530ee64b67ac21bf14e3d41b3.tar.gz rails-ff326e745614593530ee64b67ac21bf14e3d41b3.tar.bz2 rails-ff326e745614593530ee64b67ac21bf14e3d41b3.zip |
Merge pull request #27941 from y-yagi/prevent_multiple_values_being_set_to_run_via
Prevent multiple values being set to `run_via`
Diffstat (limited to 'railties/lib/rails/test_unit')
-rw-r--r-- | railties/lib/rails/test_unit/minitest_plugin.rb | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/railties/lib/rails/test_unit/minitest_plugin.rb b/railties/lib/rails/test_unit/minitest_plugin.rb index 4df3e7f0f2..7d3da6b529 100644 --- a/railties/lib/rails/test_unit/minitest_plugin.rb +++ b/railties/lib/rails/test_unit/minitest_plugin.rb @@ -59,18 +59,18 @@ module Minitest 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 @@ module Minitest # 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 @@ module Minitest 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 |