I was looking into this very issue earlier.
Binstubs are wrapper scripts around executables. In Rails they live inside bin/. If you run spring binstub --all, your binstubs will be using Spring.
Given this fact, you should be able to do something like this to use Rspec with Spring
guard :rspec, cmd: "bin/rspec" do
A little test to verify. Make sure that you have binstubbed rspec already.
bundle binstubs 'rspec-core'
Verify that Spring hasn't been bootstrapped in bin/rspec. The following block should not appear.
[bin/rspec]
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
Shut down Spring. Run bin/rspec and verify that Spring wasn't triggered.
spring stop
spring status
bin/rspec
spring status
If Spring wasn't triggered, you should see this
Spring is not running.
Now bootstrap your binstubs with Spring. Make sure that you have already bundle installed the necessary gems.
[Gemfile]
group :development, :test do
gem "rspec-rails", "~> 3.0"
gem 'spring-commands-rspec'
...
end
[terminal]
bundle install
Update binstubs to use Spring
spring binstub --all
Verify that Spring has been bootstrapped in bin/rspec. The following block should now appear.
[bin/rspec]
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
Shut down Spring. Run bin/rspec and verify that Spring was triggered.
spring stop
spring status
bin/rspec
spring status
Now check to see if the tests run faster after spring has loaded the environment for the tests.
spring stop
time bin/rspec
[output]
real 0m4.981s
user 0m0.144s
sys 0m0.032s
Spring should be running now. Let's see if it's doing its job.
time bin/rspec
[output]
real 0m0.831s
user 0m0.140s
sys 0m0.034s
Yep.
Bottom line, if your binstubs have been bootstrapped with Spring, calling the binstubs will include Spring. And, of course, only commands that have been registered with Spring can use Spring, which is why spring-commands-rspec was included in the Gemfile earlier to support Rspec.