bundle exec rspec VS rspec spec

半腔热情 提交于 2019-12-22 05:42:06

问题


Ruby 1.9.2 Rails 3.1

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

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 directory exists as exists spec_helper.rb in it.

So basically I have 2 questions:

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

  2. What is the difference between those two commands?


回答1:


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.

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.



来源:https://stackoverflow.com/questions/8288143/bundle-exec-rspec-vs-rspec-spec

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!