我正在学习“通过示例学习Rails”一书,我试图运行测试。出于某种原因,我无法使rspec正常工作。ruby on rails rspec error
如果我运行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不指定version--
group :development do
gem 'rspec-rails'
end
group :test do
gem 'rspec'
gem 'webrat'
end
如果我按照来自错误消息的建议并使用bundle exec rspec spec/
,然后前两个测试通过 - 但我们在教程中构建的新“about”页面失败,出现以下错误,尽管据我所知可以告诉我建立的页面和控制器操作等)完全相同哎应该是:
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
我是一个非常有经验的程序员,但我碰到有冲突的宝石版本和一百个不同的方式无穷无尽的问题,以完成使用Rails各种不同的任务(例如。 “使用RVM”,“不要使用RVM”,“使用sudo安装gems”,“不要使用sudo安装gems”等)
我的开发机器正在运行ubuntu linux。
感谢您的任何帮助 - 请解释您是否会在Ruby noob语言中做错了什么!
谢谢安德鲁!我错过了那个错误。现在所有人似乎都在工作。有没有办法更新Gemfile.lock,以便“正确”的rspec gem被安装? – julio
运行'bundle update'会根据给定的依赖关系树将所有gem更新到最新的可能版本,'bundle update rspec'会为指定的gem做更新。你不应该手动更新锁文件。 –
完美!非常感谢你的帮助。 – julio