title: Testing a model spec that uses an after_create callback
body: <p>Here is a model that I'm using, I've simplified it a bit down to the simplest form that still fails my example:</p>
  
  <pre><code>class User &lt;  ActiveRecord::Base
    after_create :setup_lists
  
    def setup_lists
      List.create(:user_id =&gt; self.id, :name =&gt; "current")
      List.create(:user_id =&gt; self.id, :name =&gt; "master")
    end
  end
  </code></pre>
  
  <p>And I'd like to spec the example as follows:</p>
  
  <pre><code>require 'spec_helper'
  
  describe User do
    before(:each) do
      @user = Factory(:user)
    end
  
    describe "#setup_lists" do
      before(:each) do  
       List.stub(:create).with(:name =&gt; "current")
       List.stub(:create).with(:name =&gt; "master")
  
       it "creates a new master list" do
          List.should_receive(:create).with(:name =&gt; "master")
       end
  
       it "creates a new current list" do
          List.should_receive(:create).with(:name =&gt; "current")
       end
    end
  end
  </code></pre>
  
  <p>Which I expected would work just fine, but I am left with the following error:</p>
  
  <pre><code>Failures:
    1) User#setup_lists creates a new master list
       Failure/Error: List.should_receive(:create).with(:name =&gt; "current")
       (&lt;List(id: integer, name: string, created_at: datetime, updated_at: datetime, user_id: integer) (class)&gt;).create({:name=&gt;"current"})
        expected: 1 time
        received: 0 times
      # ./spec/models/user_spec.rb:44
  
    2) User#setup_lists creates a new current list
       Failure/Error: List.should_receive(:create).with(:name =&gt; "master")
       (&lt;List(id: integer, name: string, created_at: datetime, updated_at: datetime,        user_id: integer) (class)&gt;).create({:name=&gt;"master"})
       expected: 1 time
       received: 0 times
    # ./spec/models/user_spec.rb:48
  </code></pre>
  
  <p>Can anybody help me understand why this is happening?</p>