Sha256: 2f4b43034b9a7c60830d0a3cd5200d7d8d53cb6f37442499e64eba56e0535637

Contents?: true

Size: 1.14 KB

Versions: 2

Compression:

Stored size: 1.14 KB

Contents

require 'spec_helper'

describe GeoNamesAPI::Base do
  describe "retries" do
    before :each do
      GeoNamesAPI.stub(:max_sleep_time_between_retries).and_return(0)
      @timeout = JSON.load <<-JSON
        {
          "status": {
            "message": "ERROR: canceling statement due to statement timeout",
            "value": 13
          }
        }
      JSON
      # This is not a correct, complete response, but that's not relevant to the spec:
      @response = JSON.load <<-JSON
        {"geonames": [{ "name": "Earth" }]}
      JSON
    end

    it "retries when geonames returns timeout errors" do
      GeoNamesAPI::Hierarchy.stub(:make_request).and_return(@timeout, @response)
      hierarchy = GeoNamesAPI::Hierarchy.find(6295630)
      earth = hierarchy.first
      earth.should be_present
      earth.name.should == "Earth"
    end

    it "fails when geonames returns timeout errors too many times" do
      GeoNamesAPI::Hierarchy.stub(:make_request).and_return(@timeout, @timeout, @response)
      GeoNamesAPI.stub(:retries).and_return(1)
      proc { GeoNamesAPI::Hierarchy.find(6295630) }.should raise_error GeoNamesAPI::Timeout
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
geonames_api-0.1.4 spec/geonames_api/retry_spec.rb
geonames_api-0.1.3 spec/geonames_api/retry_spec.rb