Guard-RSpec 和 Spring:命令 `cmd: spring rspec` 不运行 Guard 中的规范 [英] Guard-RSpec and Spring: command `cmd: spring rspec` doesn't run the specs within Guard
问题描述
Guard-RSpec 在 README 中提到可以通过指定 cusom cmd
使用 spring 运行规范:
Guard-RSpec mentions in the README that one could run specs using spring by specifying a cusom cmd
:
guard :rspec, cmd: 'spring rspec' do
# ...
end
这曾经工作得很好,直到我做了一个 spring binstub --all
它改变了我的 bin/spring
从...
This used to work fine, until I did a spring binstub --all
which changed my bin/spring
from...
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'spring' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('spring', 'spring')
...到...
#!/usr/bin/env ruby
# This file loads spring without using Bundler, in order to be fast
# It gets overwritten when you run the `spring binstub` command
unless defined?(Spring)
require "rubygems"
require "bundler"
if match = Bundler.default_lockfile.read.match(/^GEM$.*?^ spring \((.*?)\)$.*?^$/m)
ENV["GEM_PATH"] = ([Bundler.bundle_path.to_s] + Gem.path).join(File::PATH_SEPARATOR)
ENV["GEM_HOME"] = ""
Gem.paths = ENV
gem "spring", match[1]
require "spring/binstub"
end
end
现在当运行 guard
并按回车键时,它只是告诉我:
Now when running guard
and hitting enter, it simply tells me this:
[2] guard(main)> <<<<< pressing enter
14:35:35 - INFO - Run all
14:35:35 - INFO - Running all specs
出现类似RSpec 结果 - 失败"的通知.
And a notification like "RSpec results - Failed" appears.
当更改我的 Guardfile
并像这样从 RSpec 的 cmd
中删除 spring
时...
When changing my Guardfile
and removing spring
from the RSpec's cmd
like this...
guard :rspec, cmd: 'rspec' do
...规格再次运行,但显然没有使用弹簧?
...the specs are run again, but apparently not using spring?
我还要提一下,当从 OSX 终端运行 spring
时,似乎什么也没发生:
I also have to mention that when running spring
from the OSX terminal, nothing seems to happen:
$ spring
$
那么:我必须如何配置 Guard 和 RSpec 才能使用 Spring?
So: how must I configure Guard and RSpec to use Spring?
更新
目前,我已经将我的 bin/spring
可执行文件恢复到binstubbing"之前的版本:
At the moment, I have reverted my bin/spring
executable to the version before "binstubbing" it:
#!/usr/bin/env ruby
#
# This file was generated by Bundler.
#
# The application 'spring' is installed as part of a gem, and
# this file is here to facilitate running it.
#
require 'pathname'
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
Pathname.new(__FILE__).realpath)
require 'rubygems'
require 'bundler/setup'
load Gem.bin_path('spring', 'spring')
Guardfile 如下所示:
And the Guardfile looks like this:
guard :rspec, cmd: 'spring rspec' do ... end
这行得通,但我不认为它比运行裸 rspec
快.
This works, but I don't think it's faster than running bare rspec
.
所以我现在完全不确定如何使用 Spring 正确运行 RSpec - 使用 spring rspec
还是仅使用 rspec
?
So I'm absolutely unsure now how to correctly run RSpec with Spring - using spring rspec
or just rspec
?
推荐答案
我之前正在研究这个问题.
I was looking into this very issue earlier.
Binstubs 是围绕可执行文件的包装脚本.他们住在 Rails 中内箱/.如果你运行 spring binstub --all,你的 binstubs 将是使用弹簧.
Binstubs are wrapper scripts around executables. In Rails they live inside bin/. If you run spring binstub --all, your binstubs will be using Spring.
鉴于这个事实,你应该能够做这样的事情来将 Rspec 与 Spring 一起使用
Given this fact, you should be able to do something like this to use Rspec with Spring
guard :rspec, cmd: "bin/rspec" do
一个小测试来验证.确保您已经对 rspec 进行了 binstubbed.
A little test to verify. Make sure that you have binstubbed rspec already.
bundle binstubs 'rspec-core'
验证 Spring 尚未在 bin/rspec 中引导.不应出现以下块.
Verify that Spring hasn't been bootstrapped in bin/rspec. The following block should not appear.
[bin/rspec]
[bin/rspec]
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
关闭 Spring.运行 bin/rspec 并验证 Spring 没有被触发.
Shut down Spring. Run bin/rspec and verify that Spring wasn't triggered.
spring stop
spring status
bin/rspec
spring status
如果 Spring 没有被触发,你应该看到这个
If Spring wasn't triggered, you should see this
Spring is not running.
现在用 Spring 引导您的 binstub.确保您已经捆绑安装了必要的 gem.
Now bootstrap your binstubs with Spring. Make sure that you have already bundle installed the necessary gems.
[宝石文件]
group :development, :test do
gem "rspec-rails", "~> 3.0"
gem 'spring-commands-rspec'
...
end
[终端]
bundle install
更新 binstubs 以使用 Spring
Update binstubs to use Spring
spring binstub --all
验证 Spring 是否已在 bin/rspec 中引导.现在应该会出现以下块.
Verify that Spring has been bootstrapped in bin/rspec. The following block should now appear.
[bin/rspec]
[bin/rspec]
begin
load File.expand_path("../spring", __FILE__)
rescue LoadError
end
关闭 Spring.运行 bin/rspec 并验证 Spring 是否被触发.
Shut down Spring. Run bin/rspec and verify that Spring was triggered.
spring stop
spring status
bin/rspec
spring status
现在检查在 spring 加载测试环境后测试是否运行得更快.
Now check to see if the tests run faster after spring has loaded the environment for the tests.
spring stop
time bin/rspec
[输出]
real 0m4.981s
user 0m0.144s
sys 0m0.032s
Spring 现在应该运行了.让我们看看它是否在做它的工作.
Spring should be running now. Let's see if it's doing its job.
time bin/rspec
[输出]
real 0m0.831s
user 0m0.140s
sys 0m0.034s
是的.
最重要的是,如果你的 binstubs 已经用 Spring 引导,调用 binstubs 将包括 Spring.而且,当然,只有已经注册到 Spring 的命令才能使用 Spring,这就是为什么早先在 Gemfile 中包含 spring-commands-rspec 以支持 Rspec 的原因.
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.
这篇关于Guard-RSpec 和 Spring:命令 `cmd: spring rspec` 不运行 Guard 中的规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!