简体   繁体   中英

In Rails, how can I eager load all code before a specific Rspec test?

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

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 (eg even if you are loading that file, but targeting another spec with a tag, eg 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.*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM