Reputation:
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?
Upvotes: 1
Views: 48
Reputation: 1923
Before Rails 2.x, the best way to get the current environment was using RAILS_ENV
. Rails 2.x or later, Rails introduced the Rails
module with method Rails.env
. So you can use
Before 2.x:
if RAILS_ENV == 'test'
After 2.x:
if Rails.env.test?
Upvotes: 1