捆绑exec rspec VS rspec规范

时间:2011-11-27 18:56:39

标签: ruby-on-rails-3 rspec2

Ruby 1.9.2 Rails 3.1

问题bundle exec rspec spec/不起作用,但rspec spec/运行正常。

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

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.

基本上我有两个问题:

  1. 为什么bundle exec rspec spec/rspec spec/没有问题时无效?

  2. 这两个命令有什么区别?

1 个答案:

答案 0 :(得分:21)

看看this answer。如果是Windows,则bundle exec会更改$PATH%PATH%。因此,通过使用bundle exec rspec,您将调用Gemfile中指定的RSpec版本。没有Bundler的rspec在你的$PATH中执行。

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