开发者

Check on TEST mode during runtime

开发者 https://www.devze.com 2022-12-17 03:29 出处:网络
My web application writes some kind of log during runtime. I don\'t want to write this log when running my test suite using cucumber.

My web application writes some kind of log during runtime. I don't want to write this log when running my test suite using cucumber.

So, how can I check my current runtime environment (TEST, DEV or PROD)?

I'm looking for the C equivalent to i.e. :

#ifdef DEBUG

   // just run in debug mode

#endif

Thank you very much for helping me开发者_开发百科 on this.


Try this for the if condition:

if ENV['RAILS_ENV'] == "test"
    # Insert Code Here
end

(replace 'test' with 'development' or 'production' as needed)


You can do following

Rails.env.test?
Rails.env.development?
Rails.env.production?

This will return true or false according to the runtime environment

0

精彩评论

暂无评论...
验证码 换一张
取 消