I'm trying to test some models in a gem using Rspec and Postgres. Currently trying to do this by running a rake task in the spec_helper.rb file that will establish the pg database connection for the duration of my Rspec tests.
I've scanned other questions (my approach is largely based on these two questions 1, 2) and haven't discovered a good solution.
I'm not using the sqlite in-memory db feature due to the way our code is written.
Custom spec_helper looks like this:
RSpec.configure do |config|
load "support/schema.rb"
load File.expand_path("../../../lib/tasks/database.rake", __FILE__)
require File.dirname(__FILE__) + 'support/models.rb'
Rake::Task['database'].invoke
However when I run rspec it tells me that there is no connection pool:
active_record/connection_adapters/abstract/connection_pool.rb:570:in
`retrieve_connection': No connection pool for ActiveRecord::Base
(ActiveRecord::ConnectionNotEstablished)
Does anyone have any advice or insight on this issue? It would be much appreciated.