title: RailsTutorial - chapter 8.4.3 - Test database not clearing after adding user in integration test
body: <p>I'm stumped on this one.</p>
  
  <p>Everything on the tutorial has gone smoothly so far, but when I add this chunk of code to my /spec/requests/users_spec.rb file, things start to go south:</p>
  
  <pre><code>describe "success" do
  
    it "should make a new user" do
      lambda do
        visit signup_path
          fill_in "Name",         :with =&gt; "Example User"
          fill_in "Email",        :with =&gt; "ryan@example.com"
          fill_in "Password",     :with =&gt; "foobar"
          fill_in "Confirmation", :with =&gt; "foobar"
          click_button
          response.should have_selector("div.flash.success",
                                        :content =&gt; "Welcome")
          response.should render_template('users/show')
          end.should change(User, :count).by(1)
        end
      end
  </code></pre>
  
  <p>If i clear the test database ( rake db:test:prepare ), all of the tests pass.  But if i run the tests again, they fail because the test database doesn't clear the record that the code above added.  </p>
  
  <p>I've googled quite a bit, and most of what i found pointed either to the config.use_transactional_fixtures setting, or to a nesting issue in the code.</p>
  
  <p>I'm pretty sure that neither of these is the case for me.  Here is my spec_helper.rb file:</p>
  
  <pre><code>require 'rubygems'
  require 'spork'
  
  Spork.prefork do
    ENV["RAILS_ENV"] ||= 'test'
    require File.expand_path("../../config/environment", __FILE__)
    require 'rspec/rails'
  
  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}
  
    RSpec.configure do |config|
      config.mock_with :rspec
      config.fixture_path = "#{::Rails.root}/spec/fixtures"
      config.use_transactional_fixtures = true
  
      # Needed for Spork
      ActiveSupport::Dependencies.clear
    end 
  
  end
  
  Spork.each_run do
    load "#{Rails.root}/config/routes.rb"
    Dir["#{Rails.root}/app/**/*.rb"].each { |f| load f } 
  end
  </code></pre>
  
  <p>and here is my users_spec.rb:</p>
  
  <pre><code>describe "Users" do
  
    describe "signup" do
  
      describe "failure" do
  
        it "should not make a new user" do
          lambda do
            visit signup_path
            fill_in "Name",         :with =&gt; ""
            fill_in "Email",        :with =&gt; ""
            fill_in "Password",     :with =&gt; ""
            fill_in "Confirmation", :with =&gt; ""
            click_button
            response.should render_template('users/new')
            response.should have_selector("div#error_explanation")
          end.should_not change(User, :count)
        end 
      end 
  
  
      describe "success" do
  
        it "should make a new user" do
          lambda do
            visit signup_path
            fill_in "Name",         :with =&gt; "Example User"
            fill_in "Email",        :with =&gt; "ryan@example.com"
            fill_in "Password",     :with =&gt; "foobar"
            fill_in "Confirmation", :with =&gt; "foobar"
            click_button
            response.should have_selector("div.flash.success",
                                          :content =&gt; "Welcome")
            response.should render_template('users/show')
          end.should change(User, :count).by(1)
        end 
      end 
    end 
  end
  </code></pre>
  
  <p>Any ideas?  Thanks.</p>
  
  <p>With mpapis answer, i was able to get this working.  Here is my updated spec/requests/user_spec.rb file:</p>
  
  <pre><code>require 'spec_helper'
  require 'database_cleaner'
  DatabaseCleaner.strategy = :truncation
  
  describe "Users" do
  
    describe "signup" do
  
      describe "failure" do
  
        it "should not make a new user" do
          lambda do
            visit signup_path
            fill_in "Name",         :with =&gt; ""
            fill_in "Email",        :with =&gt; ""
            fill_in "Password",     :with =&gt; ""
            fill_in "Confirmation", :with =&gt; ""
            click_button
            response.should render_template('users/new')
            response.should have_selector("div#error_explanation")
          end.should_not change(User, :count)
        end 
      end 
  
  
      describe "success" do
  
        it "should make a new user" do
          lambda do
            visit signup_path
            fill_in "Name",         :with =&gt; "Example User"
            fill_in "Email",        :with =&gt; "ryan@example.com"
            fill_in "Password",     :with =&gt; "foobar"
            fill_in "Confirmation", :with =&gt; "foobar"
            click_button
            response.should have_selector("div.flash.success",
                                          :content =&gt; "Welcome")
            response.should render_template('users/show')
          end.should change(User, :count).by(1)
          DatabaseCleaner.clean
        end 
      end 
    end 
  end
  </code></pre>