spring
spring copied to clipboard
Spring preventing auto-load in rspec tests in Rails 5
I'm upgrading a pretty large codebase (that uses spring) from rails 4.2.7 to 5.0.1. There are a bunch of tests to fix, and in fixing them the behavior I'm seeing is that the application code does not seem to be getting auto-loaded when using spring.
For example - I have app/models/user.rb
and spec/models/user_spec.rb
. The first time I run user_spec, it loads the code correctly and then subsequent runs use spring as expected. If I make a change in any of the tests in user_spec (say, add a raise 'foo'
so one test should now fail), then when I re-run using spring the change is picked up and my test fails.
But if I add a raise or make any other change in the function under test in the User model itself, the next time I run the test the change is not picked up and my test still passes. If I do spring stop
and then run it again, the change is picked up as expected and the test fails.
Are there any configuration options I might need to change when migrating from 4.2 -> 5.0 to get spring working again? I know rails changed some behavior in production mode to stop autoloading, but I'm in test env and at the time my test runs it looks like config.cache_classes
and config.eager_load
are both false as expected. Or is this a bug in spring?
Can you please provide a sample application that reproduces the error?
I know this is old but I had the same problem and found out it was because we used a manual require
in a model to avoid a namespace resolution error.
Changing it to the proper require_dependency
fixed the issue.