title: Correct way to stub a class method with a mock object that has a expectation set on it in Rspec 3
body: <p>Here's a working test, which Rspec tells me is now wrong because <code>stub!</code> is deprecated:</p>
  
  <pre><code>it 'paginates the right number of times' do
    mock_thing = mock_model(User)
    User.stub!(:page).and_return(mock_thing)
    mock_thing.should_receive(:per).with(50)
    get :index
  end
  </code></pre>
  
  <p>What's the right way to do this? I tried the code below, but it fails:</p>
  
  <pre><code>it 'paginates the right number of times' do
    mock_thing = mock_model(User)
    mock_thing.should_receive(:per).with(50)
    User.stub(:page, mock_thing) do
      get :index
    end
  end
  
  # Error:
  # RSpec::Mocks::MockExpectationError: Double "User_1001" received unexpected 
  # message :[]= with (:expected_from, ...Stacktrace removed
  </code></pre>