[rspec-users] Basic Rspec operation questions
dchelimsky at gmail.com
Wed Oct 8 19:48:19 EDT 2008
On Wed, Oct 8, 2008 at 6:42 PM, Wes Gamble <weyus at att.net> wrote:
> David Chelimsky wrote:
>> On Wed, Oct 8, 2008 at 3:41 PM, Wes Gamble <weyus at att.net> wrote:
>>> Zach Dennis wrote:
>>>> # This file is copied to ~/spec when you run 'ruby script/generate
>>>> # from the project root directory.
>>>> ENV["RAILS_ENV"] = "test"
>>>> require File.expand_path(File.dirname(__FILE__) +
>>>> 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
>>> on what I do. I'm really just trying to figure out how to take advantage
>>> 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
>>> 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
>>> that the one that files can be run successfully using a direct call to it
>>> 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
>>> 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
>>> have to pass RAILS_ENV=test to the "rake" command.
>> What is test.rb?
> config/environments/test.rb - has test specific stuff set in it.
>> 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 this although it is still unclear to me what the state problems
Based on the other thread you started about the environment - it might
be the lack of environments/test.rb being loaded (rather than a state
Make sure every _spec.rb file requires spec_helper.rb and see if that
solves the problem.
> rspec-users mailing list
> rspec-users at rubyforge.org
More information about the rspec-users