HPJAJ HPJAJ - 4 years ago 270
Ruby Question

Error when trying to run rspec: `require': cannot load such file -- rails_helper (LoadError)

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:

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?

Answer Source

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


require 'rails_helper'


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download