提交 4a77213e 编写于 作者: R Robin Dupret

Avoid running system tests by default

These tests may be expansive so let's only allow users to run them
through `bin/rails test:system` or by passing a path to the `test`
command.

The same applies for `bin/rake test`.

Refs #28109.
上级 b1459fce
...@@ -730,6 +730,9 @@ Run the system tests. ...@@ -730,6 +730,9 @@ Run the system tests.
bin/rails test:system bin/rails test:system
``` ```
NOTE: By default, running `bin/rails test` won't run your system tests.
Make sure to run `bin/rails test:system` to actually run them.
#### Creating articles system test #### Creating articles system test
Now let's test the flow for creating a new article in our blog. Now let's test the flow for creating a new article in our blog.
......
* Avoid running system tests by default with the `bin/rails test`
and `bin/rake test` commands since they may be expansive.
*Robin Dupret* (#28286)
* Improve encryption for encrypted secrets. * Improve encryption for encrypted secrets.
Switch to aes-128-gcm authenticated encryption. Also generate a random Switch to aes-128-gcm authenticated encryption. Also generate a random
......
...@@ -62,9 +62,9 @@ def self.plugin_rails_options(opts, options) ...@@ -62,9 +62,9 @@ def self.plugin_rails_options(opts, options)
options[:patterns] = opts.order! unless run_via.rake? options[:patterns] = opts.order! unless run_via.rake?
end end
def self.rake_run(patterns) # :nodoc: def self.rake_run(patterns, exclude_patterns = []) # :nodoc:
self.run_via = :rake unless run_via.set? self.run_via = :rake unless run_via.set?
::Rails::TestRequirer.require_files(patterns) ::Rails::TestRequirer.require_files(patterns, exclude_patterns)
autorun autorun
end end
...@@ -88,7 +88,13 @@ def self.plugin_rails_init(options) ...@@ -88,7 +88,13 @@ def self.plugin_rails_init(options)
# If run via `ruby` we've been passed the files to run directly, or if run # If run via `ruby` we've been passed the files to run directly, or if run
# via `rake` then they have already been eagerly required. # via `rake` then they have already been eagerly required.
unless run_via.ruby? || run_via.rake? unless run_via.ruby? || run_via.rake?
::Rails::TestRequirer.require_files(options[:patterns]) # If there are no given patterns, we can assume that the user
# simply runs the `bin/rails test` command without extra arguments.
if options[:patterns].empty?
::Rails::TestRequirer.require_files(options[:patterns], ["test/system/**/*"])
else
::Rails::TestRequirer.require_files(options[:patterns])
end
end end
unless options[:full_backtrace] || ENV["BACKTRACE"] unless options[:full_backtrace] || ENV["BACKTRACE"]
......
...@@ -4,10 +4,13 @@ ...@@ -4,10 +4,13 @@
module Rails module Rails
class TestRequirer # :nodoc: class TestRequirer # :nodoc:
class << self class << self
def require_files(patterns) def require_files(patterns, exclude_patterns = [])
patterns = expand_patterns(patterns) patterns = expand_patterns(patterns)
Rake::FileList[patterns.compact.presence || "test/**/*_test.rb"].to_a.each do |file| file_list = Rake::FileList[patterns.compact.presence || "test/**/*_test.rb"]
file_list.exclude(exclude_patterns)
file_list.to_a.each do |file|
require File.expand_path(file) require File.expand_path(file)
end end
end end
......
...@@ -4,15 +4,15 @@ require "rails/test_unit/minitest_plugin" ...@@ -4,15 +4,15 @@ require "rails/test_unit/minitest_plugin"
task default: :test task default: :test
desc "Runs all tests in test folder" desc "Runs all tests in test folder except system ones"
task :test do task :test do
$: << "test" $: << "test"
pattern = if ENV.key?("TEST")
ENV["TEST"] if ENV.key?("TEST")
Minitest.rake_run([ENV["TEST"]])
else else
"test" Minitest.rake_run(["test"], ["test/system/**/*"])
end end
Minitest.rake_run([pattern])
end end
namespace :test do namespace :test do
......
...@@ -604,6 +604,52 @@ def reset_sessions! ...@@ -604,6 +604,52 @@ def reset_sessions!
end end
end end
def test_system_tests_are_not_run_with_the_default_test_command
app_file "test/system/dummy_test.rb", <<-RUBY
require "application_system_test_case"
class DummyTest < ApplicationSystemTestCase
test "something" do
assert true
end
end
RUBY
run_test_command("").tap do |output|
assert_match "0 runs, 0 assertions, 0 failures, 0 errors, 0 skips", output
end
end
def test_system_tests_are_not_run_through_rake_test
app_file "test/system/dummy_test.rb", <<-RUBY
require "application_system_test_case"
class DummyTest < ApplicationSystemTestCase
test "something" do
assert true
end
end
RUBY
output = Dir.chdir(app_path) { `bin/rake test` }
assert_match "0 runs, 0 assertions, 0 failures, 0 errors, 0 skips", output
end
def test_system_tests_are_run_through_rake_test_when_given_in_TEST
app_file "test/system/dummy_test.rb", <<-RUBY
require "application_system_test_case"
class DummyTest < ApplicationSystemTestCase
test "something" do
assert true
end
end
RUBY
output = Dir.chdir(app_path) { `bin/rake test TEST=test/system/dummy_test.rb` }
assert_match "1 runs, 1 assertions, 0 failures, 0 errors, 0 skips", output
end
private private
def run_test_command(arguments = "test/unit/test_test.rb") def run_test_command(arguments = "test/unit/test_test.rb")
Dir.chdir(app_path) { `bin/rails t #{arguments}` } Dir.chdir(app_path) { `bin/rails t #{arguments}` }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册