[rspec-users] NullDb makes rake spec take (much) longer

Matt Wynne matt at mattwynne.net
Mon Jan 12 09:09:33 EST 2009

Hi all,

We did a spike last week to de-couple our view and controller tests  
from the database, using NullDb. It didn't go too well. I realise that  
this plugin isn't part of RSpec, but I thought others on this list  
might have experiences to share.

Here's a summary of my colleague's investigations:

> I installed the plugin from http://github.com/jakehow/nulldb/tree/master
> Changed spec/spec_helper to set
> "ActiveRecord::Base.establish_connection(:adapter => :nulldb)" by
> default.
> The specs that complained of the lack of db, I included a before(all)
> that changed the connection to the test database (include
> NeedsDatabase - copied from Ben Mabey's Functional module)
> By default, I also included the db for all models (config.include
> NeedsDatabase, :type => :model)
> Running spec spec/views with or without nulldb takes about the same
> time (a couple of seconds less with nulldb). However, running "rake
> spec" with nulldb takes 10 times longer!!
> Another weird thing was that three tests failed in the controllers
> (venues and concerts) in a very strange way, even when I included the
> NeedsDatabase in the tests that needed it. The weird bit is, when I
> run: "spec spec/controllers/venues_controller_spec.rb" it doesn't
> fail. But when I run: "spec spec/controllers/users_controller_spec.rb
> spec/controllers/venues_controller_spec.rb" It does fail... That is,
> the user_controller test is influencing the results of the
> venue_controller test!
> The same weird behaviour happens in lib/sk/find
> This made me had to include NeedsDatabase for all lib and controllers
> tests as well.

The barrier for us was the shockingly poor performance of 'rake spec'  
on the view specs - it really means we just can't use it, and actually  
only barely improved the performance of the specs at all.

I was disappointed that the view specs didn't get any faster. My guess  
is that stub_model is the problem - as it has to do quite a bit of  
work to set up the attributes on the models.

So, can anyone tell us what we might have been doing wrong? Or did I  
just have unrealistic expectations of how this might help?

Matt Wynne

More information about the rspec-users mailing list