[rspec-users] RSpec-rails 1.2.2: autospec passes but "rake spec" fails

Stephen Eley sfeley at gmail.com
Sun Mar 29 15:18:14 EDT 2009

On Sat, Mar 28, 2009 at 4:49 PM, Bart Zonneveld <zuperinfinite at gmail.com> wrote:
> I very strongly disagree on this one. As it so happens, we've found a bug in
> Passenger regarding uploads, umasks and permissions, which was caused by
> Passenger overwriting the TMP_DIR environment variable. Took us quite a
> while to figure this one out.

Weird.  And a bit unfathomable to me why Passenger would have a need
to set a generic environment variable like that.  I seem to recall
those guys have run into trouble with namespacing before.  It seems
like a different case to me than Rails code setting RAILS_ENV.

> Even more, rake RAILS_ENV=development spec wouldn't work as expected when
> the env gets explicitly set from within a spec helper.

My first question would be, why do you want to do that?  What are you
doing in development mode that needs to be tested against separately
from other modes?

Second, assuming a good answer, why not just alter that line in
spec_helper.rb?  It's not like you have to go and fork the gem to
alter this behavior; configuration settings like this are what
spec_helper.rb is for.  If you're setting your environment on the
command line all the time then you must be clueful enough not to need
the same level of handholding.

But I'll moderate my smartassishness just slightly: while I'm still in
favor of leaving spec_helper.rb with an explicit assignment to 'test',
perhaps a comment may be in order on the lines of:

# This line ensures that RSpec will run in the 'test' environment
# regardless of defaults set by other tools.  If you have reasons to run
# specs in other environments, you can allow this value to be overridden
# by changing the line to:
# ENV['RAILS_ENV'] ||= 'test'

Then everybody who bothers to read spec_helper at least knows about
the issue and can make up their own minds.  And as a side bonus,
really new Rubyists can learn something about the ||= operator.  >8->
(Hey, everyone has a first time for seeing it.  I first noticed it in
the restful_authentication plugin, IIRC, and now I use it all the

Have Fun,
   Steve Eley (sfeley at gmail.com)
   ESCAPE POD - The Science Fiction Podcast Magazine

More information about the rspec-users mailing list