diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2017-12-06 17:33:16 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2017-12-06 20:40:04 -0800 |
commit | da225c0db640aec1df0920e86c1eb4ca35d82073 (patch) | |
tree | 3b69e271902ff2a32ed83df3e860360d1fe7c191 /railties/lib/rails/test_unit | |
parent | 0ba5615e403e9f44c775633dc2a1275a1e971390 (diff) | |
download | rails-da225c0db640aec1df0920e86c1eb4ca35d82073.tar.gz rails-da225c0db640aec1df0920e86c1eb4ca35d82073.tar.bz2 rails-da225c0db640aec1df0920e86c1eb4ca35d82073.zip |
Fix Rails environment when running tests with Ruby
I frequently run tests with `ruby`, not with a runner like `rake` or
`rails`. When running the test with just `ruby` the `RAILS_ENV`
environment variable did not get set to "test", and this would cause the
tests to fail (and even mutate the development database!)
This commit adds integration tests for running tests with just `ruby`
and ensures the environment gets defaulted to "test". I also added a
test to ensure that passing an environment to `-e` actually works (and
fixed that case too).
An interesting / annoying thing is that Minitest picks up it's plugins
by asking RubyGems for a list of files:
https://github.com/seattlerb/minitest/blob/ca6a71ca901016db09a5ad466b4adea4b52a504a/lib/minitest.rb#L92-L100
This means that RubyGems needs to somehow know about the file before it
can return it to Minitest. Since we are not packaging Rails as a Gem
before running the integration tests on it (duh, why would you do
that?), RubyGems doesn't know about the file, so it can't tell Minitest,
so Minitest doesn't automatically require it. This means I had to
manually require and insert the plugin in our integration test. I've
left comments about that in the test as well.
Ugh.
Diffstat (limited to 'railties/lib/rails/test_unit')
-rw-r--r-- | railties/lib/rails/test_unit/runner.rb | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/railties/lib/rails/test_unit/runner.rb b/railties/lib/rails/test_unit/runner.rb index 5c2f6451e2..45e8472f6a 100644 --- a/railties/lib/rails/test_unit/runner.rb +++ b/railties/lib/rails/test_unit/runner.rb @@ -12,8 +12,11 @@ module Rails class << self def attach_before_load_options(opts) + ENV["RAILS_ENV"] = "test" opts.on("--warnings", "-w", "Run with Ruby warnings enabled") {} - opts.on("--environment", "-e", "Run tests in the ENV environment") {} + opts.on("-e", "--environment ENV", "Run tests in the ENV environment") { |e| + ENV["RAILS_ENV"] = e + } end def parse_options(argv) |