How to determine that my rails are in a development environment and not in a test environment?

I have code that needs to be run only if the rails application is in the development environment (i.e. the $ rails server), but not in the test environment (i.e. $ rake test).

When i try

if Rails.env.development? dont run me during testing end 

the code runs no matter what environment I am in. I even tried:

 if Rails.env.development? and not Rails.env.test? NO, REALLY, DONT RUN ME DURING TESTING end 

but no love.

What should I do instead?

Peter.

+60
ruby-on-rails environment testing
Mar 18 '13 at 18:18
source share
1 answer

You seem to be calling him right. Perhaps the problem is that the environment is called differently somewhere. Try it in the console:

 [1] pry(main)> Rails.env => "development" [2] pry(main)> Rails.env.development? => true [3] pry(main)> Rails.env.test? => false 

... to make sure the environment is what you think.

+114
Mar 18 '13 at 18:29
source share



All Articles