捆绑执行 rspec VS rspec 规范 [英] bundle exec rspec VS rspec spec

查看:34
本文介绍了捆绑执行 rspec VS rspec 规范的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby 1.9.2 轨道 3.1

Ruby 1.9.2 Rails 3.1

这里是问题 bundle exec rspec spec/ 不起作用,但 rspec spec/ 运行正常.

Here is the problem bundle exec rspec spec/ does not work, but rspec spec/ runs ok.

当我运行 c:\RailsInstaller\work\apptwit>bundle exec rspec spec/(这是我的应用所在的目录,所以不需要指定 spec 的路径)我收到

When I run c:\RailsInstaller\work\apptwit>bundle exec rspec spec/ (this is the directory where my app is located, so the path to spec would not need to be specified) I receive

c:/RailsInstaller/work/apptwit/spec/controllers/pages_controller_spec.rb:1:in `require': no such file to load -- spec_he lper (LoadError)
        from c:/RailsInstaller/work/apptwit/spec/controllers/pages_controller_spec.rb:1:in `<top (required)>'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:i
n `load'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:i
n `block in load_spec_files'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:i
n `map'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/configuration.rb:459:i
n `load_spec_files'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/command_line.rb:18:in
`run'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:80:in `run_i
n_process'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:69:in `run'
        from C:/RailsInstaller/Ruby1.9.2/lib/ruby/gems/1.9.1/gems/rspec-core-2.7.1/lib/rspec/core/runner.rb:10:in `block
 in autorun'

/spec 目录和 spec_helper.rb 一样存在.

/spec directory exists as exists spec_helper.rb in it.

所以基本上我有两个问题:

So basically I have 2 questions:

  1. 为什么 bundle exec rspec spec/ 不起作用而 rspec spec/ 没有问题?

  1. Why doesn't bundle exec rspec spec/ work while rspec spec/ has no problems?

这两个命令有什么区别?

What is the difference between those two commands?

推荐答案

看看 这个答案.bundle exec 更改您的 $PATH%PATH% 在 Windows 的情况下.因此,通过使用 bundle exec rspec,您调用的是 Gemfile 中指定的 RSpec 版本.rspec 在没有 Bundler 的情况下运行会执行您的 $PATH 中的那个.

Take a look at this answer. bundle exec changes your $PATH, or %PATH% in case of Windows. As a result, by using bundle exec rspec you're calling the RSpec's version which is specified in your Gemfile. rspec ran without Bundler executes the one in your $PATH.

您看到的错误可能是由于您的 $PATH 中的 RSpec 版本与您正在使用的 Rails 版本不兼容造成的.Bundler 安装和执行的版本(使用 bundle exec rspec)兼容并且工作正常.

The error you see might be caused by the fact that the RSpec version in your $PATH is incompatible with Rails version you're working with. The version installed and executed by Bundler (with bundle exec rspec) is compatible and works fine.

这篇关于捆绑执行 rspec VS rspec 规范的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆