Forum: Ruby on Rails Order of tests matters???

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
429e9d8e16b3c6e4ab0c954893e0334a?d=identicon&s=25 Matthew Thill (Guest)
on 2005-12-15 22:48
(Received via mailing list)
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?
429e9d8e16b3c6e4ab0c954893e0334a?d=identicon&s=25 Matthew Thill (Guest)
on 2005-12-15 22:54
(Received via mailing list)
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?
5ceea097a3b29cb6a5da6705926410f4?d=identicon&s=25 Gerret Apelt (Guest)
on 2005-12-16 11:01
(Received via mailing list)
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:
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.

716e752d40f722681b3099c64b68df5c?d=identicon&s=25 Kenny Grant (Guest)
on 2005-12-16 20:06
Gerret Apelt 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
429e9d8e16b3c6e4ab0c954893e0334a?d=identicon&s=25 Matthew Thill (Guest)
on 2005-12-16 20:34
(Received via mailing list)
Thanks Kenny. I knew about the transactional fixtures, but had
This topic is locked and can not be replied to.