aboutsummaryrefslogtreecommitdiffstats
path: root/railties
diff options
context:
space:
mode:
authorKasper Timm Hansen <kaspth@gmail.com>2017-07-25 21:01:34 +0200
committerKasper Timm Hansen <kaspth@gmail.com>2017-07-25 21:16:05 +0200
commit5948871e822d5c73286d58fbfc134628cd47d805 (patch)
treeac6be1d25a482c5a747685a799091d10810c3664 /railties
parentea6139101ccaf8be03b536b1293a9f36bc12f2f7 (diff)
parent07d84b7c8db5b85f7521cfc5d2028ed973d9a14b (diff)
downloadrails-5948871e822d5c73286d58fbfc134628cd47d805.tar.gz
rails-5948871e822d5c73286d58fbfc134628cd47d805.tar.bz2
rails-5948871e822d5c73286d58fbfc134628cd47d805.zip
Merge pull request #29926 from pawandubey:fix-test-with-absolute-paths
Diffstat (limited to 'railties')
-rw-r--r--railties/lib/rails/test_unit/runner.rb5
-rw-r--r--railties/test/application/test_runner_test.rb26
2 files changed, 30 insertions, 1 deletions
diff --git a/railties/lib/rails/test_unit/runner.rb b/railties/lib/rails/test_unit/runner.rb
index 8018ef9d02..1f3a248bcb 100644
--- a/railties/lib/rails/test_unit/runner.rb
+++ b/railties/lib/rails/test_unit/runner.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
require "shellwords"
require "method_source"
require "rake/file_list"
@@ -58,7 +60,8 @@ module Rails
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(":")
diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb
index c0027ab9a2..bcd311c461 100644
--- a/railties/test/application/test_runner_test.rb
+++ b/railties/test/application/test_runner_test.rb
@@ -31,12 +31,26 @@ module ApplicationTests
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'
@@ -264,6 +278,18 @@ module ApplicationTests
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'