Merge pull request #47031 from p8/railties/test-command-descriptions

Show all test command descriptions when running `rails -h`
This commit is contained in:
Jonathan Hefner 2023-01-31 16:37:28 -06:00 committed by GitHub
commit d7d93faacf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 6 deletions

View File

@ -36,27 +36,47 @@ module Rails
end
# Define Thor tasks to avoid going through Rake and booting twice when using bin/rails test:*
Rails::TestUnit::Runner::TEST_FOLDERS.each do |name|
desc name, "Run tests in test/#{name}"
define_method(name) do |*|
args.prepend("test/#{name}")
perform
end
end
desc "test:all", "Runs all tests, including system tests", hide: true
desc "all", "Run all tests, including system tests"
def all(*)
@force_prepare = true
args.prepend("test/**/*_test.rb")
perform
end
desc "functionals", "Run tests in test/controllers, test/mailers, and test/functional"
def functionals(*)
@force_prepare = true
args.prepend("test/controllers")
args.prepend("test/mailers")
args.prepend("test/functional")
perform
end
desc "units", "Run tests in test/models, test/helpers, and test/unit"
def units(*)
@force_prepare = true
args.prepend("test/models")
args.prepend("test/helpers")
args.prepend("test/unit")
perform
end
desc "system", "Run system tests only"
def system(*)
@force_prepare = true
args.prepend("test/system")
perform
end
desc "generators", "Run tests in test/lib/generators"
def generators(*)
args.prepend("test/lib/generators")
perform

View File

@ -6,7 +6,7 @@ require "rails/test_unit/runner"
task default: :test
desc "Runs all tests in test folder except system ones"
desc "Run all tests in test folder except system ones"
task :test do
if ENV.key?("TEST")
Rails::TestUnit::Runner.rake_run([ENV["TEST"]])
@ -23,7 +23,7 @@ namespace :test do
task run: %w[test]
desc "Run tests quickly, but also reset db"
desc "Reset the database and run `bin/rails test`"
task :db do
success = system({ "RAILS_ENV" => ENV.fetch("RAILS_ENV", "test") }, "rake", "db:test:prepare", "test")
success || exit(false)
@ -35,7 +35,6 @@ namespace :test do
end
end
desc "Runs all tests, including system tests"
task all: "test:prepare" do
Rails::TestUnit::Runner.rake_run(["test/**/*_test.rb"])
end
@ -52,7 +51,6 @@ namespace :test do
Rails::TestUnit::Runner.rake_run(["test/controllers", "test/mailers", "test/functional"])
end
desc "Run system tests only"
task system: "test:prepare" do
Rails::TestUnit::Runner.rake_run(["test/system"])
end

View File

@ -19,6 +19,7 @@ class HelpTest < ActiveSupport::TestCase
assert_match " generate Generate new code (short-cut alias: \"g\")", output
assert_match "In addition to those commands", output
assert_match(/^about(\s+)List versions of all Rails frameworks/, output)
assert_match(/^test:models(\s+)Run tests in test\/models/, output)
assert_match(/^routes(\s+)Lists all the defined routes/, output)
assert_no_match(/^generate/, output)
assert_no_match(/^console/, output)