Sha256: a833f2fbc2a5fce461fc642018cea6f4dfee1d8d40a10e4ca9332be55578cbe4

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

describe "Search" do
  let :connection do
    double(:connection, get: nil)
  end

  let :la_search_response do
    File.read(File.expand_path("spec/responses/la_search_response.json"))
  end

  let :no_location_search_response do
    File.read(File.expand_path("spec/responses/no_location_response.json"))
  end

  let :invalid_search_response do
    File.read(File.expand_path("spec/responses/invalid_key_response.json"))
  end

  before :each do
    Parkwhiz.api_key = 'asdf1234'
  end

  context 'on empty search results' do
    it "should return an emtpy Array" do
      expect(connection).to receive(:get) { double( body: JSON.parse(no_location_search_response) ) }
      Parkwhiz.connection = connection
      locations = Parkwhiz.search({})
      expect(locations).to be_kind_of(Array)
      expect(locations).to be_empty

    end
  end
  context "on successful search" do
    it "should return an array of Parkwhiz::Locations" do
      expect(connection).to receive(:get) { double( body: JSON.parse(la_search_response) ) }
      Parkwhiz.connection = connection
      locations = Parkwhiz.search({})
      expect(locations).to be_kind_of(Array)
      expect(locations.first).to be_kind_of(Parkwhiz::Location)
    end
  end

  context 'on error' do
    it "should raise a Parkwhiz::SearchError" do
      expect(connection).to receive(:get) { double( body: JSON.parse(invalid_search_response) ) }
      Parkwhiz.connection = connection
      expect do
        Parkwhiz.search({})
      end.to raise_error(Parkwhiz::SearchError)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
parkwhiz-0.4.0 spec/search_spec.rb