title: Rails: Cucumber not cleaning DB
body: <p>I'm having some issues with cucumber &amp; database transactions - specifically, when I run the test suite, database transactions are not cleaned afterwards.</p>
  
  <p>I'm running rails 3.1 with spork, postgres.</p>
  
  <p>Initially features/support/env.rb was set to use database_cleaner, but consistently got the following error on each call to the db:</p>
  
  <blockquote>
    <p>No database specified. Missing argument: database. (ArgumentError)
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/postgresql_adapter.rb:22:in <code>postgresql_connection'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:292:in</code>new_connection'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:302:in <code>checkout_new_connection'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:254:in</code>block (2 levels) in checkout'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:250:in <code>loop'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:250:in</code>block in checkout'
          /Users/john/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/monitor.rb:201:in <code>mon_synchronize'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:249:in</code>checkout'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:151:in <code>connection'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_pool.rb:388:in</code>retrieve_connection'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/activerecord-3.1.0.rc4/lib/active_record/connection_adapters/abstract/connection_specification.rb:107:in <code>retrieve_connection'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-rails-1.0.2/lib/cucumber/rails/hooks/active_record.rb:7:in</code>connection'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.6.7/lib/database_cleaner/active_record/transaction.rb:17:in <code>clean'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.6.7/lib/database_cleaner/base.rb:77:in</code>clean'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.6.7/lib/database_cleaner/configuration.rb:56:in <code>block in clean'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.6.7/lib/database_cleaner/configuration.rb:56:in</code>each'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/database_cleaner-0.6.7/lib/database_cleaner/configuration.rb:56:in <code>clean'
          /Users/john/.rvm/gems/ruby-1.9.2-p290/gems/cucumber-rails-1.0.2/lib/cucumber/rails/hooks/database_cleaner.rb:9:in</code>After'</p>
  </blockquote>
  
  <p>I tried reverting to regular transactions, but no joy. I can access the database via the console (cucumber environment) and create/delete/retrieve records with no problems. The config/database.yml, features/support/env.rb, config/environments/cucumber.rb and rspec/spec_helper.rb files are added below. Any suggestions very appreciated - this one has had me stumped for some time:</p>
  
  <p>CONFIG/DATABASE.yml</p>
  
  <pre><code>default: &amp;defaults
    adapter: postgresql
    username: rails_dev
    password: foobar
  
  development:
    &lt;&lt;: *defaults
    database: fcct_d
  
  test: &amp;test
    &lt;&lt;: *defaults
    database: fcct_t
  
  production:
    &lt;&lt;: *defaults
    database: fcct_p
    username: fcct
    password: k#1*5Avb3dTa
  
  cucumber:
    adapter: postgresql
    username: rails_dev
    password: foobar
    database: fcct_t
  </code></pre>
  
  <p>FEATURES/SUPPORT/ENV.RB</p>
  
  <pre><code>require 'rubygems'
  require 'spork'
  
  Spork.prefork do
    require 'cucumber/rails'
    require 'database_cleaner'
    require 'database_cleaner/cucumber'
  
  
    Capybara.default_selector = :css
  
    ActionController::Base.allow_rescue = false
  
    begin
      DatabaseCleaner.strategy = :transaction
    rescue NameError
      raise "You need to add database_cleaner to your Gemfile (in the :test group) if you wish to use it."
    end
  
  end
  
  Spork.each_run do
    require 'factory_girl'
    require File.join(File.dirname(__FILE__), '../../lib/existing_factory/existing_factory.rb')
  end
  </code></pre>
  
  <p>CONFIG/ENVIRONMENTS/CUCUMBER.RB</p>
  
  <blockquote>
    <p>BusinessschoolCorporate::Application.configure do   # Settings
    specified here will take precedence over those in
    config/application.rb</p>
    
    <p># The test environment is used exclusively to run your application's</p>
    
    <h1>test suite.  You never need to work with it otherwise.  Remember</h1>
    
    <p>that   # your test database is "scratch space" for the test suite and
    is wiped   # and recreated between test runs.  Don't rely on the data
    there!<br>
    config.cache_classes = true<br>
    config.use_transactional_fixtures = true</p>
    
    <p># Configure static asset server for tests with Cache-Control for
    performance   config.serve_static_assets = true<br>
    config.static_cache_control = "public, max-age=3600"</p>
    
    <p># Log error messages when you accidentally call methods on nil<br>
    config.whiny_nils = true</p>
    
    <p># Show full error reports and disable caching<br>
    config.consider_all_requests_local       = true<br>
    config.action_controller.perform_caching = false</p>
    
    <p># Raise exceptions instead of rendering exception templates<br>
    config.action_dispatch.show_exceptions = false</p>
    
    <p># Disable request forgery protection in test environment<br>
    config.action_controller.allow_forgery_protection    = false</p>
    
    <p># Tell Action Mailer not to deliver emails to the real world.   #
    The :test delivery method accumulates sent emails in the   #
    ActionMailer::Base.deliveries array.<br>
    config.action_mailer.delivery_method = :test</p>
    
    <p># Use SQL instead of Active Record's schema dumper when creating the
    test database.   # This is necessary if your schema can't be
    completely dumped by the schema dumper,   # like if you have
    constraints or database-specific column types   #
    config.active_record.schema_format = :sql</p>
    
    <p># Print deprecation notices to the stderr<br>
    config.active_support.deprecation = :stderr end</p>
  </blockquote>
  
  <p>SPEC/SPEC_HELPER.RB</p>
  
  <blockquote>
    <p>require 'rubygems' require 'spork'</p>
    
    <p>Spork.prefork do   # Loading more in this block will cause your tests
    to run faster. However,   # if you change any configuration or code
    from libraries loaded here, you'll   # need to restart spork for it
    take effect.   # This file is copied to spec/ when you run 'rails
    generate rspec:install'   ENV["RAILS_ENV"] ||= 'test'   require
    File.expand_path("../../config/environment", <strong>FILE</strong>)   require
    'rspec/rails'</p>
    
    <p># Requires supporting ruby files with custom matchers and macros,
    etc,   # in spec/support/ and its subdirectories.<br>
    Dir[Rails.root.join("spec/support/*<em>/</em>.rb")].each {|f| require f}</p>
    
    <p>RSpec.configure do |config|
        # == Mock Framework
        #
        # If you prefer to use mocha, flexmock or RR, uncomment the
    appropriate line:
        #
        # config.mock_with :mocha
        # config.mock_with :flexmock
        # config.mock_with :rr
        config.mock_with :rspec</p>
  
  <pre><code># Remove this line if you're not using ActiveRecord or
  </code></pre>
    
    <p>ActiveRecord fixtures
        # config.fixture_path = "#{::Rails.root}/spec/fixtures"</p>
  
  <pre><code># If you're not using ActiveRecord, or you'd prefer not to run
  </code></pre>
    
    <p>each of your
        # examples within a transaction, remove the following line or
    assign false
        # instead of true.
        config.use_transactional_fixtures = true   end</p>
    
    <p>end</p>
    
    <p>Spork.each_run do   # This code will be run each time you run your
    specs.</p>
    
    <p>end</p>
  </blockquote>