问题描述
我正在尝试为Ruby on Rails运行rspec。我正在运行Rails 4.1.1。我已经安装了gem,并通过一些测试建立了一个spec文件夹。我已经通过 $ rails g rspec:install
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
创建了一个目录我试图通过<$创建一个测试数据库c $ c> $ rake db:test:prepare ,但它抛出此错误消息:
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
因此,现在我需要运行rspec 。
当我从命令行运行 $ rspec spec
时,出现此错误:
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?
推荐答案
rspec V3存在一些问题。
There is some problem with rspec V3. But in your case you are using V2.
change
require 'rails_helper'
至
require 'spec_helper'
其他说明可在此处找到
Other description find here https://teamtreehouse.com/forum/problem-with-rspec
对于V3:
如果有人使用rspec V3,则在发电机不运行时也会发生类似错误。因此,在尝试运行发生器之前。
If someone using rspec V3 then similar error occurs when generator not run. So before trying anything run generator.
rails generate rspec:install
如果在控制台上收到大量警告。然后,您需要从 .rspec
文件中删除-警告
。
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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!