ruby on rails rspec错误
我正在通过“按示例学习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/
然后前两个测试通过 – 但是我们在教程中构建的新“about”页面失败并出现以下错误,尽管据我所知我构建的页面(以及控制器操作等)完全符合它们的要求:
Failures: 1) PagesController GET 'about' should be successful Failure/Error: response.should_be_success NoMethodError: undefined method `should_be_success' for # # ./spec/controllers/pages_controller_spec.rb:23:in `block (3 levels) in ' 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”,“安装”gem使用sudo“,”不要使用sudo“等安装gem)
我的开发机器正在运行ubuntu linux。
感谢您的帮助 – 请解释一下,如果您在Ruby noob语言中做错了!
运行bundle exec
是正确的,并且是必需的,因为您安装了更新版本的gem,而不是Gemfile.lock中指定的版本。 使用bundle exec
会覆盖加载路径,只会加载Gemfile.lock中指定的gem。 (您可能会发现将别名bundle exec
为更短的内容非常方便。)
第二个问题的答案就在错误消息中:
undefined method `should_be_success'
它应该是should be_success
。
- Rspec生成的规范失败了
- 无效的gemspec -Illformed要求
- 在Ruby中重置单例实例
- 为什么我得到FactoryGirl错误的参数数量错误?
- 使用rspec / devise登录集成测试
- 在rspec中的控制器测试中使用rails“post”,并在路由上使用作用域和协议
- NameError:未定义的局部变量或方法`app’
- rspec –init not working /`mkd ir’:参数无效 – ./C :( Errno :: EINVAL)
- ActiveRecord :: Base的未定义方法`mass_assignment_sanitizer =’:Class(NoMethodError)