outoftime / noaa

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

This URL has Read+Write access

noaa / test / test_station.rb
100644 66 lines (49 sloc) 1.726 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
59
60
61
62
63
64
65
66
require File.join(File.dirname(__FILE__), 'test_helper')
 
class TestStation < NOAA::TestCase
  before :all do
    NOAA::Station.stations_file = File.join(File.dirname(__FILE__), 'data', 'stations.yml')
  end
 
  after :all do
    NOAA::Station.stations_file = nil
  end
 
  test 'should load station by id' do
    NOAA::Station.find('KNYC').id.should == 'KNYC'
  end
 
  test 'should find closest to coordinates' do
    NOAA::Station.closest_to(GeoKit::LatLng.new(40.8, -73.96)).id.should == 'KNYC'
  end
 
  test 'should find closest to lat/lng' do
    NOAA::Station.closest_to(40.8, -73.96).id.should == 'KNYC'
  end
 
  test 'should find closest to lat/lng passed as array' do
    NOAA::Station.closest_to([40.8, -73.96]).id.should == 'KNYC'
  end
 
  test 'should throw ArgumentError if bad argument passed into #closest_to()' do
    lambda { NOAA::Station.closest_to('hey') }.should raise_error(ArgumentError)
  end
 
  test 'should throw ArgumentError if more than two arguments passed into #closest_to()' do
    lambda { NOAA::Station.closest_to(1, 2, 3) }.should raise_error(ArgumentError)
  end
 
  test 'should return name' do
    station.name.should == 'New York City, Central Park'
  end
 
  test 'should return state' do
    station.state.should == 'NY'
  end
 
  test 'should return XML URL' do
    station.xml_url.should == 'http://weather.gov/xml/current_obs/KNYC.xml'
  end
 
  test 'should return latitude' do
    station.latitude.should == 40.783
  end
 
  test 'should return longitude' do
    station.longitude.should == -73.967
  end
 
  test 'should return coordinates' do
    station.coordinates.should == GeoKit::LatLng.new(40.783, -73.967)
  end
 
  private
 
  def station
    NOAA::Station.find('KNYC')
  end
end