I am currently using Spork with Guard, Rspec, and Cucumber. I'd like to move to Spring, but can't find any documentation on what I need to change.
Specifically, I'm curious if I need to change out my:
require 'spork'
Spork.prefork do
# ...
end
Spork.each_run do
# ...
end
...with something like:
require 'spring'
Spring.prefork do
# ...
end
Spring.each_run do
# ...
end
However, I know that there isn't a Spring.prefork because the documentation says so. So should I simply remove the references to Spork or do I need to replace them with something?
As you mention in your question, there is no Prefork block. The docs provide a workaround: simply move your existing Spork.prefork block to an initializer or anywhere that it will be picked up and run at load time by Rails.
From https://github.com/rails/spring#running-code-before-forking:
There is no Spring.before_fork callback. To run something before the fork, you can place it in
~/.spring.rborconfig/spring.rbor in any of the files which get run when your application initializes, such asconfig/application.rb,config/environments/*.rborconfig/initializers/*.rb.
As for your Spork.each_run block, since you're using Rspec you could move it into a before(:suite) block. See the Rspec docs on before and after hooks
Simply remove all occurrences of Spork and install spring.
Afterwards run bundle exec spring binstub --all.
Now if you run bin/rails c it will use spring.
For rspec use spring-commands-rspec
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With