Skip to content

Commit

Permalink
Merge pull request #29926 from pawandubey:fix-test-with-absolute-paths
Browse files Browse the repository at this point in the history
  • Loading branch information
kaspth committed Jul 25, 2017
1 parent b0206dd commit b1b6839
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
5 changes: 4 additions & 1 deletion railties/lib/rails/test_unit/runner.rb
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "shellwords"
require "method_source"
require "rake/file_list"
Expand Down Expand Up @@ -58,7 +60,8 @@ def compose_filter(runnable, filter)

private
def extract_filters(argv)
argv.select { |arg| arg =~ /^\w+\// }.map do |path|
# Extract absolute and relative paths but skip -n /.*/ regexp filters.
argv.select { |arg| arg =~ %r%^/?\w+/% && !arg.end_with?("/") }.map do |path|
case
when path =~ /(:\d+)+$/
file, *lines = path.split(":")
Expand Down
26 changes: 26 additions & 0 deletions railties/test/application/test_runner_test.rb
Expand Up @@ -31,12 +31,26 @@ def test_run_single_file
assert_match "1 runs, 1 assertions, 0 failures", run_test_command("test/models/foo_test.rb")
end

def test_run_single_file_with_absolute_path
create_test_file :models, "foo"
create_test_file :models, "bar"
assert_match "1 runs, 1 assertions, 0 failures", run_test_command("#{app_path}/test/models/foo_test.rb")
end

def test_run_multiple_files
create_test_file :models, "foo"
create_test_file :models, "bar"
assert_match "2 runs, 2 assertions, 0 failures", run_test_command("test/models/foo_test.rb test/models/bar_test.rb")
end

def test_run_multiple_files_with_absolute_paths
create_test_file :models, "foo"
create_test_file :controllers, "foobar_controller"
create_test_file :models, "bar"

assert_match "2 runs, 2 assertions, 0 failures", run_test_command("#{app_path}/test/models/foo_test.rb #{app_path}/test/controllers/foobar_controller_test.rb")
end

def test_run_file_with_syntax_error
app_file "test/models/error_test.rb", <<-RUBY
require 'test_helper'
Expand Down Expand Up @@ -264,6 +278,18 @@ def test_run_multiple_folders
end
end

def test_run_multiple_folders_with_absolute_paths
create_test_file :models, "account"
create_test_file :controllers, "accounts_controller"
create_test_file :helpers, "foo_helper"

run_test_command("#{app_path}/test/models #{app_path}/test/controllers").tap do |output|
assert_match "AccountTest", output
assert_match "AccountsControllerTest", output
assert_match "2 runs, 2 assertions, 0 failures, 0 errors, 0 skips", output
end
end

def test_run_with_ruby_command
app_file "test/models/post_test.rb", <<-RUBY
require 'test_helper'
Expand Down

0 comments on commit b1b6839

Please sign in to comment.