ruby on rails rspec 错误 [英] ruby on rails rspec error

查看:34
本文介绍了ruby on rails rspec 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读通过示例学习 Rails"一书,并且正在尝试运行测试.出于某种原因,我无法让 rspec 正常工作.

I'm following through the "Learn Rails by Example" book, and I'm trying to run the tests. For some reason I can't get rspec to work properly.

如果我按照他的指示运行 rspec spec/ 命令,我会收到以下错误:

If I run the rspec spec/ command as he instructs, I get the following error:

$ 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 没有指定版本——

The odd thing is my Gemfile doesn't specify version--

group :development do
  gem 'rspec-rails'
end

group :test do
  gem 'rspec'
  gem 'webrat'
end

如果我遵循错误消息中的建议并使用 bundle exec rspec spec/ 然后前两个测试通过——但是我们在教程中构建的新关于"页面失败并显示以下内容错误,尽管据我所知,我构建的页面(以及控制器操作等)完全符合它们应有的样子:

If I follow the advice from the error message and use bundle exec rspec spec/ then the first two tests pass-- but the new "about" page we built in the tutorial fails with the following error, even though as far as I can tell the page I'd built (and controller actions etc.) are exactly as they should be:

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"等)

I'm a pretty experienced programmer but I've run into endless issues with conflicting gem versions and a hundred different ways to accomplish all the different tasks using Rails (eg. "use RVM", "Don't use RVM", "install gems using sudo", "don't install gems using sudo" etc.)

我的开发机器运行的是 ubuntu linux.

My dev machine is running ubuntu linux.

感谢您的帮助——请解释一下我在 Ruby noob 语言中做错了什么!

Thanks for any help-- please explain if you would what I'm doing wrong in Ruby noob language!

推荐答案

Running bundle exec 是正确的,并且是必需的,因为您安装了该 gem 的较新版本,它被加载而不是一个在您的 Gemfile.lock 中指定.使用 bundle exec 覆盖加载路径,导致仅加载 Gemfile.lock 中指定的 gem.(您可能会发现将 bundle exec 别名为较短的内容很方便.)

Running bundle exec is correct, and is needed because you have a newer version of that gem installed that gets loaded instead of the one specified in your Gemfile.lock. Using bundle exec overrides the load path, causing only the gems specified in your Gemfile.lock to be loaded. (You may find it handy to alias bundle exec to something shorter.)

第二个问题的答案在错误消息中是正确的:

The answer to the second problem is right in the error messages:

undefined method `should_be_success'

应该是should be_success.

这篇关于ruby on rails rspec 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆