1

In recent versions of Rails they've set config.cache_classes = true in config/environments/test.rb. This makes sense to me, as we won't typically be dynamically reloading classes. However, when we run with Spring, it complains that this should be set to false. I would love it if there was a way to thread the needle and accommodate both, something like:

config.cache_classes = !Spring.enabled?

I'm not seeing a way to accomplish this, though. Is there some way to tell if spring is active when the application is booting?

lobati
  • 9,284
  • 5
  • 40
  • 61
  • If your app is loading Spring before your test suite runs (check bin/rspec and/or bin/rails) then it'll always be loaded. However if you start it manually you could use `defined?(Spring)`. – Sebastián Palma Jan 02 '22 at 20:43
  • For me it looks like it's defined regardless of whether it's using Spring or not. I put a `binding.pry` inside my `test.rb` and with or without running with `spring rspec ...` it had `Spring` defined. – lobati Jan 03 '22 at 04:32

1 Answers1

2

Try this:

require 'spring/env'
Spring::Env.new.server_running?
=> true
Bart
  • 2,606
  • 21
  • 32