title: Rspec controller tests with chaining method calls
body: <p>My controller looks like this:</p>
  
  <pre class="lang-rb prettyprint-override"><code>def index
    params[:page]||1
    @stories = Story.all.page(params[:page]).per(5)
  end
  </code></pre>
  
  <p>When I try to write controller tests for the chaining line through using RSpec, I can't seem to get the tests to pass.</p>
  
  <p>My controller_spec looks something like:</p>
  
  <pre class="lang-rb prettyprint-override"><code>describe '#index' do
    let(:story) {double(Story)}
    before do
      allow(Story).to receive(:all).and_return(story)
      allow(story).to receive(:page).and_return(story)
      allow(story).to receive(:per).and_return(story)                                                                                                         
      get :index
    end
    context 'when user is not logged in' do
      it 'should get page 1' do                                                                                                
        expect(story).to receive(:page).with(1)                                                                                                               
      end
      it 'should get 5 stories' do
        expect(story).to receive(:per).with(5)                                                                                                                
      end
    end
  end 
  </code></pre>
  
  <p>What would be good example test to write for such a controller?</p>