From 29f0fbd5db643b885665e4a14c7de3bf6c0d9c96 Mon Sep 17 00:00:00 2001 From: Kasper Timm Hansen Date: Sun, 25 Sep 2016 20:21:30 +0200 Subject: Revise setting of run_with_rails_extension. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Rails test runner supports three ways to run tests: directly, via rake, or ruby. When Running with Ruby ala `ruby -Itest test/models/post_test.rb` our test file would be evaluated first, requiring `test_helper` and then `active_support/testing/autorun` that would then require the test file (which it hadn't been before) thus reevaluating it. This caused exceptions if using Active Support's declarative syntax. Fix this by shifting around when we set the how we're run to closer mimick the require order. If we're running with `bin/rails test` the test command file is run first and we then set `run_with_rails_extension`, later we hit `active_support/testing/autorun` and do nothing — because we've been run elsewhere. If we at this point haven't set `run_with_rails_extension` we've been running with `ruby` this whole time and thus we set that. We should always trigger `Minitest.autorun` as it doesn't hurt to call it twice. Consolidate the two methods into a single one that better brings out the intent of why they're there. --- activesupport/lib/active_support/testing/autorun.rb | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'activesupport/lib') diff --git a/activesupport/lib/active_support/testing/autorun.rb b/activesupport/lib/active_support/testing/autorun.rb index 898ef209da..2e7b7246aa 100644 --- a/activesupport/lib/active_support/testing/autorun.rb +++ b/activesupport/lib/active_support/testing/autorun.rb @@ -2,11 +2,8 @@ gem "minitest" require "minitest" -if Minitest.respond_to?(:run_with_rails_extension) - unless Minitest.run_with_rails_extension - Minitest.run_with_autorun = true - Minitest.autorun - end -else - Minitest.autorun +if Minitest.respond_to?(:run_with_rails_extension) && !Minitest.run_with_rails_extension + Minitest.run_with_autorun = true end + +Minitest.autorun -- cgit v1.2.3