Reputation: 433
I have some Rspec tests that are sometimes failing with an error: Circular dependency detected while autoloading constant
. These tests are multithreaded (rufus-scheduler tests), which is apparently a known problem for autoloading code (http://route.github.io/2013/11/13/rails-autoloading.html).
I can get the tests to work consistently if I set config.eager_load = true
in config/environments/test.rb. However, I'm worried that this will really slow down the rest of my test suite when it grows larger. Is there any way to set this eager load option ONLY for my multithreaded tests?
Rails 4.1.4
Upvotes: 8
Views: 5097
Reputation: 4506
Add before { MyApp::Application.eager_load! } as the setup for this file/suite only. (Agreeing with @SterlingParamore above)
FYI: You need to put it in a before{}
rather than just loose in the body of the describe, because otherwise it will occur whenever the file is loaded (e.g. even if you are loading that file, but targeting another spec with a tag, e.g. rspec spec --tag=focus
).
Setting config.eager_load = true
in your test.rb config will slow down time to first test, unless you are using Spring (which after all is designed to speed up time to first test on subsequent test runs). However, if you are using Spring, might be worth cross-referencing https://github.com/rails/spring/issues/519, though this relates to quite a different eager-loading problem.*
Upvotes: 2