私のコントローラーは次のようになります。
def index
params[:page]||1
@stories = Story.all.page(params[:page]).per(5)
end
RSpec を使用してチェーン ラインのコントローラー テストを作成しようとすると、テストに合格できないようです。
私の controller_spec は次のようになります。
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
このようなコントローラー用に作成する良いサンプル テストは何でしょうか?