Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to transition from spork to spring?

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?

like image 649
Andrew Avatar asked Jan 13 '15 18:01

Andrew


2 Answers

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.rb or config/spring.rb or in any of the files which get run when your application initializes, such as config/application.rb, config/environments/*.rb or config/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

like image 136
Chris Bloom Avatar answered Sep 26 '22 02:09

Chris Bloom


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

like image 31
Magnuss Avatar answered Sep 24 '22 02:09

Magnuss