views:

61

answers:

1

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.

A: 

first of all see this thread and see if it can help you.

if you run the rail task rake test:units it will for sure load all fixtures before you run your code. if you are running just the test, and your unit test has no reference to the test_help.rb probably it is not loading the fixtures. You should try to run it through the rake tasks.

Another tip that i give you is that you forget the fixtures and use factories (here i recommend factory_girl). It takes sometime to get used, but it worth. Fixtures are too hard to manage, update and etc.

there is another post explaing little about the concept behind factories.

VP