I wrote a code that needs to be run only in production environment. In my spec/test file, when testing this code, I have to change the ENV variable to 'production' so the code works.
The code:
do_something if Rails.env.production?
Spec:
context "some context" do
before { Rails.env = 'production' }
# test something
end
My question is: there is a problems with this approache? Other option is to change the code to run when in 'production' OR 'test' environment. Is this "better" in some way? I feel that I should not change the environment in the middle of a test but don't know if this is right and why.
Aucun commentaire:
Enregistrer un commentaire