diff options
author | Pawan Dubey <git@pawandubey.com> | 2017-07-24 21:53:01 -0400 |
---|---|---|
committer | Kasper Timm Hansen <kaspth@gmail.com> | 2017-07-25 21:00:43 +0200 |
commit | 07d84b7c8db5b85f7521cfc5d2028ed973d9a14b (patch) | |
tree | 1a071303a91ef30d833fd6bf5b0f259472fd92a6 /railties | |
parent | 82200b2541c2e1adee2919aaaccf4bf268c9af99 (diff) | |
download | rails-07d84b7c8db5b85f7521cfc5d2028ed973d9a14b.tar.gz rails-07d84b7c8db5b85f7521cfc5d2028ed973d9a14b.tar.bz2 rails-07d84b7c8db5b85f7521cfc5d2028ed973d9a14b.zip |
Allow bin/rails test task to take absolute paths as arguments
Solves #29923
This regression was caused due to a wrong regex to filter out
paths, introduced in commit 796a1cf0e
The regex was /^\w+\// which did not accept paths with a leading
slash and hence all absolute paths were filtered out.
This change introduces a change in regex which allows for a leading
slash and acts on the matched term accordingly.
While cascading through the case block, the paths are checked for
line number specification, existence of a directory at that path
and if none of those match, then it is considered to be a path to the
file. The regex matchers specified are filtered out via the call
to `Array#compact` since they do not match any of these conditions.
Diffstat (limited to 'railties')
-rw-r--r-- | railties/lib/rails/test_unit/runner.rb | 6 | ||||
-rw-r--r-- | railties/test/application/test_runner_test.rb | 26 |
2 files changed, 29 insertions, 3 deletions
diff --git a/railties/lib/rails/test_unit/runner.rb b/railties/lib/rails/test_unit/runner.rb index 8018ef9d02..33ba2788b4 100644 --- a/railties/lib/rails/test_unit/runner.rb +++ b/railties/lib/rails/test_unit/runner.rb @@ -58,7 +58,7 @@ module Rails private def extract_filters(argv) - argv.select { |arg| arg =~ /^\w+\// }.map do |path| + argv.select { |arg| arg =~ %r{^/?\w+/} }.map do |path| case when path =~ /(:\d+)+$/ file, *lines = path.split(":") @@ -66,11 +66,11 @@ module Rails file when Dir.exist?(path) "#{path}/**/*_test.rb" - else + when path !~ /\/$/ filters << [ path, [] ] path end - end + end.compact end end end 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' |