Getting an uninitialized constant error with RSpec. Have no idea what's causing it

半城伤御伤魂 提交于 2019-12-01 02:11:26

I ran into this problem. In the spec_helper.rb try replacing:

require "rails"

with

require "rails/all"

Worked in my situation.

You need to initialize environment, add this line to spec_helper.rb:

require File.expand_path("../../config/environment", __FILE__)

You may encounter this issue if you're trying to use rspec-rails in a non-rails project. In that case using require "rails/all" is not an option because it'd require ActiveRecord stuff leaving you with:

ActiveRecord::ConnectionNotEstablished: No connection pool with 'primary' found.

Instead you can fix this issue with:

require "action_controller/railtie"

If it's not a Rails app and you don't want to include all of Rails, add this to your spec_helper.rb:

require 'action_view'
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!