title: RSpec + FactoryGirl should_receive failing
body: <p>I can't figure out why this RSpec test fails. Any advice? I'm new-ish to FactoryGirl, RSpec, and TDD in general.</p>
  
  <h3>Controller:</h3>
  
  <pre><code>def update
    @vendor = current_user.vendors.find(params[:id])
  
    if @vendor.update_attributes(params[:vendor])
      redirect_to vendor_path(@vendor)
    else
      render 'edit'
    end
  end
  </code></pre>
  
  <h3>Test:</h3>
  
  <pre><code>require 'spec_helper'
  
  describe VendorsController do
    login_user
  
    before :each do
      @user = subject.current_user
      @vendor = FactoryGirl.create(:vendor, :user =&gt; @user)
    end
  
    [...]
  
    describe 'POST update' do
      def do_update
        post :update, :id =&gt; @vendor.id, :vendor =&gt; FactoryGirl.attributes_for(:vendor)
      end
  
      [...]
  
      it 'should update a given vendor' do
        do_update
        @vendor.should_receive(:update_attributes).with(FactoryGirl.attributes_for(:vendor))
      end
    end
  end
  </code></pre>
  
  <h3>Factory:</h3>
  
  <pre><code>FactoryGirl.define do
    factory :vendor do
      name 'Widget Vendor'
      user
    end
  end
  </code></pre>
  
  <h3>The Failure:</h3>
  
  <pre><code>Failures:
  
    1) VendorsController POST update should update a given vendor
       Failure/Error: @vendor.should_receive(:update_attributes).with(FactoryGirl.attributes_for(:vendor))
         (#&lt;Vendor:0x007faeb75e77d0&gt;).update_attributes({:name=&gt;"Widget Vendor"})
             expected: 1 time
             received: 0 times
       # ./spec/controllers/vendors_controller_spec.rb:108:in `block (3 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <h3><em>Update:</em></h3>
  
  <p>I'm a little closer, now. I changed the test to the following:</p>
  
  <pre><code>it 'should update a given vendor' do
    Vendor.any_instance.should_receive(:update_attributes).with(FactoryGirl.attributes_for(:vendor))
    do_update
  end
  </code></pre>
  
  <p>And the new error is:</p>
  
  <pre><code>Failures:
  
    1) VendorsController POST update should update a given vendor
       Failure/Error: post :update, :id =&gt; @vendor.id, :vendor =&gt; FactoryGirl.attributes_for(:vendor)
         #&lt;Vendor:0x007ff30d765900&gt; received :update_attributes with unexpected arguments
           expected: ({:name=&gt;"Widget Vendor"})
                got: ({"name"=&gt;"Widget Vendor"})
       # ./app/controllers/vendors_controller.rb:33:in `update'
       # ./spec/controllers/vendors_controller_spec.rb:98:in `do_update'
       # ./spec/controllers/vendors_controller_spec.rb:108:in `block (3 levels) in &lt;top (required)&gt;'
  </code></pre>
  
  <h3>Answer...?</h3>
  
  <p>Well, this worked. There has to be a better way of doing this, though:</p>
  
  <p><code>Vendor.any_instance.should_receive(:update_attributes).with(JSON.parse(FactoryGirl.attributes_for(:vendor).to_json)).and_return(true)</code></p>