2019-07-25 01:21:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-12-12 11:20:23 -05:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe Bitbucket::Paginator do
|
|
|
|
let(:last_page) { double(:page, next?: false, items: ['item_2']) }
|
|
|
|
let(:first_page) { double(:page, next?: true, next: last_page, items: ['item_1']) }
|
|
|
|
|
|
|
|
describe 'items' do
|
|
|
|
it 'return items and raises StopIteration in the end' do
|
|
|
|
paginator = described_class.new(nil, nil, nil)
|
|
|
|
|
|
|
|
allow(paginator).to receive(:fetch_next_page).and_return(first_page)
|
|
|
|
expect(paginator.items).to match(['item_1'])
|
|
|
|
|
|
|
|
allow(paginator).to receive(:fetch_next_page).and_return(last_page)
|
|
|
|
expect(paginator.items).to match(['item_2'])
|
|
|
|
|
|
|
|
allow(paginator).to receive(:fetch_next_page).and_return(nil)
|
2017-08-09 05:52:22 -04:00
|
|
|
expect { paginator.items }.to raise_error(StopIteration)
|
2016-12-12 11:20:23 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|