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

后端 未结 7 2036
予麋鹿
予麋鹿 2021-01-30 19:09

I\'m writing tests on Rspec for my models in Ruby on Rails application. And I receive this error while starting \'rspec spec\'

command:
/spec/models/client_spec         


        
7条回答
  •  忘了有多久
    2021-01-30 19:49

    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.

提交回复
热议问题