From e4f0608164b1a25bc3a35a1bd024efe425410758 Mon Sep 17 00:00:00 2001
From: Kasper Timm Hansen <kaspth@gmail.com>
Date: Wed, 3 Feb 2016 21:58:55 +0100
Subject: Fix line filters running tests from multiple runnables.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

`derive_regexp` was written with the assumption that we were run from a
blank slate — that if the filter didn't match we might as well return it
because it was nil.

This isn't the case because minitest calls `run` on every runnable. Which
is any subclass of Minitest::Runnable, such as ActiveSupport::TestCase,
ActionDispatch::IntegrationTest as well as any inheriting from those.

Thus after the first `run` we'd have put in a composite filter in
`options[:filter]` making the next `run` create a linked list when it
failed to match the regexp and put the composite filter as the head.

Every runnable would accumulate more and more of the same filters,
which effectively acted like an expanding whitelist and we ran tests
from other runnables.

Clog the accumulation by returning nil if there's no filter to derive
a regexp from.

Note: we pass a seed in the tests because Minitest shuffles the runnables
to ensure the whitelist is expanded enough that the failure is triggered.
---
 railties/lib/rails/test_unit/line_filtering.rb | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'railties/lib/rails')

diff --git a/railties/lib/rails/test_unit/line_filtering.rb b/railties/lib/rails/test_unit/line_filtering.rb
index dab4d3631d..b7635c71f4 100644
--- a/railties/lib/rails/test_unit/line_filtering.rb
+++ b/railties/lib/rails/test_unit/line_filtering.rb
@@ -26,7 +26,7 @@ module Rails
     private
       def derive_regexp(filter)
         # Regexp filtering copied from Minitest.
-        filter =~ %r%/(.*)/% ? Regexp.new($1) : filter
+        Regexp.new $1 if filter =~ %r%/(.*)/%
       end
 
       def derive_line_filters(patterns)
-- 
cgit v1.2.3