Rspec doesn't see my model Class. uninitialized constant error
In rails 4.x (rspec-rails 3.1.0) use
require "rails_helper" # this
not
require "spec_helper" # not this
in your spec files
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
.
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.