2011-11-27 67 views
4

的Ruby 1.9.2的Rails 3.1束EXEC rspec的VS rspec的規範

這裏的問題是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在裏面。

所以基本上我有2個問題:

  1. 爲什麼不bundle exec rspec spec/工作,而rspec spec/有沒有問題?

  2. 這兩個命令有什麼區別?

回答

16

看看this answer。在Windows的情況下,bundle exec更改您的$PATH%PATH%。因此,通過使用bundle exec rspec,您可以調用您的Gemfile中指定的RSpec版本。 rspec在沒有Bundler的情況下運行,執行$PATH中的那個。

您看到的錯誤可能是由於您的$PATH中的RSpec版本與您正在使用的Rails版本不兼容導致的。由Bundler安裝和執行的版本(與bundle exec rspec)兼容並且正常工作。