Merge pull request #22833 from sivagollapalli/test_runner_with_multiple_lines

Running tests with multiple line numbers
This commit is contained in:
Kasper Timm Hansen 2016-01-10 18:25:54 +01:00
commit efa445c7b5
3 changed files with 87 additions and 4 deletions

View File

@ -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

View File

@ -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

View File

@ -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'