Sha256: d0a2992e34916fbf784db210179f0d5af0220f33ec7bd3b4b129965e0a4edff9

Contents?: true

Size: 1.83 KB

Versions: 2

Compression:

Stored size: 1.83 KB

Contents

require 'spec_helper'

#useless purely integration tests... remove?
module RubyHackernews
  describe EntryService do

    describe :get_entries do

      it "should always call EntryPageParser with current agent" do
        parser = stub()
        parser.should_receive(:get_lines).and_return([])
        parser.should_receive(:get_next_url).and_return(nil)
        agent = stub()
        agent.should_receive(:get).any_number_of_times.and_return(:page)
        MechanizeContext.create(:default, agent)
        service = EntryService.new
        EntryPageParser.should_receive(:new).any_number_of_times.with(:page).and_return(parser)
        service.get_entries
      end

      it "should always call get_lines 'pages' number of times" do
        pages  = 5
        parser = stub()
        parser.should_receive(:get_lines).exactly(pages).times.and_return([])
        parser.should_receive(:get_next_url).any_number_of_times.and_return(nil)
        agent = stub()
        agent.should_receive(:get).any_number_of_times.and_return(:page)
        MechanizeContext.create(:default, agent)
        service = EntryService.new
        EntryPageParser.should_receive(:new).any_number_of_times.with(:page).and_return(parser)
        service.get_entries(pages)
      end

      it "should always call get_next_url 'pages' number of times" do
        pages  = 5
        parser = stub()
        parser.should_receive(:get_lines).any_number_of_times.and_return([])
        parser.should_receive(:get_next_url).exactly(pages).times.and_return(nil)
        agent = stub()
        agent.should_receive(:get).any_number_of_times.and_return(:page)
        MechanizeContext.create(:default, agent)
        service = EntryService.new
        EntryPageParser.should_receive(:new).any_number_of_times.with(:page).and_return(parser)
        service.get_entries(pages)
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruby-hackernews-1.3.6 spec/HNAPI/services/entries/entry_service_spec.rb
ruby-hackernews-1.3.5 spec/HNAPI/services/entries/entry_service_spec.rb