Rails 2.3.5 table populated by fixtures at end of test run rather than at start

Posted by rlandster on Stack Overflow See other posts from Stack Overflow or by rlandster
Published on 2010-05-06T17:16:24Z Indexed on 2010/05/06 17:18 UTC
Read the original article Hit count: 228

I start with a test database containing the schema but with no data in the tables. I run a test like so

cd test/
ruby unit/directive_test.rb

I get failures indicating that the code found no data in the data tables. However, I look at the tables after running that test and the data is now in the the table. In fact, if I immediately run the test again I get no failures.

So it appears that the fixture is being loaded into the table too late for one of my modules to find it.

  1. When are the fixtures loaded? After or before the app/model/*.rb files are executed?
  2. If it is after the models are executed is there a way to delay the loading?

This issue is also relevant when running rake test:units since that task clears the test data after it finished.

© Stack Overflow or respective owner

Related posts about unit-testing

Related posts about fixtures