[rspec-users] Strange behavior with using webrat in requests tests

Mike Gehard mgehard at pivotallabs.com
Tue Jul 6 11:43:45 EDT 2010

Good morning,

I am using Rails3 (beta4) and RSpec2 (beta 15) under RVM and am running into
an interesting issue.

My request tests using webrat seem to think that they are running in the
development Rails environment (I know this because I get all kinds of
entries in the development log) and that is messing with Factory Girl (the
factory_girl_rails gem).

If I run "env" from the OSX command line, I have an entry for RAILS_ENV =

After some poking around, I found the line:
ENV["RAILS_ENV"] ||= 'test'

in the spec_helper.rb file. I figured that this might be why webrat runs in
the development environment since the above line won't do anything if
RAILS_ENV is already set (which it is).

If I remove the "||" from the above line, everything seems to work fine and
webrat now stops putting stuff into the development log and puts stuff into
the test log and the strangeness with factory_girl_rails goes away.

I would like to confirm that removing the "||" from the spec_helper.rb file
isn't going to mess with anything later down the road ro get an explanation
as to why one wouldn't want to always force RAILS_ENV to be equal to "test"
when running specs.


Mike Gehard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20100706/8738f249/attachment-0001.html>

More information about the rspec-users mailing list