Rspec doesn't see my model Class. uninitialized constant error

Solution 1:

In rails 4.x and later (rspec-rails 3.1.0 and later) add this to the top of each of your spec files:

require "rails_helper"  # this

not

require "spec_helper"   # not this

Solution 2:

Your spec_helper file is missing some important commands. Specifically, it's not including config/environment and initializing rspec-rails.

You can add the following lines to the start of your spec/spec_helper.rb file

ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'

or you can just run

rails generate rspec:install

and overwrite your spec_helper with one generated for use with rspec-rails.

Solution 3:

You might also like to add --require rails_helper in your .rspec file so that it looks like this.

--color
--require spec_helper
--require rails_helper

You won't need to require rails_helper in all your specs, after this.