aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorSiva Gollapalli <siva@joshsoftware.com>2015-12-29 22:57:27 +0530
committerSiva Gollapalli <siva@joshsoftware.com>2016-01-10 22:37:01 +0530
commit78b5a01252bccdb326f94e6fd293f1454596c1f8 (patch)
tree6c6457323756e5749b2bdffbe10c87b1d2486379 /railties
parent78edeb33346e13ab33a62d2a6b553aabf5b3186a (diff)
downloadrails-78b5a01252bccdb326f94e6fd293f1454596c1f8.tar.gz
rails-78b5a01252bccdb326f94e6fd293f1454596c1f8.tar.bz2
rails-78b5a01252bccdb326f94e6fd293f1454596c1f8.zip
Added multiple line filters support for test runner
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/test_unit/line_filtering.rb11
-rw-r--r--railties/lib/rails/test_unit/test_requirer.rb2
-rw-r--r--railties/test/application/test_runner_test.rb78
3 files changed, 87 insertions, 4 deletions
diff --git a/railties/lib/rails/test_unit/line_filtering.rb b/railties/lib/rails/test_unit/line_filtering.rb
index fb5ff231e4..dab4d3631d 100644
--- a/railties/lib/rails/test_unit/line_filtering.rb
+++ b/railties/lib/rails/test_unit/line_filtering.rb
@@ -30,9 +30,14 @@ module Rails
end
def derive_line_filters(patterns)
- patterns.map do |file_and_line|
- file, line = file_and_line.split(':')
- Filter.new(@runnable, file, line) if file
+ patterns.flat_map do |file_and_line|
+ file, *lines = file_and_line.split(':')
+
+ if lines.empty?
+ Filter.new(@runnable, file, nil) if file
+ else
+ lines.map { |line| Filter.new(@runnable, file, line) }
+ end
end
end
end
diff --git a/railties/lib/rails/test_unit/test_requirer.rb b/railties/lib/rails/test_unit/test_requirer.rb
index 83d2c55ffd..8b9933bed4 100644
--- a/railties/lib/rails/test_unit/test_requirer.rb
+++ b/railties/lib/rails/test_unit/test_requirer.rb
@@ -15,7 +15,7 @@ module Rails
private
def expand_patterns(patterns)
patterns.map do |arg|
- arg = arg.gsub(/:(\d+)?$/, '')
+ arg = arg.gsub(/(:\d*)+?$/, '')
if Dir.exist?(arg)
"#{arg}/**/*_test.rb"
else
diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb
index 868153762d..ae8a73842c 100644
--- a/railties/test/application/test_runner_test.rb
+++ b/railties/test/application/test_runner_test.rb
@@ -294,6 +294,84 @@ module ApplicationTests
end
end
+ def test_more_than_one_line_filter
+ app_file 'test/models/post_test.rb', <<-RUBY
+ require 'test_helper'
+
+ class PostTest < ActiveSupport::TestCase
+ test "first filter" do
+ puts 'PostTest:FirstFilter'
+ assert true
+ end
+
+ test "second filter" do
+ puts 'PostTest:SecondFilter'
+ assert true
+ end
+
+ test "test line filter does not run this" do
+ assert true
+ end
+ end
+ RUBY
+
+ run_test_command('test/models/post_test.rb:4:9').tap do |output|
+ assert_match 'PostTest:FirstFilter', output
+ assert_match 'PostTest:SecondFilter', output
+ assert_match '2 runs, 2 assertions', output
+ end
+ end
+
+ def test_more_than_one_line_filter_with_multiple_files
+ app_file 'test/models/account_test.rb', <<-RUBY
+ require 'test_helper'
+
+ class AccountTest < ActiveSupport::TestCase
+ test "first filter" do
+ puts 'AccountTest:FirstFilter'
+ assert true
+ end
+
+ test "second filter" do
+ puts 'AccountTest:SecondFilter'
+ assert true
+ end
+
+ test "line filter does not run this" do
+ assert true
+ end
+ end
+ RUBY
+
+ app_file 'test/models/post_test.rb', <<-RUBY
+ require 'test_helper'
+
+ class PostTest < ActiveSupport::TestCase
+ test "first filter" do
+ puts 'PostTest:FirstFilter'
+ assert true
+ end
+
+ test "second filter" do
+ puts 'PostTest:SecondFilter'
+ assert true
+ end
+
+ test "line filter does not run this" do
+ assert true
+ end
+ end
+ RUBY
+
+ run_test_command('test/models/account_test.rb:4:9 test/models/post_test:4:9').tap do |output|
+ assert_match 'AccountTest:FirstFilter', output
+ assert_match 'AccountTest:SecondFilter', output
+ assert_match 'PostTest:FirstFilter', output
+ assert_match 'PostTest:SecondFilter', output
+ assert_match '4 runs, 4 assertions', output
+ end
+ end
+
def test_multiple_line_filters
create_test_file :models, 'account'
create_test_file :models, 'post'