jul*_*lio 3 ruby rspec ruby-on-rails ruby-on-rails-3
我正在阅读"通过示例学习Rails"一书,我正在尝试运行测试.出于某种原因,我无法让rspec正常工作.
如果我rspec spec/按照他的指示运行命令,我会收到以下错误:
$ rspec spec/
/home/desktop/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.21/lib/bundler/runtime.rb:31:in `block in setup':
You have already activated rspec-core 2.7.1, but your Gemfile requires rspec-core 2.6.4.
Using bundle exec may solve this. (Gem::LoadError)
Run Code Online (Sandbox Code Playgroud)
奇怪的是我的Gemfile没有指定版本 -
group :development do
gem 'rspec-rails'
end
group :test do
gem 'rspec'
gem 'webrat'
end
Run Code Online (Sandbox Code Playgroud)
如果我按照错误消息的建议并使用bundle exec rspec spec/然后前两个测试通过 - 但是我们在教程中构建的新"关于"页面失败并出现以下错误,即使我可以告诉页面我也是内置(和控制器动作等)完全符合它们:
Failures:
1) PagesController GET 'about' should be successful
Failure/Error: response.should_be_success
NoMethodError:
undefined method `should_be_success' for #<ActionController::TestResponse:0x00000003539438>
# ./spec/controllers/pages_controller_spec.rb:23:in `block (3 levels) in <top (required)>'
Finished in 0.10861 seconds
3 examples, 1 failure
Failed examples:
rspec ./spec/controllers/pages_controller_spec.rb:21 # PagesController GET 'about' should be successful
Run Code Online (Sandbox Code Playgroud)
我是一个非常有经验的程序员,但是我遇到了冲突的宝石版本和使用Rails完成所有不同任务的一百种不同方法的无穷无尽的问题(例如"使用RVM","不要使用RVM","安装"宝石使用sudo","不要使用sudo"等安装宝石)
我的开发机器正在运行ubuntu linux.
感谢您的帮助 - 请解释一下,如果您在Ruby noob语言中做错了!
运行bundle exec是正确的,并且是必需的,因为您安装了更新版本的gem,而不是Gemfile.lock中指定的版本.使用bundle exec覆盖加载路径,仅加载Gemfile.lock中指定的gem.(您可能会发现将其缩写为bundle exec更短的别名.)
第二个问题的答案就在错误消息中:
undefined method `should_be_success'
Run Code Online (Sandbox Code Playgroud)
它应该是should be_success.
| 归档时间: |
|
| 查看次数: |
2063 次 |
| 最近记录: |