[Rspec-devel] run specs FAST with rails_spec

Daniel Siemssen daniel at dr-siemssen.de
Thu Aug 17 17:16:27 EDT 2006


On 04.07.2006 16:59, aslak hellesoy wrote:
> On 7/4/06, Jay Levitt <lists-rspec at shopwatch.org> wrote:
>   
>> Probably nothing.  The tests completed in no time!  But then I ran them
>> again, and they all failed, with errors like:
>>     
>
> I get a similar error running from the demo app. However it's the
> model classes that aren't found - not the ficture ones:
>
> $ script/rails_spec spec/models/person_spec.rb
>
> 1)
> NameError in 'The Person model should find an existing person'
> uninitialized constant Person
>
> etc.....
>
>   
>> FixtureClassNotFound in 'The BBB receipt can handle adding the bunny
>> slippers'
>> The class "Receipt" was not found.
>> /usr/lib/ruby/gems/1.8/gems/activerecord-1.14.2/lib/active_record/fixtures.rb:403:in
>> `find'
>> ./spec/models/receipt_spec.rb:68:in `setup'
>> script/rails_spec_runner:25:in `run'
>> /usr/lib/ruby/1.8/drb/drb.rb:1552:in `perform_without_block'
>> /usr/lib/ruby/1.8/drb/drb.rb:1512:in `perform'
>> /usr/lib/ruby/1.8/drb/drb.rb:1586:in `main_loop'
>> /usr/lib/ruby/1.8/drb/drb.rb:1582:in `main_loop'
>> /usr/lib/ruby/1.8/drb/drb.rb:1578:in `main_loop'
>> /usr/lib/ruby/1.8/drb/drb.rb:1427:in `run'
>> /usr/lib/ruby/1.8/drb/drb.rb:1424:in `run'
>> /usr/lib/ruby/1.8/drb/drb.rb:1344:in `initialize'
>> /usr/lib/ruby/1.8/drb/drb.rb:1624:in `start_service'
>> script/rails_spec_runner:46
>>
>> Finished in 0.341 seconds
>>
>> 32 specifications, 32 failures
>>
>> Did I miss a step, or is this a bug with rails_spec_runner's handling of
>> fixtures?
>>
>>     
>
> This is definitely a bug, and it's not fixture specific. Nothing works
> on a second run.
> I don't know what's causing this yet.
>
> And it needs to get fixed!
>
> Aslak
>   
>
The models fail to load in the second run because rails can't reload the 
models after Dispatcher.reset_application! in test mode. Why is rails 
doing that? Because config.cache_classes = true by default in test mode 
and the initialize_dependency_mechanism in Rails::Initializer sets the 
Dependencies.mechanism depending on the value of config.cache_classes. 
Thus Dependencies.mechanism = :load is reset to :require after the first 
call of Dispatcher.reset_application! and models won't get loaded 
anymore. All you have to do is put a Dependencies.mechanism = :load 
before the "Dispatcher.reset_application!"-line or set cache_classes = 
false.

Daniel


More information about the Rspec-devel mailing list