I have a problem with tests. I always thought that the order of tests doesn't matter because the fixtures are reloaded before every test method. However, I've just discovered that this isn't true. This is a quote from the "Guide to testing the rails" howto: "... if we had another test method, we wouldn?t have 10 users on the 2nd test because they would be wiped out before being created..." The last part of the quote indicates to me that the fixtures are reloaded before each test method. Scaffold generates same basic tests for you, but these fail for me. My fixture for the things table has an entry for a thing with id = 1. The destroy test destroys Thing with id = 1 with Thing.destroy(1). The edit test tries to find the same object with Thing.find(1) and fails because the object it's looking for has been deleted. But the fixtures should have been reloaded!! I don't get it. I'm using Rails 0.14.3 - perhaps this is only an issue here? Does 1.0 address this issue? Am I just thinking about fixtures incorrectly, and in fact they are never reloaded between test methods? Do I have to do that manually with setup and teardown?
on 2005-12-15 23:48
on 2005-12-15 23:54
I forgot to mention - you can get things to work by just having the destroy test run last. Things are done in alphabetical order, so changing the method name to test_zzzzzz_destroy will make things work. The order of tests should not have any effect on whether the test passes or fails - should it?
on 2005-12-16 12:01
I just ran into this same issue today. Running Rails 1.0: rails test cd test ./script/generate person rake test_functional Gives me three errors of the kind 3) Error: test_update(ServiceDeploymentsControllerTest): ActiveRecord::RecordNotFound: Couldn't find Person with ID=1 When I comment out the test_delete method, the scaffold-generated tests pass. The Person created by test_create remains in the test database as well, even though other tests ran after test_create. Any ideas much appreciated. cheers Gerret
on 2005-12-16 21:06
Gerret A. wrote: > I just ran into this same issue today. Running Rails 1.0: > rails test > cd test > ./script/generate person > rake test_functional > > Gives me three errors of the kind The guide and the docs should really mention this problem. Transactional fixtures were turned on by default in Rails 1.0, to speed up testing. Unfortunately the default MySQL database type (MyISAM) doesn't support transactional fixtures... The quick fix is to put the following line at the top of your test class (inside the class) self.use_transactional_fixtures = false The alternative fix is to change your table type to InnoDB (assuming you're using MySQL) alter table products type=InnoDB; Then you won't have to worry and your tests will be faster... See this article for more details http://www.clarkware.com/cgi/blosxom/2005/10/24#Ra...
on 2005-12-16 21:34
Thanks Kenny. I knew about the transactional fixtures, but had forgotten.