1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Make test file patterns configurable via Environment variables

This makes test file patterns configurable via two environment variables:
`DEFAULT_TEST`, to configure files to test, and `DEFAULT_TEST_EXCLUDE`,
to configure files to exclude from testing.

These values were hardcoded before, which made it difficult to add
new categories of tests that should not be executed by default (e.g:
smoke tests).

It uses environment variables instead of regular Rails config options
because Rails environment is not available when the Runner builds the
list of files to test (unless using Spring). A nicer solution would be
making sure that the Rails environment is always loaded when the runner
starts. This is a first simple step to make these paths configurable for
now

This way at least you could override defaults in `config/boot.rb`:

```ruby
ENV["DEFAULT_TEST_EXCLUDE"] = "test/{dummy,smoke,system}/**/*_test.rb
```

Co-authored-by: Jeremy Daer <jeremydaer@gmail.com>
This commit is contained in:
Jorge Manrubia 2020-05-03 15:08:49 +02:00 committed by Kasper Timm Hansen
parent cea27af06d
commit a0f18e6090
No known key found for this signature in database
GPG key ID: 191153215EDA53D8
3 changed files with 38 additions and 2 deletions

View file

@ -1,3 +1,15 @@
* Make test file patterns configurable via Environment variables
This makes test file patterns configurable via two environment variables:
`DEFAULT_TEST`, to configure files to test, and `DEFAULT_TEST_EXCLUDE`,
to configure files to exclude from testing.
These values were hardcoded before, which made it difficult to add
new categories of tests that should not be executed by default (e.g:
smoke tests).
*Jorge Manrubia*
* No longer include `rake rdoc` task when generating plugins.
To generate docs, use the `rdoc lib` command instead.

View file

@ -44,8 +44,9 @@ module Rails
def load_tests(argv)
patterns = extract_filters(argv)
tests = Rake::FileList[patterns.any? ? patterns : "test/**/*_test.rb"]
tests.exclude("test/system/**/*", "test/dummy/**/*") if patterns.empty?
tests = Rake::FileList[patterns.any? ? patterns : default_test_glob]
tests.exclude(default_test_exclude_glob) if patterns.empty?
tests.to_a.each { |path| require File.expand_path(path) }
end
@ -76,6 +77,14 @@ module Rails
end
end
def default_test_glob
ENV["DEFAULT_TEST"] || "test/**/*_test.rb"
end
def default_test_exclude_glob
ENV["DEFAULT_TEST_EXCLUDE"] || "test/{system,dummy}/**/*_test.rb"
end
def regexp_filter?(arg)
arg.start_with?("/") && arg.end_with?("/")
end

View file

@ -895,6 +895,21 @@ module ApplicationTests
assert_match "1 runs, 1 assertions, 0 failures, 0 errors, 0 skips", output
end
def test_can_exclude_files_from_being_tested_via_default_rails_command_by_setting_DEFAULT_TEST_EXCLUDE_env_var
create_test_file "smoke", "smoke_foo"
switch_env "DEFAULT_TEST_EXCLUDE", "test/smoke/**/*_test.rb" do
assert_match "0 runs, 0 assertions, 0 failures, 0 errors, 0 skips", run_test_command("")
end
end
def test_can_exclude_files_from_being_tested_via_rake_task_by_setting_DEFAULT_TEST_EXCLUDE_env_var
create_test_file "smoke", "smoke_foo"
output = Dir.chdir(app_path) { `DEFAULT_TEST_EXCLUDE="test/smoke/**/*_test.rb" bin/rake test` }
assert_match "0 runs, 0 assertions, 0 failures, 0 errors, 0 skips", output
end
private
def run_test_command(arguments = "test/unit/test_test.rb", **opts)
rails "t", *Shellwords.split(arguments), allow_failure: true, **opts