require "spec_helper" require_relative "../../lib/dribbble_bucket_api/shot_index_parser" describe DribbbleBucketApi::ShotIndexParser do let(:body) do %Q(

212 Shots

) end let(:connection) do mock("connection", username: "ryantownsend") end let(:options) do { page: 2, connection: connection } end subject do DribbbleBucketApi::ShotIndexParser.new(body, options) end describe "#shots" do it "should return an item for each shot in the list" do expect(subject.shots.size).to eq 2 end it "should return Shot instances" do subject.shots.each do |shot| expect(shot).to be_kind_of DribbbleBucketApi::Shot end end it "should parse the ids correctly" do ids = subject.shots.map(&:id) expect(ids).to eq [693587, 693929] end it "should parse the extensions correctly" do ids = subject.shots.map(&:ext) expect(ids).to eq ["png", "jpg"] end end describe "#current_page" do it "should return the options page" do expect(subject.current_page).to eq 2 end end describe "#next_page" do context "when total_pages > current_page" do before do subject.stub(:current_page).and_return(2) subject.stub(:total_pages).and_return(3) end it "should return current_page + 1" do expect(subject.next_page).to eq 3 end end context "when total_pages <= current_page" do before do subject.stub(:current_page).and_return(3) subject.stub(:total_pages).and_return(3) end it "should return nil" do expect(subject.next_page).to be_nil end end end describe "#previous_page" do context "when current_page > 1" do before do subject.stub(:current_page).and_return(3) end it "should return current_page - 1" do expect(subject.previous_page).to eq 2 end end context "when current_page <= 1" do before do subject.stub(:current_page).and_return(1) end it "should return nil" do expect(subject.previous_page).to be_nil end end end describe "#total_entries" do it "should return count from the HTML document" do expect(subject.total_entries).to eq 212 end end describe "#total_pages" do it "should return the total / 15" do expect(subject.total_pages).to eq 15 end end end