require 'spec_helper' describe RubyRides::Client do before do @client = RubyRides::Client.new(client_id: 'gandalf', client_api_key: 'asdf') end describe '.initialize' do it 'returns a valid client when passed a client_id and client_api_key in the options hash' do expect(@client).to be_a RubyRides::Client end it 'raises an ArgumentError when creating a client without client_id and/or client_api_key' do expect{RubyRides::Client.new()}.to raise_error(ArgumentError) end end describe '.client_id' do it 'returns client_id of the client it\'s called on' do expect(@client.client_id).to eq('gandalf') end end describe '.client_api_key' do it 'returns client_api_key of the client it\'s called on' do expect(@client.client_api_key).to eq('asdf') end end describe '.station_data' do before do stub_request(:get, "http://hubwaydatachallenge.org/api/v1/station/?format=json&username=gandalf&api_key=asdf").to_return(body: fixture('station_data.json')) end it 'makes a get request which retrieves a set of data including all Hubway stations' do data = @client.station_data expect(a_request(:get, "http://hubwaydatachallenge.org/api/v1/station/?format=json&username=gandalf&api_key=asdf")).to have_been_made expect(data['objects'].first['id']).to eq(3) end end describe '.station_geo_locations' do before do stub_request(:get, "http://hubwaydatachallenge.org/api/v1/station/?format=json&username=gandalf&api_key=asdf").to_return(body: fixture('station_data.json')) end it 'makes a get request which retrieves a set of data including all Hubway stations' do @client.station_geo_locations expect(a_request(:get, "http://hubwaydatachallenge.org/api/v1/station/?format=json&username=gandalf&api_key=asdf")).to have_been_made end it 'returns a hash of Hubway station latitudes/longitudes with station names as keys' do hash = @client.station_geo_locations expect(hash['Colleges of the Fenway']).to eq([-71.100812, 42.340021]) end end end