require 'spec_helper' describe UndergroundWeather::ApiCall do before do @api_key = 'apikey' @feature = 'forecast' @query = '19106' @uw = UndergroundWeather::ApiCall.new(@api_key, @feature, @query) end it "can be initialized with api_key, forecast, and query" do @uw.must_be_instance_of(UndergroundWeather::ApiCall) end it "should not have an error if no call has been made" do @uw.error.must_equal(false) end it "should have an error if http response code is not 200" do http_response = mock() http_response.expects(:code).returns('404') Net::HTTP.stubs(:get_response).returns(http_response) @uw.get! @uw.error.must_equal(true) end it "should not have an error if http response code is 200" do http_response = mock() http_response.expects(:code).returns('200') http_response.expects(:body).returns({}) Net::HTTP.stubs(:get_response).returns(http_response) @uw.get! @uw.error.must_equal(false) end it "should return correct url" do @uw.url.to_s.must_equal(URI.parse("http://api.wunderground.com/api/apikey/forecast/q/19106.json").to_s) end end