尝试运行 rspec 时出错:`require': 无法加载此类文件 -- rails_helper (LoadError) [英] Error when trying to run rspec: `require': cannot load such file -- rails_helper (LoadError)

查看:28
本文介绍了尝试运行 rspec 时出错:`require': 无法加载此类文件 -- rails_helper (LoadError)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 Ruby on Rails 运行 rspec.我正在运行 Rails 4.1.1.我已经安装了 gem,已经建立了一个带有一些测试的规范文件夹.我已经通过 $ rails g rspec:install

创建了一个目录

我试图通过 $ rake db:test:prepare 创建一个测试数据库,但是它抛出了这个错误信息:

警告:不推荐使用 db:test:prepare.Rails 测试助手现在维护您的测试模式自动,有关详细信息,请参阅发行说明.

所以我最终查看了 this stack overflow post,在两个选项中,有效的一个是:

rake db:schema:load RAILS_ENV=test

所以,现在我需要运行 rspec.

当我从命令行运行 $ rspec spec 时,我收到此错误:

/Users/myname/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': 无法加载此类文件 -- rails_helper (LoadError)

如何解决这个问题,以便我可以开始运行测试?

解决方案

rspec V3 存在一些问题.但就您而言,您使用的是 V2.

改变

需要'rails_helper'

需要'spec_helper'

其他描述在这里https://teamtreehouse.com/forum/problem-with-rspec

对于 V3:

如果有人使用 rspec V3,那么在生成器未运行时会发生类似的错误.所以在尝试任何事情之前运行生成器.

rails 生成 rspec:install

如果您在控制台上收到大量警告.然后你需要从 .rspec 文件中删除 --warnings.

I am trying to run rspec for Ruby on Rails. I am running Rails 4.1.1. I have installed the gem, have established a spec folder with some tests. I have created a directory through $ rails g rspec:install

I tried to create a testing database through $ rake db:test:prepare but it throws this error message:

WARNING: db:test:prepare is deprecated. The Rails test helper now maintains your test 
schema automatically, see the release notes for details.

So I ended up looking at this stack overflow post, and of the two options, the one that worked was:

rake db:schema:load RAILS_ENV=test 

So, now I need to run rspec.

When I run $ rspec spec from the command line I get this error:

/Users/myname/.rbenv/versions/2.1.1/lib/ruby/2.1.0/rubygems/core_ext/
kernel_require.rb:55:in `require': cannot load such file -- rails_helper (LoadError)

How do I resolve this so that I can start running tests?

解决方案

There is some problem with rspec V3. But in your case you are using V2.

change

require 'rails_helper'

to

require 'spec_helper'

Other description find here https://teamtreehouse.com/forum/problem-with-rspec

For V3 :

If someone using rspec V3 then similar error occurs when generator not run. So before trying anything run generator.

rails generate rspec:install

If you are getting a huge list of warning on your console. Then you need to remove --warnings from .rspec file.

这篇关于尝试运行 rspec 时出错:`require': 无法加载此类文件 -- rails_helper (LoadError)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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