Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect that code run by RSpec, Ruby

I would like to be able to know that my code is run under rspec or not. Is this possible?

The reason is that I am loading some error loggers that would be cluttered with deliberate errors (expect{x}.to raise_error) during testing.

I have looked at my ENV variable, and there is no (apparent) signs of a test environment variable.

like image 976
Automatico Avatar asked Jul 24 '14 11:07

Automatico


1 Answers

Add at the beginning of your spec_helper.rb:

ENV['RACK_ENV'] = 'test'

Now you can check in your code whether the RACK_ENV is test or not.

like image 166
Uri Agassi Avatar answered Sep 24 '22 07:09

Uri Agassi