27

我正在尝试在 Rails 3.2.16 项目中使用带有 rspec 和防护的 spring。

安装 spring 和 spring-commands-rspec 后,我创建了 binstubs:

> bundle exec spring binstub --all
  * bin/rake: spring inserted
  * bin/rspec: spring inserted
  * bin/rails: spring inserted

现在尝试使用 spring 运行规范失败(gems 路径和项目路径替换为易读性):

> bin/rspec spec/
Version: 1.1.0

Usage: spring COMMAND [ARGS]

Commands for spring itself:

binstub         Generate spring based binstubs. Use --all to generate a binstub for all known commands.
help            Print available commands.
status          Show current status.
stop            Stop all spring processes for this project.

Commands for your application:

rails           Run a rails command. The following sub commands will use spring: console, runner, generate, destroy.
rake            Runs the rake command
rspec           Runs the rspec command
rspec binstub
No DRb server is running. Running in local process instead ...
gemspath/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load': cannot load such file -- [PROJECT_PATH]/rspec (LoadError)
from gemspath/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `block in load_spec_files'
from gemspath/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `each'
from gemspath/rspec-core-2.14.7/lib/rspec/core/configuration.rb:896:in `load_spec_files'
from gemspath/rspec-core-2.14.7/lib/rspec/core/command_line.rb:22:in `run'
from gemspath/rspec-core-2.14.7/lib/rspec/core/runner.rb:77:in `rescue in run'
from gemspath/rspec-core-2.14.7/lib/rspec/core/runner.rb:73:in `run'
from gemspath/rspec-core-2.14.7/lib/rspec/core/runner.rb:17:in `block in autorun'

其他尝试:

> spring rspec

只显示弹簧帮助

同样适用

> spring rspec spec/

这是 rspec binstub (bin/rspec) :

#!/usr/bin/env ruby
begin
  load File.expand_path("../spring", __FILE__)
rescue LoadError
end
require 'bundler/setup'
load Gem.bin_path('rspec', 'rspec')

任何想法 ?

4

3 回答 3

60

我有同样的问题。我已经通过停止 spring 并添加到我的来解决它Gemfile

gem 'spring-commands-rspec', group: :development, require: false

需要重新启动 Spring 才能使用新添加的命令。

bin/spring stop
bin/rspec path/to/file.rb
于 2014-02-10T13:31:38.277 回答
13

答案已过时!已修复。请参阅下面的@pfleidi 答案。

我已经解决了这个问题,即使我不知道它为什么解决了这个问题。

只需gem 'spring', group: :development从 Gemfile 中删除,这样您就gem 'spring-commands-rspec'只剩下了。

运行bundle install,然后spring rpsec spec将工作!它太快了:)

于 2014-01-21T14:05:47.663 回答
10

您必须重新启动弹簧。所以停止它然后重新运行它

spring stop

spring rspec

然后它应该按预期工作。

于 2014-05-28T16:27:48.833 回答