Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid running system tests by default #28286

Merged
merged 1 commit into from
Mar 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions guides/source/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,9 @@ Run the system tests.
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

Now let's test the flow for creating a new article in our blog.
Expand Down
5 changes: 5 additions & 0 deletions railties/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
* 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.

Switch to aes-128-gcm authenticated encryption. Also generate a random
Expand Down
12 changes: 9 additions & 3 deletions railties/lib/rails/test_unit/minitest_plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ def self.plugin_rails_options(opts, options)
options[:patterns] = opts.order! unless run_via.rake?
end

def self.rake_run(patterns) # :nodoc:
def self.rake_run(patterns, exclude_patterns = []) # :nodoc:
self.run_via = :rake unless run_via.set?
::Rails::TestRequirer.require_files(patterns)
::Rails::TestRequirer.require_files(patterns, exclude_patterns)
autorun
end

Expand All @@ -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
# via `rake` then they have already been eagerly required.
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

unless options[:full_backtrace] || ENV["BACKTRACE"]
Expand Down
7 changes: 5 additions & 2 deletions railties/lib/rails/test_unit/test_requirer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
module Rails
class TestRequirer # :nodoc:
class << self
def require_files(patterns)
def require_files(patterns, exclude_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)
end
end
Expand Down
10 changes: 5 additions & 5 deletions railties/lib/rails/test_unit/testing.rake
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ require "rails/test_unit/minitest_plugin"

task default: :test

desc "Runs all tests in test folder"
desc "Runs all tests in test folder except system ones"
task :test do
$: << "test"
pattern = if ENV.key?("TEST")
ENV["TEST"]

if ENV.key?("TEST")
Minitest.rake_run([ENV["TEST"]])
else
"test"
Minitest.rake_run(["test"], ["test/system/**/*"])
end
Minitest.rake_run([pattern])
end

namespace :test do
Expand Down
46 changes: 46 additions & 0 deletions railties/test/application/test_runner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,52 @@ def reset_sessions!
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
def run_test_command(arguments = "test/unit/test_test.rb")
Dir.chdir(app_path) { `bin/rails t #{arguments}` }
Expand Down