[rspec-users] Basic Rspec operation questions

Wes Gamble weyus at att.net
Wed Oct 8 20:09:13 EDT 2008

David Chelimsky wrote:
> On Wed, Oct 8, 2008 at 3:41 PM, Wes Gamble <weyus at att.net> wrote:
>> Zach,
>> Zach Dennis wrote:
>>> # This file is copied to ~/spec when you run 'ruby script/generate rspec'
>>> # from the project root directory.
>>> ENV["RAILS_ENV"] = "test"
>>> require File.expand_path(File.dirname(__FILE__) +
>>> "/../config/environment")
>>> require 'spec'
>>> require 'spec/rails'
>>> 1) If I run each of my specs separately on the command line using "spec
>>> spec/whatever.rb" they run fine.
>>> 2) If I run "spec spec/*spec.rb", then all _but one_ run without error (note
>>> that the one that files can be run successfully using a direct call to it as
>>> in #1 above).
> As for getting different results if you run files individually, with
> the spec command or with the rake command, that is *usually* a sign
> that there is some state leaking between examples. 'rake spec' and
> 'spec spec' don't load the files in the same order, so the fact that
> you also get different failures from each of those also supports this
> theory in your case.
I agree with your statement, but I can reproduce a case where I can run 
all of my specs using the "spec" command using "spec spec/**/*_spec.rb" 
and one of them will fail.  I can either leave in or remove the 
"--reverse" option in my spec.opts file and get that failure.

But...when I run the spec standalone, using "spec 
spec/<specific_spec_name>.rb" it works fine.

So this is a difference in behavior within the spec command and the only 
difference is that it's one test (SUCCESS) vs. 22 tests (FAIL).  To the 
best of my knowledge, the other tests don't even touch the stuff that is 
under test in the spec that fails, so I can't figure out where the state 
would be leaking. 

(Argh - of course if I reverse the order of the 22 tests, while in both 
cases the individual spec that I'm talking about always fails, if I 
reverse the order, one set is a lot more successful than the other.  Sigh.)



More information about the rspec-users mailing list