Skip to content

Ensure bin/rails test command defaults to test` env #403

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

Merged

Conversation

eileencodes
Copy link
Member

bin/rails test was defauling to the development environment because
ENV['RAILS_ENV'] and ENV['RACK_ENV'] are nil and default_rails_env
defaults to the development environment when an environment is not
provided.

This resulted in Spring ignoring even explicitly setting the environment
option when running tests. The environment would get overwritten with
development even when test was set. Tests seemed to run fine, but if
there was a required file or included module the test would not be able
to find those files because the environment was set incorrectly.

Borrowing code from RailsConsole I updated RailsTest to set the
default env to test but take --environment and -e into account
like the other commands.

I added tests to ensure that when not set the environment will default
to test.


Note: I opened a PR instead of pushing because I haven't work with Spring before. This seems like the right change based on the other commands. 😸

end

test 'RailsTest#command sets rails environment from --environment option' do
command = Spring::Commands::RailsConsole.new
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be RailsTest instead of RailsConsole?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops 😓

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed 👍

`bin/rails test` was defauling to the `development` environment because
`ENV['RAILS_ENV']` and `ENV['RACK_ENV']` are nil and `default_rails_env`
defaults to the `development` environment when an environment is not
provided.

This resulted in Spring ignoring even explicitly setting the environment
option when running tests. The environment would get overwritten with
`development` even when `test` was set. Tests seemed to run fine, but if
there was a required file or included module the test would not be able
to find those files because the environment was set incorrectly.

Borrowing code from `RailsConsole` I updated `RailsTest` to set the
default env to `test` but take `--environment` and `-e` into account
like the other commands.

I added tests to ensure that when not set the environment will default
to `test`.
@eileencodes eileencodes force-pushed the fix-environment-settings-on-spring branch from 06b4b9a to 497c1ee Compare April 28, 2015 14:36
@senny
Copy link
Member

senny commented Apr 28, 2015

👍 looks good.

@eileencodes
Copy link
Member Author

wow that took a long time, but woo green! 🍏 📗 💚 ♻️

@senny
Copy link
Member

senny commented Apr 28, 2015

@eileencodes this is the first green build from Travis that I've seen today. 🎉 💚

@rafaelfranca
Copy link
Member

:shipit:

eileencodes added a commit that referenced this pull request Apr 28, 2015
…spring

Ensure `bin/rails test command defaults to `test` env
@eileencodes eileencodes merged commit 93ddd60 into rails:master Apr 28, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants