Michael Hamann
2007-Aug-08 17:41 UTC
[rspec-users] Transactional fixtures not working as expected
Hi! 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 I am using edge rails with the current RSpec and RSpec on Rails - plugins. I first used sqlite3, then mysql to verify that it is no sqlite3 bug, but the errors occur also when I am using Mysql. Transactional fixtures are enabled, instantiated fixtures are disabled. My question is now: Is this behavior really desired? Because now my model-tests alone pass, and all the other tests too, but when the view-tests are run before the model-tests, they don''t pass. So the passing of the tests becomes unpredictable. And I think I will have additional fixtures for models I don''t use fixtures at the moment and this will make other tests fail, too. So should I really write tests that work with any fixtures loaded? And why is there a possibility to load fixtures in one description also this loads the fixtures actually globally? What can I do against this behavior? Is this a bug? Greetings Michael Hamann
Tilmann Singer
2007-Aug-10 15:15 UTC
[rspec-users] Transactional fixtures not working as expected
* 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.htmlA 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 Post.delete_all end This is certainly not ideal, but maybe a necessary workaround for you as long as fixtures work the way they do now. greetings, Til