[rspec-users] Basic Rspec operation questions

David Chelimsky dchelimsky at gmail.com
Wed Oct 8 19:27:47 EDT 2008

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'
> This is exactly what the top of my spec_helper.rb file looks like.
> I have several specs, and the success of running them is different depending
> on what I do.  I'm really just trying to figure out how to take advantage of
> the "rake spec" task.
> I'm on Windows XP.  Rails 2.1.0.  Rspec and Rspec-Rails 1.1.8 gems.  No
> Rspec plugins.  Freshly generate rspec stuff using "ruby script/generate
> rspec"
> 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).
> 3) If I run "rake spec", I get multiple failures, all because the
> config/environments/test.rb file is not loaded (I know this because they
> fail due to the lack of a variable that is set only in test.rb).  The spec
> that failed in #2 works in this case.
> 4) If I run "rake spec RAILS_ENV=test", all _but one_ run without error
> (same error as in #2).
> I draw the following conclustions:
> 1) I only get the color output if I use "rake spec" (not sure why)
> 2) spec loads test.rb by default, but "rake spec" does not and that's why I
> have to pass RAILS_ENV=test to the "rake" command.

What is test.rb?

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.

Do you have a spec/spec.opts file? What does that look like?

> Wes
> rspec 1.1.8 gem
> rspec-rails 1.1.8 gem

More information about the rspec-users mailing list