title: Rspec is using my development DB
body: <p>I'm using Rspec for testing. However, it uses my development DB instead of my test DB. How can this occur?</p>
  
  <p>I simply use rspec to run my tests: <code>don:my_project_root $ rspec</code></p>
  
  <p>It seems like the common mistakes from other questions are only relevant to Rails 3 or are pretty outdated (using commands you no longer use with rspec).</p>
  
  <p>Below is my spec_helper.rb.</p>
  
  <pre><code>ENV["RAILS_ENV"] = 'test'
  require File.expand_path("../../config/environment", __FILE__)
  require 'rspec/rails'
  require 'rspec/autorun'
  require "capybara/rspec" 
  require 'database_cleaner'
  
  # Requires supporting ruby files with custom matchers and macros, etc,
  # in spec/support/ and its subdirectories.
  Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
  
  # Checks for pending migrations before tests are run.
  # If you are not using ActiveRecord, you can remove this line.
  # ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)
  
  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
  
    # 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 # commented-out during tim's tutorial
  
    # Rails cast tutorial
    config.before(:suite) do
      DatabaseCleaner.strategy = :truncation
    end
  
    config.before(:each) do
      DatabaseCleaner.start
    end
  
    config.after(:each) do
      DatabaseCleaner.clean
    end
  
    # If true, the base class of anonymous controllers will be inferred
    # automatically. This will be the default behavior in future versions of
    # rspec-rails.
    config.infer_base_class_for_anonymous_controllers = false
  
    # Run specs in random order to surface order dependencies. If you find an
    # order dependency and want to debug it, you can fix the order by providing
    # the seed, which is printed after each run.
    #     --seed 1234
    config.order = "random"
  
    config.include FactoryGirl::Syntax::Methods
  
    config.include Capybara::DSL
  end
  </code></pre>
  
  <p>database.yml</p>
  
  <pre><code>development:
    adapter: sqlite3
    database: db/development.sqlite3
    pool: 5
    timeout: 5000
  
  # Warning: The database defined as "test" will be erased and
  # re-generated from your development database when you run "rake".
  # Do not set this db to the same as development or production.
  test:
    adapter: sqlite3
    database: db/test.sqlite3
    pool: 5
    timeout: 5000
  
  production:
    adapter: sqlite3
    database: db/production.sqlite3
    pool: 5
    timeout: 5000
  </code></pre>