我正在阅读“通过示例学习 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)
奇怪的是我的 Gemfile 没有指定版本——
group :development do
gem 'rspec-rails'
end
group :test do
gem 'rspec'
gem 'webrat'
end
如果我按照错误消息中的建议并使用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
我是一位经验丰富的程序员,但我遇到了无数与冲突的 gem 版本和一百种不同的方法来使用 Rails 完成所有不同任务的问题(例如“使用 RVM”、“不使用 RVM”、“安装使用 sudo 的 gems”、“不要使用 sudo 安装 gems”等)
我的开发机器运行的是 ubuntu Linux。
感谢您的帮助——如果您明白我在 Ruby noob 语言中做错了什么,请解释一下!