Order of tests matters?

I have a problem with tests. I always thought that the order of tests
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
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
for the things table has an entry for a thing with id = 1. The destroy
destroys Thing with id = 1 with Thing.destroy(1). The edit test tries to
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
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
and teardown?

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
any effect on whether the test passes or fails - should it?

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

  1. Error:
    ActiveRecord::RecordNotFound: Couldn’t find Person with ID=1

When I comment out the test_delete method, the scaffold-generated tests
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.


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


Thanks Kenny. I knew about the transactional fixtures, but had

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs