diff --git a/.rspec b/.rspec
new file mode 100644
index 0000000..5f16476
--- /dev/null
+++ b/.rspec
@@ -0,0 +1,2 @@
+--color
+--format progress
diff --git a/Gemfile.lock b/Gemfile.lock
new file mode 100644
index 0000000..bb6083d
--- /dev/null
+++ b/Gemfile.lock
@@ -0,0 +1,36 @@
+PATH
+ remote: .
+ specs:
+ noaa (0.2.3)
+ geokit (>= 1.5.0)
+ nokogiri (>= 0.9.7)
+
+GEM
+ remote: https://rubygems.org/
+ specs:
+ diff-lcs (1.2.5)
+ geokit (1.8.4)
+ multi_json (>= 1.3.2)
+ jnunemaker-matchy (0.4.0)
+ mcmire-context (0.5.6)
+ mini_portile (0.5.2)
+ multi_json (1.8.4)
+ nokogiri (1.6.1)
+ mini_portile (~> 0.5.0)
+ rspec (2.14.1)
+ rspec-core (~> 2.14.0)
+ rspec-expectations (~> 2.14.0)
+ rspec-mocks (~> 2.14.0)
+ rspec-core (2.14.8)
+ rspec-expectations (2.14.5)
+ diff-lcs (>= 1.1.3, < 2.0)
+ rspec-mocks (2.14.6)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ jnunemaker-matchy (>= 0.4.0)
+ mcmire-context (>= 0.0.16)
+ noaa!
+ rspec
diff --git a/lib/noaa/station.rb b/lib/noaa/station.rb
index 1a23df9..fcdd79b 100644
--- a/lib/noaa/station.rb
+++ b/lib/noaa/station.rb
@@ -31,7 +31,7 @@ def find(id)
#
# NOAA::Station.closest_to(37.989, -77.507)
# NOAA::Station.closest_to([37.989, -77.507])
- # NOAA::Station.closest_to(GeoKit::LatLng.new(37.989, -77.507))
+ # NOAA::Station.closest_to(Geokit::LatLng.new(37.989, -77.507))
def closest_to(*args)
if args.length == 1
if args.first.respond_to?(:distance_to)
@@ -39,19 +39,19 @@ def closest_to(*args)
elsif %w(first last).all? { |m| args.first.respond_to?(m) }
closest_to_lat_lng(args.first)
else
- raise ArgumentError, "expected two-element Array or GeoKit::LatLng"
+ raise ArgumentError, "expected two-element Array or Geokit::LatLng"
end
elsif args.length == 2
closest_to_lat_lng(args)
else
- raise ArgumentError, "closest_to() will accept one Array argument, one GeoKit::LatLng argument, or two FixNum arguments"
+ raise ArgumentError, "closest_to() will accept one Array argument, one Geokit::LatLng argument, or two FixNum arguments"
end
end
private
def closest_to_lat_lng(pair)
- closest_to_coordinates(GeoKit::LatLng.new(pair.first, pair.last))
+ closest_to_coordinates(Geokit::LatLng.new(pair.first, pair.last))
end
def closest_to_coordinates(coordinates)
@@ -74,7 +74,7 @@ def stations_file
end
end
- # GeoKit::LatLng containing the station's coordinates
+ # Geokit::LatLng containing the station's coordinates
attr_reader :coordinates
# Station ID (e.g., "KNYC")
@@ -92,7 +92,7 @@ def initialize(properties)
@id, @name, @state, @xml_url = %w(id name state xml_url).map do |p|
properties[p]
end
- @coordinates = GeoKit::LatLng.new(properties['latitude'], properties['longitude'])
+ @coordinates = Geokit::LatLng.new(properties['latitude'], properties['longitude'])
end
# Latitude of station
diff --git a/noaa.gemspec b/noaa.gemspec
index c5f6148..4ff7c78 100644
--- a/noaa.gemspec
+++ b/noaa.gemspec
@@ -14,7 +14,7 @@ Gem::Specification.new do |s|
s.description = %q{Ruby API for National Oceanic and Atmospheric Administration weather data}
s.email = %q{mat@patch.com}
s.executables = ["noaa-update-stations"]
- s.files = Dir.glob('{bin,lib,test,data}/**/*') + %w(CHANGELOG README)
+ s.files = Dir.glob('{bin,lib,spec,data}/**/*') + %w(CHANGELOG README)
s.has_rdoc = true
s.homepage = %q{http://github.com/outoftime/noaa}
s.post_install_message = %q{Be sure to update the weather station list:
@@ -27,9 +27,8 @@ This can be run at any time to update the stations, but you must run it once to
s.rubyforge_project = %q{noaa}
s.rubygems_version = %q{1.3.1}
s.summary = %q{Ruby API for National Oceanic and Atmospheric Administration weather data}
- s.test_files = ["test/test_station_writer.rb", "test/test_forecast.rb", "test/test_helper.rb", "test/test_station.rb", "test/test_http_service.rb", "test/test_current_conditions.rb"]
+ s.test_files = ["spec/station_writer_spec.rb", "spec/forecast_spec.rb", "spec/spec_helper.rb", "spec/station_spec.rb", "spec/http_service_spec.rb", "spec/current_conditions_spec.rb"]
s.add_runtime_dependency('nokogiri', '>= 0.9.7')
s.add_runtime_dependency('geokit', '>= 1.5.0')
- s.add_development_dependency('mcmire-context', ">= 0.0.16")
- s.add_development_dependency('jnunemaker-matchy', ">= 0.4.0")
+ s.add_development_dependency('rspec')
end
diff --git a/spec/current_conditions_spec.rb b/spec/current_conditions_spec.rb
new file mode 100644
index 0000000..ff5a301
--- /dev/null
+++ b/spec/current_conditions_spec.rb
@@ -0,0 +1,212 @@
+require "spec_helper"
+
+describe NOAA do
+ describe NOAA::CurrentConditions do
+ let(:xml_doc) { LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'data', 'KVAY.xml')) }
+ let(:current_conditions) { NOAA::CurrentConditions.from_xml(xml_doc) }
+
+ describe "#observed_at" do
+ it "returns observation time" do
+ expect(current_conditions.observed_at)
+ .to eq Time.parse('2008-12-23 10:54:00 -0500')
+ end
+ end
+
+ describe "#weather_description" do
+ it "returns the weather description" do
+ expect(current_conditions.weather_description).to eq 'Fair'
+ end
+ end
+
+ describe "#weather_summary" do
+ it "returns the weather description" do
+ expect(current_conditions.weather_summary).to eq 'Fair'
+ end
+ end
+
+ describe "#weather_type_code" do
+ it "returns the weather type code" do
+ expect(current_conditions.weather_type_code).to eq :skc
+ end
+ end
+
+ describe "#temperature" do
+ context "when the unit is not specified" do
+ it "returns the temperature in farenheit" do
+ expect(current_conditions.temperature).to eq 24
+ end
+ end
+
+ context "when farenheit is specified" do
+ it "returns the temperature in farenheit" do
+ expect(current_conditions.temperature(:f)).to eq 24
+ end
+ end
+
+ context "when celsius is specified" do
+ it "returns the temperature in celsius" do
+ expect(current_conditions.temperature(:c)).to eq -4
+ end
+ end
+
+ context "when an unknown unit is specified" do
+ it "raises an Argument error" do
+ expect { current_conditions.temperature(:kelvin) }
+ .to raise_error ArgumentError
+ end
+ end
+ end
+
+ describe "#image_url" do
+ it "returns the image URL" do
+ expect(current_conditions.image_url)
+ .to eq 'http://weather.gov/weather/images/fcicons/skc.jpg'
+ end
+ end
+
+ describe "#relative_humidity" do
+ it "returns the relative humidity" do
+ expect(current_conditions.relative_humidity)
+ .to eq 52
+ end
+ end
+
+ describe "#wind_direction" do
+ it 'returns the wind direction' do
+ expect(current_conditions.wind_direction).to eq 'Northwest'
+ end
+ end
+
+ describe "#wind_degrees" do
+ it 'returns the wind degrees' do
+ expect(current_conditions.wind_degrees).to eq 330
+ end
+ end
+
+ describe "#wind_speed" do
+ it 'returns the wind speed in MPH' do
+ expect(current_conditions.wind_speed).to eq 3.45
+ end
+ end
+
+ describe "#wind_gust" do
+ it 'returns the wind gust in MPH' do
+ expect(current_conditions.wind_gust).to eq 10.25
+ end
+ end
+
+ describe "#pressure" do
+ context "when the unit is not specified" do
+ it 'returns the pressure in inches' do
+ expect(current_conditions.pressure).to eq 30.7
+ end
+ end
+
+ context "when the provided unit is 'in'" do
+ it 'returns the pressure in inches' do
+ expect(current_conditions.pressure(:in)).to eq 30.7
+ end
+ end
+
+ context "when the provided unit is 'mb'" do
+ it 'returns the pressure in millibars' do
+ expect(current_conditions.pressure(:mb)).to eq 1039.5
+ end
+ end
+
+ context "when the provided unit is not recognized" do
+ it 'raises an ArgumentError' do
+ expect { current_conditions.pressure(:psi) }.to raise_error(ArgumentError)
+ end
+ end
+ end
+
+
+ describe "#dew_point" do
+ context "when the unit is not specified" do
+ it 'returns the dew point in fahrenheit' do
+ expect(current_conditions.dew_point).to eq 9
+ end
+ end
+
+ context "when the provided unit is farenheit" do
+ it 'returns the dew point in fahrenheit' do
+ expect(current_conditions.dew_point(:f)).to eq 9
+ end
+ end
+
+ context "when the provided unit is celsius" do
+ it 'returns the dew point in celsius' do
+ expect(current_conditions.dew_point(:c)).to eq -13
+ end
+ end
+
+ context "when the provided unit is not recognized" do
+ it 'raises an ArgumentError' do
+ expect { current_conditions.dew_point(:kelvin) }
+ .to raise_error(ArgumentError)
+ end
+ end
+ end
+
+ describe "#heat_index" do
+ it 'returns the heat index in fahrenheit by default' do
+ expect(current_conditions.heat_index).to eq 105
+ end
+
+ context "when the provided unit is farenheit" do
+ it 'returns the heat index in fahrenheit' do
+ expect(current_conditions.heat_index(:f)).to eq 105
+ end
+ end
+
+ context "when the provided unit is celsius" do
+ it 'returns the heat index in celsius' do
+ expect(current_conditions.heat_index(:c)).to eq 41
+ end
+ end
+
+ context "when the provided unit is unrecognized" do
+ it 'raises an ArgumentError' do
+ expect { current_conditions.heat_index(:kelvin) }
+ .to raise_error(ArgumentError)
+ end
+ end
+
+ context "when the heat index is NA"
+ end
+
+ describe "#wind_chill" do
+ it 'returns the wind chill in fahrenheit by default' do
+ expect(current_conditions.wind_chill).to eq 19
+ end
+
+ context "when the provided unit is farenheit" do
+ it 'returns the wind chill in fahrenheit' do
+ expect(current_conditions.wind_chill(:f)).to eq 19
+ end
+ end
+
+ context "when the provided unit is celsius" do
+ it 'returns the wind chill in celsius' do
+ expect(current_conditions.wind_chill(:c)).to eq -7
+ end
+ end
+
+ context "when the provided unit is unrecognized" do
+ it 'raises an ArgumentError' do
+ expect { current_conditions.wind_chill(:kelvin) }.to raise_error(ArgumentError)
+ end
+ end
+
+ context "when the heat index is NA"
+ end
+
+
+ describe "#visibility" do
+ it 'returns the visibility in miles' do
+ expect(current_conditions.visibility).to eq 10.0
+ end
+ end
+ end
+end
diff --git a/test/data/4-day.xml b/spec/data/4-day.xml
similarity index 100%
rename from test/data/4-day.xml
rename to spec/data/4-day.xml
diff --git a/test/data/KVAY.xml b/spec/data/KVAY.xml
similarity index 100%
rename from test/data/KVAY.xml
rename to spec/data/KVAY.xml
diff --git a/test/data/stations-abridged.xml b/spec/data/stations-abridged.xml
similarity index 100%
rename from test/data/stations-abridged.xml
rename to spec/data/stations-abridged.xml
diff --git a/test/data/stations.xml b/spec/data/stations.xml
similarity index 100%
rename from test/data/stations.xml
rename to spec/data/stations.xml
diff --git a/test/data/stations.yml b/spec/data/stations.yml
similarity index 100%
rename from test/data/stations.yml
rename to spec/data/stations.yml
diff --git a/spec/forecast_spec.rb b/spec/forecast_spec.rb
new file mode 100644
index 0000000..5f87275
--- /dev/null
+++ b/spec/forecast_spec.rb
@@ -0,0 +1,90 @@
+require "spec_helper"
+
+describe NOAA do
+ describe NOAA::Forecast do
+ let(:xml_doc) { LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'data', '4-day.xml')) }
+ let(:forecast) { NOAA::Forecast.from_xml(xml_doc) }
+
+ describe "#length" do
+ it "returns the number of days" do
+ expect(forecast.length).to eq 4
+ end
+ end
+
+ describe "[i]#starts_at" do
+ it "return correct start time for each day" do
+ ['2008-12-23', '2008-12-24',
+ '2008-12-25', '2008-12-26'].each_with_index do |date, i|
+ expect(forecast[i].starts_at)
+ .to eq Time.parse("#{date} 06:00:00 -05:00")
+ end
+ end
+ end
+
+ describe "[i]#ends_at" do
+ it "return correct end time for each day" do
+ ['2008-12-24', '2008-12-25',
+ '2008-12-26', '2008-12-27'].each_with_index do |date, i|
+ expect(forecast[i].ends_at)
+ .to eq Time.parse("#{date} 06:00:00 -05:00")
+ end
+ end
+ end
+
+ describe "[i]#high" do
+ it "return correct high for each day" do
+ [32, 49, 43, 41].each_with_index do |temp, i|
+ expect(forecast[i].high).to eq temp
+ end
+ end
+ end
+
+ describe "a specification" do
+ it "returns the correct low for each day" do
+ [31, 41, 33, 39].each_with_index do |temp, i|
+ expect(forecast[i].low).to eq temp
+ end
+ end
+ end
+
+ describe "#weather_summary" do
+ it "returns the correct weather summary for each day" do
+ ['Rain', 'Rain', 'Slight Chance Rain', 'Chance Rain'].each_with_index do |summary, i|
+ expect(forecast[i].weather_summary).to eq summary
+ end
+ end
+ end
+
+ describe "#weather_type_code" do
+ it "returns the correct weather type code for each day" do
+ 4.times do |i|
+ expect(forecast[i].weather_type_code).to eq :ra
+ end
+ end
+ end
+
+ describe "a specification" do
+ it "returns the correct image URL for each day" do
+ [80, 90, 20, 50].each_with_index do |probability, i|
+ expect(forecast[i].image_url).to eq "http://www.nws.noaa.gov/weather/images/fcicons/ra#{probability}.jpg"
+ end
+ end
+ end
+
+ describe "a specification" do
+ it "returns the correct daytime probability of precipitation for each day" do
+ [5, 94, 22, 50].each_with_index do |probability, i|
+ expect(forecast[i].daytime_precipitation_probability).to eq probability
+ end
+ end
+ end
+
+ describe "a specification" do
+ it "returns the correct evening probability of precipitation for each day" do
+ [77, 84, 19, 50].each_with_index do |probability, i|
+ expect(forecast[i].evening_precipitation_probability).to eq probability
+ end
+ end
+ end
+ end
+end
diff --git a/spec/http_service_spec.rb b/spec/http_service_spec.rb
new file mode 100644
index 0000000..d33e6b2
--- /dev/null
+++ b/spec/http_service_spec.rb
@@ -0,0 +1,37 @@
+require "spec_helper"
+
+describe NOAA do
+ describe NOAA::HttpService do
+ let(:http_service) { NOAA::HttpService.new(HTTP) }
+
+ describe "#get_current_conditions" do
+ it 'sends a properly-formed URL for current conditions' do
+ pending
+ end
+
+ it 'returns a XML document for current conditions' do
+ pending
+ end
+ end
+
+ describe "#get_forecast" do
+ it 'sends a properly-formed URL for forecast' do
+ pending
+ end
+
+ it 'returns a XML document for forecast' do
+ pending
+ end
+ end
+
+ describe "#get_station_list" do
+ it 'sends a properly-formed URL for station list' do
+ pending
+ end
+
+ it 'returns a XML document for station list' do
+ pending
+ end
+ end
+ end
+end
diff --git a/spec/noaa_spec.rb b/spec/noaa_spec.rb
new file mode 100644
index 0000000..5dd67d2
--- /dev/null
+++ b/spec/noaa_spec.rb
@@ -0,0 +1,5 @@
+describe NOAA do
+ it { should respond_to :forecast }
+ it { should respond_to :current_conditions }
+ it { should respond_to :current_conditions_at_station }
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..798f5af
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,25 @@
+# This file was generated by the `rspec --init` command. Conventionally, all
+# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
+# Require this file using `require "spec_helper"` to ensure that it is only
+# loaded once.
+#
+# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
+require 'rubygems'
+
+APP_ROOT = File.expand_path('../..', __FILE__)
+$: << File.join(APP_ROOT, 'lib/')
+require 'noaa'
+
+Dir[File.join(APP_ROOT, 'spec/support/**/*.rb')].each { |f| require f }
+
+RSpec.configure do |config|
+ config.treat_symbols_as_metadata_keys_with_true_values = true
+ config.run_all_when_everything_filtered = true
+ config.filter_run :focus
+
+ # Run specs in random order to surface order dependencies. If you find an
+ # order dependency and want to debug it, you can fix the order by providing
+ # the seed, which is printed after each run.
+ # --seed 1234
+ config.order = 'random'
+end
diff --git a/spec/station_spec.rb b/spec/station_spec.rb
new file mode 100644
index 0000000..923f15c
--- /dev/null
+++ b/spec/station_spec.rb
@@ -0,0 +1,66 @@
+require "spec_helper"
+
+describe NOAA::Station do
+ before :all do
+ NOAA::Station.stations_file = File.join(File.dirname(__FILE__), 'data', 'stations.yml')
+ end
+
+ let(:station) { NOAA::Station.find('KNYC') }
+
+ after :all do
+ NOAA::Station.stations_file = nil
+ end
+
+ it 'loads the station by id' do
+ expect(NOAA::Station.find('KNYC').id).to eq 'KNYC'
+ end
+
+ describe "#closest_to" do
+ it 'finds the closest to coordinates' do
+ expect(NOAA::Station.closest_to(Geokit::LatLng.new(40.8, -73.96)).id)
+ .to eq 'KNYC'
+ end
+
+ it 'finds the closest to lat/lng' do
+ expect(NOAA::Station.closest_to(40.8, -73.96).id)
+ .to eq 'KNYC'
+ end
+
+ it 'finds the closest to lat/lng passed as array' do
+ expect(NOAA::Station.closest_to([40.8, -73.96]).id).to eq 'KNYC'
+ end
+
+ it 'throws the ArgumentError if bad argument passed into #closest_to()' do
+ expect { NOAA::Station.closest_to('hey') }.to raise_error(ArgumentError)
+ end
+
+ it 'throws the ArgumentError if more than two arguments passed into #closest_to()' do
+ expect { NOAA::Station.closest_to(1, 2, 3) }
+ .to raise_error(ArgumentError)
+ end
+ end
+
+ it 'returns the name' do
+ expect(station.name).to eq 'New York City, Central Park'
+ end
+
+ it 'returns the state' do
+ expect(station.state).to eq 'NY'
+ end
+
+ it 'returns the XML URL' do
+ expect(station.xml_url).to eq 'http://weather.gov/xml/current_obs/KNYC.xml'
+ end
+
+ it 'returns the latitude' do
+ expect(station.latitude).to eq 40.783
+ end
+
+ it 'returns the longitude' do
+ expect(station.longitude).to eq(-73.967)
+ end
+
+ it 'returns the coordinates' do
+ expect(station.coordinates).to eq Geokit::LatLng.new(40.783, -73.967)
+ end
+end
diff --git a/spec/station_writer_spec.rb b/spec/station_writer_spec.rb
new file mode 100644
index 0000000..339302d
--- /dev/null
+++ b/spec/station_writer_spec.rb
@@ -0,0 +1,49 @@
+require 'spec_helper'
+
+describe NOAA do
+ describe NOAA::StationWriter do
+ let(:xml_document) { LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'data', 'stations-abridged.xml')) }
+
+ before do
+ io = StringIO.new
+ NOAA::StationWriter.new(xml_document).write(io)
+ @yaml = YAML.load(io.string)
+ end
+
+ it "writes the latitude for each station" do
+ [40.66, 40.77, 40.783].each_with_index do |latitude, i|
+ expect(@yaml[i]['latitude']).to eq latitude
+ end
+ end
+
+ it "writes the longitude for each station" do
+ [-73.78, -73.9, -73.967].each_with_index do |longitude, i|
+ expect(@yaml[i]['longitude']).to eq longitude
+ end
+ end
+
+ it "writes the id for each station" do
+ ['KJFK', 'KLGA', 'KNYC'].each_with_index do |id, i|
+ expect(@yaml[i]['id']).to eq id
+ end
+ end
+
+ it "writes the name for each station" do
+ ['New York/John F. Kennedy Intl Airport', 'New York, La Guardia Airport', 'New York City, Central Park'].each_with_index do |name, i|
+ expect(@yaml[i]['name']).to eq name
+ end
+ end
+
+ it "writes the state for each station" do
+ (%w(NY) * 3).each_with_index do |state, i|
+ expect(@yaml[i]['state']).to eq state
+ end
+ end
+
+ it "writes the XML URL for each station" do
+ 3.times do |i|
+ expect(@yaml[i]['xml_url']).to eq "http://weather.gov/xml/current_obs/#{@yaml[i]['id']}.xml"
+ end
+ end
+ end
+end
diff --git a/test/test_current_conditions.rb b/test/test_current_conditions.rb
deleted file mode 100644
index abbebea..0000000
--- a/test/test_current_conditions.rb
+++ /dev/null
@@ -1,141 +0,0 @@
-require File.join(File.dirname(__FILE__), 'test_helper')
-
-class TestCurrentConditions < NOAA::TestCase
- XML_DOC = File.open(File.join(File.dirname(__FILE__), 'data', 'KVAY.xml')) { |f| Nokogiri::XML(f) }
-
- test 'should return observation time' do
- conditions.observed_at.should == Time.parse('2008-12-23 10:54:00 -0500')
- end
-
- test 'should return weather description' do
- conditions.weather_description.should == 'Fair'
- end
-
- test 'should return weather description from #weather_summary' do
- conditions.weather_summary.should == 'Fair'
- end
-
- test 'should return weather type code' do
- conditions.weather_type_code.should == :skc
- end
-
- test 'should return image URL' do
- conditions.image_url.should == 'http://weather.gov/weather/images/fcicons/skc.jpg'
-end
-
-test 'should return temperature in fahrenheit by default' do
- conditions.temperature.should == 24
-end
-
-test 'should return temperature in fahrenheit when specified' do
- conditions.temperature(:f).should == 24
-end
-
-test 'should return temperature in celsius when specified' do
- conditions.temperature(:c).should == -4
-end
-
-test 'should raise ArgumentError if unknown unit specified for temperature' do
- lambda { conditions.temperature(:kelvin) }.should raise_error(ArgumentError)
-end
-
-test 'should return relative humidity' do
- conditions.relative_humidity.should == 52
-end
-
- test 'should return wind direction' do
- conditions.wind_direction.should == 'Northwest'
- end
-
- test 'should return wind degrees' do
- conditions.wind_degrees.should == 330
- end
-
- test 'should return wind speed in MPH' do
- conditions.wind_speed.should == 3.45
- end
-
- test 'should return wind gust in MPH' do
- conditions.wind_gust.should == 10.25
- end
-
- #TODO wind gust can be NA
-
- test 'should return pressure in inches by default' do
- conditions.pressure.should == 30.7
- end
-
- test 'should return pressure in inches when specified' do
- conditions.pressure(:in).should == 30.7
- end
-
- test 'should return pressure in millibars when specified' do
- conditions.pressure(:mb).should == 1039.5
- end
-
- test 'should throw ArgumentError when unrecognized pressure specified for pressure' do
- lambda { conditions.pressure(:psi) }.should raise_error(ArgumentError)
- end
-
- test 'should return dew point in fahrenheit by default' do
- conditions.dew_point.should == 9
- end
-
- test 'should return dew point in fahrenheit when specified' do
- conditions.dew_point(:f).should == 9
- end
-
- test 'should return dew point in celsius when specified' do
- conditions.dew_point(:c).should == -13
- end
-
- test 'should throw ArgumentError when unrecognized unit specified for dew point' do
- lambda { conditions.dew_point(:kelvin) }.should raise_error(ArgumentError)
- end
-
- #TODO heat index can be NA
-
- test 'should return heat index in fahrenheit by default' do
- conditions.heat_index.should == 105
- end
-
- test 'should return heat index in fahrenheit when specified' do
- conditions.heat_index(:f).should == 105
- end
-
- test 'should return heat index in celsius when specified' do
- conditions.heat_index(:c).should == 41
- end
-
- test 'should throw ArgumentError when unrecognized unit specified for heat index' do
- lambda { conditions.heat_index(:kelvin) }.should raise_error(ArgumentError)
- end
-
- #TODO wind chill can be NA
-
- test 'should return wind chill in fahrenheit by default' do
- conditions.wind_chill.should == 19
- end
-
- test 'should return wind chill in fahrenheit when specified' do
- conditions.wind_chill(:f).should == 19
- end
-
- test 'should return wind chill in celsius when specified' do
- conditions.wind_chill(:c).should == -7
- end
-
- test 'should throw ArgumentError when unrecognized unit specified for wind chill' do
- lambda { conditions.wind_chill(:kelvin) }.should raise_error(ArgumentError)
- end
-
- test 'should return visibility in miles' do
- conditions.visibility.should == 10.0
- end
-
- private
-
- def conditions
- @conditions ||= NOAA::CurrentConditions.from_xml(XML_DOC)
- end
-end
diff --git a/test/test_forecast.rb b/test/test_forecast.rb
deleted file mode 100644
index b1c3542..0000000
--- a/test/test_forecast.rb
+++ /dev/null
@@ -1,69 +0,0 @@
-require File.join(File.dirname(__FILE__), 'test_helper')
-
-class TestForecast < NOAA::TestCase
- XML_DOC = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'data', '4-day.xml'))
-
- should 'return number of days' do
- forecast.length.should == 4
- end
-
- ['2008-12-23', '2008-12-24', '2008-12-25', '2008-12-26'].each_with_index do |date, i|
- should "return correct start time for day #{i}" do
- forecast[i].starts_at.should == Time.parse("#{date} 06:00:00 -05:00")
- end
- end
-
- ['2008-12-24', '2008-12-25', '2008-12-26', '2008-12-27'].each_with_index do |date, i|
- should "return correct end time for day #{i}" do
- forecast[i].ends_at.should == Time.parse("#{date} 06:00:00 -05:00")
- end
- end
-
- [32, 49, 43, 41].each_with_index do |temp, i|
- should "return correct high for day #{i}" do
- forecast[i].high.should == temp
- end
- end
-
- [31, 41, 33, 39].each_with_index do |temp, i|
- should "return correct low for day #{i}" do
- forecast[i].low.should == temp
- end
- end
-
- ['Rain', 'Rain', 'Slight Chance Rain', 'Chance Rain'].each_with_index do |summary, i|
- should "return correct weather summary for day #{i}" do
- forecast[i].weather_summary.should == summary
- end
- end
-
- 4.times do |i|
- should "return correct weather type code for day #{i}" do
- forecast[i].weather_type_code.should == :ra
- end
- end
-
- [80, 90, 20, 50].each_with_index do |probability, i|
- should "return correct image URL for day #{i}" do
- forecast[i].image_url.should == "http://www.nws.noaa.gov/weather/images/fcicons/ra#{probability}.jpg"
- end
- end
-
- [5, 94, 22, 50].each_with_index do |probability, i|
- should "return correct daytime probability of precipitation for day #{i}" do
- forecast[i].daytime_precipitation_probability.should == probability
- end
- end
-
- [77, 84, 19, 50].each_with_index do |probability, i|
- should "return correct evening probability of precipitation for day #{i}" do
- forecast[i].evening_precipitation_probability.should == probability
- end
- end
-
- private
-
- def forecast
- @forecast ||= NOAA::Forecast.from_xml(XML_DOC)
- end
-end
diff --git a/test/test_helper.rb b/test/test_helper.rb
deleted file mode 100644
index 44a32af..0000000
--- a/test/test_helper.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-begin
- require 'context'
- require 'matchy'
-rescue LoadError => e
- if require 'rubygems' then retry
- else raise(e)
- end
-end
-
-require File.join(File.dirname(__FILE__), '..', 'lib', 'noaa')
-
-module NOAA
- class TestCase < ::Test::Unit::TestCase
- end
-end
diff --git a/test/test_http_service.rb b/test/test_http_service.rb
deleted file mode 100644
index 8a036d7..0000000
--- a/test/test_http_service.rb
+++ /dev/null
@@ -1,57 +0,0 @@
-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{\n\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{\n\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{\n\n}
- end
-
- private
-
- def http_service
- NOAA::HttpService.new(HTTP)
- end
-
- module HTTP
- class <"
- end
- end
- end
-end
diff --git a/test/test_station.rb b/test/test_station.rb
deleted file mode 100644
index 2aaefd8..0000000
--- a/test/test_station.rb
+++ /dev/null
@@ -1,65 +0,0 @@
-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
diff --git a/test/test_station_writer.rb b/test/test_station_writer.rb
deleted file mode 100644
index 9edd4ac..0000000
--- a/test/test_station_writer.rb
+++ /dev/null
@@ -1,49 +0,0 @@
-require File.join(File.dirname(__FILE__), 'test_helper')
-
-class TestStationWriter < NOAA::TestCase
- XML_DOC = LibXML::XML::Document.file(File.join(File.dirname(__FILE__), 'data', 'stations-abridged.xml'))
-
- [40.66, 40.77, 40.783].each_with_index do |latitude, i|
- test "should write latitude for station #{i}" do
- yaml[i]['latitude'].should == latitude
- end
- end
-
- [-73.78, -73.9, -73.967].each_with_index do |longitude, i|
- test "should write longitude for station #{i}" do
- yaml[i]['longitude'].should == longitude
- end
- end
-
- ['KJFK', 'KLGA', 'KNYC'].each_with_index do |id, i|
- test "should write id for station #{i}" do
- yaml[i]['id'].should == id
- end
- end
-
- ['New York/John F. Kennedy Intl Airport', 'New York, La Guardia Airport', 'New York City, Central Park'].each_with_index do |name, i|
- test "should write name for station #{i}" do
- yaml[i]['name'].should == name
- end
- end
-
- (%w(NY) * 3).each_with_index do |state, i|
- test "should write state for station #{i}" do
- yaml[i]['state'].should == state
- end
- end
-
- 3.times do |i|
- test "should write XML URL for station #{i}" do
- yaml[i]['xml_url'].should == "http://weather.gov/xml/current_obs/#{yaml[i]['id']}.xml"
- end
- end
-
- def yaml
- @yaml ||= begin
- io = StringIO.new
- NOAA::StationWriter.new(XML_DOC).write(io)
- YAML.load(io.string)
- end
- end
-end