[rspec-users] Cucumber: Why rake features needs to call db:test:prepare?

Ben Mabey ben at benmabey.com
Tue Nov 4 18:33:05 EST 2008

Fernando Perez wrote:
> I am missing something here. Using PostgreSQL, when I remove this line
> from the rake task, I don't see the DB being populated although I do
> invoke create! on some models.
> When I use debug(@some_instance) I see its id gets increased, so there
> is definitely some data already in the DB.
> Why can't I see anything in the DB? Is it possible to mock models so
> that the rake features doesn't have to recreate the test DB each time to
> speed things up?

I believe this can be explained by transactions.  Cucumber wraps it's 
scenarios in ActiveRecord transactions (when in a rails app.)  Most DBs 
by default will not allow you to see data that has been inserted until 
the transaction is committed. You may disable the transactions if you 
wish by commenting out the following line in env.rb:

If you want to place data in your DB before cucumber is ran you could 
consider Zach's suggestion here:

> I am interested in replacing controller specs by webrat features. I
> prefer the webrat's black box approach more for testing controllers and
> views.
> Would it be possible to have autotest trigger "rake features"?
The latest version of cucumber (master from github-- not released yet) 
currently does it.  But that default behavior might change in the future.
  (Reason being is that cucumber features are application level tests 
and may be too slow for the regular red->green->refactor cycle that 
autotest/autospec offers.)


More information about the rspec-users mailing list