[英]How can I insert logs just in test environment in Rails?
I want to put some code ONLY in test environment, for example insert a line of log: 我只想在测试环境中放置一些代码,例如插入一行日志:
puts "Something in TEST"
What's the best way to do it? 最好的方法是什么?
Before Rails 2.x, the best way to get the current environment was using RAILS_ENV
. 在Rails 2.x之前,获取当前环境的最佳方法是使用
RAILS_ENV
。 Rails 2.x or later, Rails introduced the Rails
module with method Rails.env
. 在Rails 2.x或更高版本中,Rails通过
Rails.env
方法引入了Rails
模块。 So you can use 所以你可以使用
Before 2.x:
if RAILS_ENV == 'test'
在2.x之前:
if RAILS_ENV == 'test'
After 2.x:
if Rails.env.test?
在2.x之后:
if Rails.env.test?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.