运行控制器的 rspec 测试时出现 Rspec 错误 [英] Rspec error when I run my rspec test of my controller

查看:54
本文介绍了运行控制器的 rspec 测试时出现 Rspec 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Rails v2.3 应用程序.

I am developing a Rails v2.3 application.

当我通过执行命令运行 rspec 测试时:

When I run the rspec test by execute command:

rspec spec/controllers/my_controller_spec.rb

我收到了错误消息,显示如下:

/.rvm/gems/ruby-1.8.7-p352@myapp/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:427:in `raise_if_rspec_1_is_loaded':  (RuntimeError)
********************************************************************************
  You are running rspec-2, but it seems as though rspec-1 has been loaded as
  well.  This is likely due to a statement like this somewhere in the specs:

      require 'spec'

  Please locate that statement, remove it, and try again.
********************************************************************************
/.rvm/gems/ruby-1.8.7-p352@myapp/gems/rspec-core-2.6.4/lib/rspec/core/configuration.rb:420:in `load_spec_files'

----更新---

因为它抱怨一些包含代码 require 'spec' 的文件,所以我按照这个线索在 中找到了require 'spec'"spec/spec_helper.rb然而,在我删除之后,同样的错误仍然出现,我没有现在让任何其他文件包含代码.

Since it complains about some file which contain the code require 'spec', so I follow this clue and I found "require 'spec'" in spec/spec_helper.rb , However, after I removed it , the same error still raise up, and I don't have any other file contain the code now.

为什么还会出现错误,那么真正的原因是什么?

Why the error still coming, what is the real cause then?

推荐答案

rspecrspec-2 的可执行文件.specrspec-1 的可执行文件.rspec-2rails 2.3 不兼容.你的命令应该是:

rspec is the executable for rspec-2. spec is the executable for rspec-1. rspec-2 is not compatible with rails 2.3. Your command should be:

spec spec/controllers/my_controller_spec.rb

这篇关于运行控制器的 rspec 测试时出现 Rspec 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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