title: Testing a databaseless Rails 5 application with rspec-rails
body: <p>I have a Rails <code>5.0.1</code> app that is NOT backed by any database. When attempting to write a controller test I get a <code>ActiveRecord::ConnectionNotEstablished</code> exception even though I have explicitly configured my <code>spec/rails_helper.rb</code> not to use <code>ActiveRecord</code> and removed references to active_record in <code>config/application.rb</code>. RSpec is trying to run such test within a transaction which requires a database connection to be established. I am attaching the stack trace for reference and I used this Github issue to setup RSpec without <code>ActiveRecord</code> <a href="https://github.com/rspec/rspec-rails/issues/1416#issuecomment-120055707" rel="noreferrer">rspec-rails for a rails project without db connection</a>. </p>
  
  <p>Failures:</p>
  
  <p>1) ApplicationController the truth false not equal true
       Failure/Error: raise ConnectionNotEstablished, "No connection pool with id #{spec_name} found." unless pool</p>
  
  <pre><code> ActiveRecord::ConnectionNotEstablished:
     No connection pool with id primary found.
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_adapters/abstract/connection_pool.rb:882:in `retrieve_connection'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_handling.rb:128:in `retrieve_connection'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/connection_handling.rb:91:in `connection'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/fixtures.rb:516:in `create_fixtures'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/fixtures.rb:1015:in `load_fixtures'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/fixtures.rb:988:in `setup_fixtures'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/fixtures.rb:852:in `before_setup'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-rails-3.6.1/lib/rspec/rails/adapters.rb:126:in `block (2 levels) in &lt;module:MinitestLifecycleAdapter&gt;'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:447:in `instance_exec'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:375:in `execute_with'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:606:in `block (2 levels) in run_around_example_hooks_for'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:342:in `call'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:607:in `run_around_example_hooks_for'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/hooks.rb:464:in `run'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:457:in `with_around_example_hooks'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:500:in `with_around_and_singleton_context_hooks'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example.rb:251:in `run'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:627:in `block in run_examples'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:623:in `map'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:623:in `run_examples'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:589:in `run'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:590:in `block in run'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:590:in `map'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/example_group.rb:590:in `run'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:118:in `block (3 levels) in run_specs'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:118:in `map'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:118:in `block (2 levels) in run_specs'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/configuration.rb:1894:in `with_suite_hooks'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:113:in `block in run_specs'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/reporter.rb:79:in `report'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:112:in `run_specs'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:87:in `run'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:71:in `run'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/lib/rspec/core/runner.rb:45:in `invoke'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/gems/rspec-core-3.6.0/exe/rspec:4:in `&lt;top (required)&gt;'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/bin/rspec:23:in `load'
   # /home/vagrant/.bundle/easypost_admin/ruby/2.3.0/bin/rspec:23:in `&lt;top (required)&gt;'
   # /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `load'
   # /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:63:in `kernel_load'
   # /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli/exec.rb:24:in `run'
   # /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:304:in `exec'
   # /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
   # /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/invocation.rb:126:in `invoke_command'
   # /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor.rb:359:in `dispatch'
   # /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/vendor/thor/lib/thor/base.rb:440:in `start'
   # /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/cli.rb:11:in `start'
   # /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/exe/bundle:27:in `block in &lt;top (required)&gt;'
   # /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/lib/bundler/friendly_errors.rb:98:in `with_friendly_errors'
   # /opt/ruby2.3/lib64/ruby/gems/2.3.0/gems/bundler-1.12.5/exe/bundle:19:in `&lt;top (required)&gt;'
   # /vagrant/easypost_admin/vendor/bundle/bundle:23:in `load'
   # /vagrant/easypost_admin/vendor/bundle/bundle:23:in `&lt;main&gt;'
   #
   #   Showing full backtrace because every line was filtered out.
   #   See docs for RSpec::Configuration#backtrace_exclusion_patterns and
   #   RSpec::Configuration#backtrace_inclusion_patterns for more information.
  </code></pre>
  
  <p>Finished in 0.0058 seconds (files took 2.29 seconds to load)
  1 example, 1 failure</p>
  
  <p>Failed examples:</p>
  
  <p>rspec ./spec/controllers/application_controller_spec.rb:15 # ApplicationController the truth false not equal true</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p><code>rails_help.rb</code></p>
  
  <pre><code>require 'spec_helper'
  ENV['RAILS_ENV'] ||= 'test'
  require File.expand_path('../../config/environment', __FILE__)
  # Prevent database truncation if the environment is production
  abort("The Rails environment is running in production mode!") if Rails.env.production?
  require 'rspec/rails'
  # Add additional requires below this line. Rails is not loaded until this point!
  
  # Checks for pending migration and applies them before tests are run.
  # If you are not using ActiveRecord, you can remove this line.
  # ActiveRecord::Migration.maintain_test_schema!
  
  RSpec.configure do |config|
    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
    # config.fixture_path = "#{::Rails.root}/spec/fixtures"
  
    # If you're not using ActiveRecord, or you'd prefer not to run each of your
    # examples within a transaction, remove the following line or assign false
    # instead of true.
    config.use_transactional_fixtures = false
    # The different available types are documented in the features, such as in
    # https://relishapp.com/rspec/rspec-rails/docs
    config.infer_spec_type_from_file_location!
  
    # Filter lines from Rails gems in backtraces.
    config.filter_rails_from_backtrace!
  end
  </code></pre>
  
  <p><code>spec_helper.rb</code></p>
  
  <pre><code>RSpec.configure do |config|
    # rspec-expectations config goes here. You can use an alternate
    # assertion/expectation library such as wrong or the stdlib/minitest
    # assertions if you prefer.
    config.expect_with :rspec do |expectations|
      expectations.include_chain_clauses_in_custom_matcher_descriptions = true
    end
  
    # rspec-mocks config goes here. You can use an alternate test double
    # library (such as bogus or mocha) by changing the `mock_with` option here.
    config.mock_with :rspec do |mocks|
      # Prevents you from mocking or stubbing a method that does not exist on
      # a real object. This is generally recommended, and will default to
      # `true` in RSpec 4.
      mocks.verify_partial_doubles = true
    end
  
    config.shared_context_metadata_behavior = :apply_to_host_groups
  end
  </code></pre>