I was told that I shouldn't run my rspec specs in a rails_env other than test.
What are the potential problems running specs in production or development? I run specs in both. I usually run the specs in dev unless I'm testing something that uses the asset pipeline. I switch to production for that and spend 15 minutes pre-compiling assets. Are there any advantages to using the test environment over my current methods?
I searched for an answer but nothing explained why I shouldn't use dev or prod.
Running test suites (such as rspec) in a test
environment is intended to isolate resources for security concerns, in particular the integrity of your databases. Tests often corrupt or entirely delete data in your databases.
The same holds true for all resources. By using the test
environment you are able to cut off and mock resources, thereby preventing you tests from corrupting anything.
There are many reasons to use separate environments but fundamentally it is a separation of resources, and in the context of the test
environment it is to enable the validation of your application while ensuring the safety of the production resources and running system.
Let's be clear, especially for nubes that may be reading this post: RAILS_ENV=production
(locally) is not the same as running test "in the production
environment." I know you (OP) know that, but the danger of running tests in the production env warrant this warning.
There are several reasons to only run in the test
env, generally relating to the handling of the DB:
other reasons are along them lines you've surmised already:
The possibilities are too-custom (to your app) to suggest a best-practice... but, needless to say, there are many 'test mode' settings that may need configuration when rails_ENV=test
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With