2

I have classes in my Rails project that are 'registered' with attributes read from the database. However, when I run 'rake test', the classes are loaded before the fixtures are created in SQLLite. As a result, the classes are 'registered' with null values, causing my tests to fail.

Manually testing by running my rails server works perfectly fine, so I don't think there is a problem with my code logic. Also, my fixtures are correct.

How can I change the order of loading the fixtures before the classes and models are instantiated.

Neel Vasa
  • 169
  • 1
  • 8
  • I am having this issue when I am trying to upgrade a legacy project from Rails 2.3 to Rails 3.0. Tests work fine if ran independently without Rake, but if tests are run with `rake test TEST=[test_path]` which runs the test three times (with units, functionals and integrations setups) the tests fail on the first run but pass on the latter two. I am using `fixtures :all` in `test_helper` and the test file itself. – vkopio Jul 12 '17 at 09:47
  • Did you find a solution? – Babar Sep 19 '18 at 13:45

1 Answers1

0

rake test loads fixtures if you specify fixtures :all. Run rake test --trace to see what happens behind the scenes. I dont think the fixtures are loaded without mentioning fixtures :all Try to rake db:fixtures:load and see if it raises any error.

mhaseeb
  • 1,739
  • 2
  • 12
  • 24
  • That does not help since both test_helper and the test class is loaded only after the models and classes are loaded. – Neel Vasa Dec 18 '15 at 06:37
  • `rake test` loads fixtures if you specify `fixtures :all` – mhaseeb Dec 18 '15 at 06:50
  • 1
    Sorry, but you are missing the point. Fixtures load fine, thats not the problem. The problem is the fixtures load after the classes are loaded. I need the fixtures to load before the classes load. – Neel Vasa Dec 19 '15 at 01:25