Cucumber: Why rake features needs to call db:test:prepare?

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 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”?

On Wed, Nov 5, 2008 at 12:16 AM, Fernando P. [email protected]
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.

Vanilla Rails test:* tasks do the same, as do the rspec:* tasks.
db:test:prepare is a shortcut for running all the migrations from the
first to the last.

If you write a functional Test::Unit test and run rake
test:functionals - do you still have problems? If so - this is likely
not related to Cucumber.

Fernando P. wrote:

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:
Cucumber::Rails.use_transactional_fixtures

If you want to place data in your DB before cucumber is ran you could
consider Zach’s suggestion here:
http://www.continuousthinking.com/2008/7/17/using-seed-data-with-rspec-stories

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.)

-Ben

On Tue, Nov 4, 2008 at 3:25 PM, aslak hellesoy
[email protected]wrote:

db:test:prepare is a shortcut for running all the migrations from the
first to the last.

Not quite. db:test:prepare just copies the schema from the development
database to the test database. It aborts if there are any pending
migrations, but it doesn’t actually run any. That’s why any data
population
in a migration does not get done in the test db.

///ark