title: Rspec - Test that rails view renders a specific partial
body: <p>I have a rails 3.2.13 app running rspec-rails 2.14.0 and am trying to confirm that a view renders a particular partial in my test. It actually <em>does</em> work, but I need to add this test. Here's what I have so far:</p>
  
  <pre><code>require 'spec_helper'
  
  describe 'users/items/index.html.haml' do
    let(:current_user) { mock_model(User) }
  
    context 'when there are no items for this user' do
      items = nil
  
      it 'should render empty inventory partial' do
        response.should render_template(:partial =&gt; "_empty_inventory")
      end
  
    end
  end
  </code></pre>
  
  <p>This runs without error, but does not pass. The failure is:</p>
  
  <pre><code>Failure/Error: response.should render_template(:partial =&gt; "_empty_inventory")
     expecting partial &lt;"_empty_inventory"&gt; but action rendered &lt;[]&gt;
  </code></pre>
  
  <p>Thanks for any ideas.</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>This works for me, but Peter's solution is better... </p>
  
  <pre><code>context 'when there are no items for this user' do
  
    before do
      view.stub(current_user: current_user)
      items = nil
      render
    end
  
    it 'should render empty inventory partial' do
      view.should render_template(:partial =&gt; "_empty_inventory")
    end
  
  end 
  </code></pre>
  
  <p>For some reason it was counter-intuitive to me to have to call <code>render</code> on a view, but there you go...</p>