spec/HNAPI/services/entries/entry_service_spec.rb in ruby-hackernews-1.3.6 vs spec/HNAPI/services/entries/entry_service_spec.rb in ruby-hackernews-1.3.7

- old
+ new

@@ -5,44 +5,42 @@ 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) + parser = Object.new + allow(parser).to receive_messages(:get_lines => [], :get_next_url => nil) + agent = Object.new + allow(agent).to receive_messages(:get => :page) + MechanizeContext.send(:class_variable_set, :@@contexts, {:default => agent}) service = EntryService.new - EntryPageParser.should_receive(:new).any_number_of_times.with(:page).and_return(parser) + expect(EntryPageParser).to receive(:new).at_least(1).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) + parser = Object.new + expect(parser).to receive(:get_lines).and_return([]) + allow(parser).to receive(:get_next_url).and_return(nil) + agent = Object.new + allow(agent).to receive_messages(:get => :page) + MechanizeContext.send(:class_variable_set, :@@contexts, {:default => agent}) service = EntryService.new - EntryPageParser.should_receive(:new).any_number_of_times.with(:page).and_return(parser) - service.get_entries(pages) + allow(EntryPageParser).to receive(:new).with(:page).and_return(parser) + service.get_entries 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) + parser = Object.new + allow(parser).to receive(:get_lines).and_return([]) + expect(parser).to receive(:get_next_url).and_return(nil) + agent = Object.new + allow(agent).to receive_messages(:get => :page) + MechanizeContext.send(:class_variable_set, :@@contexts, {:default => agent}) service = EntryService.new - EntryPageParser.should_receive(:new).any_number_of_times.with(:page).and_return(parser) - service.get_entries(pages) + allow(EntryPageParser).to receive(:new).with(:page).and_return(parser) + service.get_entries end end end end