【发布时间】:2014-03-11 13:42:48
【问题描述】:
Guard-RSpec 在自述文件中提到,可以通过指定自定义 cmd 来使用 spring 运行规范:
guard :rspec, cmd: 'spring rspec' do
# ...
end
这曾经工作得很好,直到我做了一个spring binstub --all,它改变了我的bin/spring 从......
#!/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 并按回车键时,它只会告诉我:
[2] guard(main)> <<<<< pressing enter
14:35:35 - INFO - Run all
14:35:35 - INFO - Running all specs
并出现类似“RSpec results - Failed”的通知。
像这样更改我的Guardfile 并从 RSpec 的cmd 中删除spring 时...
guard :rspec, cmd: 'rspec' do
...再次运行规范,但显然没有使用弹簧?
我还必须提到,当从 OSX 终端运行 spring 时,似乎什么也没发生:
$ spring
$
那么:我必须如何配置 Guard 和 RSpec 才能使用 Spring?
更新
目前,我已将我的 bin/spring 可执行文件恢复为“binstubbing”之前的版本:
#!/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 看起来像这样:
guard :rspec, cmd: 'spring rspec' do ... end
这可行,但我不认为它比运行 rspec 更快。
所以我现在完全不确定如何使用 Spring 正确运行 RSpec - 使用 spring rspec 还是仅使用 rspec?
【问题讨论】:
-
试试
cmd: 'spring rspec spec'。由于 Spring 更新到 1.1.0,它似乎不再默认选择 spec 目录。 -
谢谢,但这对我来说没有任何改变。
标签: ruby-on-rails spring rspec guard