我的控制器如下所示:
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
为这样的控制器编写什么是好的示例测试?