Skip to content

Rspec-Rails assumes I am using ActiveRecord, but I am not #2172

@JohnMerlino2

Description

@JohnMerlino2

So I used byebug to isolate the issue to these lines of code:

/home/myuser/.rvm/gems/ruby-2.4.7@core/gems/rspec-rails-3.8.2/lib/rspec/rails/adapters.rb:126

At adapters.rb:126, it performs the around example, which invokes before_setup:

    group.around do |example|
      before_setup

This is where the problems begin. before_setup in turns invokes setup_fixtures:

 def before_setup
=> 826:       setup_fixtures
   827:       super
   828:     end

setup_fixtures makes reference to ActiveRecord all over:

def setup_fixtures(config = ActiveRecord::Base)
   949:       else
=> 950:         ActiveRecord::FixtureSet.reset_cache
   951:         @@already_loaded_fixtures[self.class] = nil
   952:         @loaded_fixtures = load_fixtures(config)

Thus, it gives me the error:

#<ActiveRecord::ConnectionNotEstablished: No connection pool for ActiveRecord::Base>

I don't have any of these settings in my app:

ActiveRecord::Migration.maintain_test_schema!
ActiveRecord::Migration.check_pending!
config.fixture_path = "#{::Rails.root}/spec/fixtures"
config.use_transactional_fixtures = true

Also, initializers/devise.rb is configured with Mongoid, not ActiveRecord. I did a global search in Emacs Projectile of my app. There is no reference to ActiveRecord anywhere. I cannot vouch for specific Gems I am using, but I am sure I configured all Gems to use Mongoid where necessary.

The bottom line is as far as rspec-rails is concerned, I am not using ActiveRecord. There are no migration files, no database.yml, no reference at all to ActiveRecord.

To get things to work, I had to use this hack in rails_helper.rb:

require 'spec_helper'
Object.send(:remove_const, :ActiveRecord)
require 'rspec/rails'

Your response might be 'well if another Gem uses ActiveRecord, then it might be causing the autoload behavior and hence why rspec-rails thinks ActiveRecord is present'. But I can say that I am not autoloading ActiveRecord anywhere in my app, and rspec-rails should respect my configuration, not the configuration of some other gem outside my control.

P.S. I appreciate your contribution to the open source community, especially ruby testing. I do not intend to sound cantankerous above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions