[rspec-users] Transactional fixtures not working as expected

Tilmann Singer tils-rspec at tils.net
Fri Aug 10 11:15:49 EDT 2007

* Michael Hamann <rails at content-space.de> [20070808 19:46]:
> I am quite new to BDD and I just wrote my first tests. Suddenly I
> received unexpected results because in a model test I load only
> users-fixtures but when the views-fixtures in which I load the
> posts-fixtures, are run before this model-test, the posts-fixtures are
> loaded too. I test for example if there is one record in the posts-table
> after creating one post. But when there are fixtures loaded, this does
> not work of course. A similar issue was discussed here already in
> October 2006, but there was no real result:
> http://rubyforge.org/pipermail/rspec-users/2006-October/000088.html

A fixture declaration in a context only guarantees that the
explicitely declared fixtures are loaded and correspond to their
fixture data in the .yml file - it does not guarantee that the
non-declared fixtures are not loaded, nor does the absence of a
fixture declaration guarantee that no fixtures are loaded.

If a specific context depends on empty tables that may contain fixture
data from previous runs the only way I can think of to guarantee that
state is to add something like this in the context:

before(:each) do

This is certainly not ideal, but maybe a necessary workaround for you
as long as fixtures work the way they do now.

greetings, Til

More information about the rspec-users mailing list