user5633750
user5633750

Reputation:

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?

Upvotes: 1

Views: 48

Answers (1)

Yang
Yang

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

Related Questions