outoftime / noaa

Ruby API for National Oceanic and Atmospheric Association (National Weather Service) weather data

This URL has Read+Write access

noaa / test / test_http_service.rb
100644 58 lines (45 sloc) 1.667 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require File.join(File.dirname(__FILE__), 'test_helper')
 
class TestHttpService < NOAA::TestCase
  before :each do
    HTTP.reset
  end
 
  test 'should send properly-formed URL for current conditions' do
    http_service.get_current_conditions('KNYC')
    HTTP.requests.should == [URI.parse('http://www.weather.gov/xml/current_obs/KNYC.xml')]
  end
 
  test 'should return XML document for current conditions' do
    http_service.get_current_conditions('KNYC').to_s.should == %Q{<?xml version="1.0" encoding="UTF-8"?>\n<test/>\n}
  end
 
  test 'should send properly-formed URL for forecast' do
    http_service.get_forecast(4, 40.72, -73.99)
    HTTP.requests.should == [URI.parse('http://www.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?lat=40.72&lon=-73.99&format=24+hourly&numDays=4')]
  end
 
  test 'should return XML document for forecast' do
    http_service.get_forecast(4, 40.72, -73.99).to_s.should == %Q{<?xml version="1.0" encoding="UTF-8"?>\n<test/>\n}
  end
 
  test 'should send properly-formed URL for station list' do
    http_service.get_station_list
    HTTP.requests.should == [URI.parse('http://www.weather.gov/xml/current_obs/index.xml')]
  end
 
  test 'should return XML document for station list' do
    http_service.get_station_list.to_s.should == %Q{<?xml version="1.0" encoding="UTF-8"?>\n<test/>\n}
  end
 
  private
 
  def http_service
    NOAA::HttpService.new(HTTP)
  end
 
  module HTTP
    class <<self
      def reset
        requests.clear
      end
 
      def requests
        @requests ||= []
      end
 
      def get(uri)
        requests << uri
        "<test/>"
      end
    end
  end
end