spec/weather_services/wunderground_spec.rb in barometer-0.5.0 vs spec/weather_services/wunderground_spec.rb in barometer-0.6.1
- old
+ new
@@ -9,142 +9,141 @@
end
describe "the class methods" do
it "defines accepted_formats" do
- WeatherService::Wunderground.accepted_formats.should == @accepted_formats
+ WeatherService::Wunderground._accepted_formats.should == @accepted_formats
end
- it "defines get_current" do
- WeatherService::Wunderground.respond_to?("get_current").should be_true
+ it "defines source_name" do
+ WeatherService::Wunderground._source_name.should == :wunderground
end
- it "defines get_forecast" do
- WeatherService::Wunderground.respond_to?("get_forecast").should be_true
+ it "defines fetch_current" do
+ WeatherService::Wunderground.respond_to?("_fetch_current").should be_true
end
+ it "defines fetch_forecast" do
+ WeatherService::Wunderground.respond_to?("_fetch_forecast").should be_true
+ end
+
end
describe "building the current data" do
it "defines the build method" do
- WeatherService::Wunderground.respond_to?("build_current").should be_true
+ WeatherService::Wunderground.respond_to?("_build_current").should be_true
end
it "requires Hash input" do
- lambda { WeatherService::Wunderground.build_current }.should raise_error(ArgumentError)
- WeatherService::Wunderground.build_current({})
- lambda { WeatherService::Wunderground.build_current({}) }.should_not raise_error(ArgumentError)
+ lambda { WeatherService::Wunderground._build_current }.should raise_error(ArgumentError)
+ WeatherService::Wunderground._build_current({})
+ lambda { WeatherService::Wunderground._build_current({}) }.should_not raise_error(ArgumentError)
end
it "returns Barometer::CurrentMeasurement object" do
- current = WeatherService::Wunderground.build_current({})
- current.is_a?(Data::CurrentMeasurement).should be_true
+ current = WeatherService::Wunderground._build_current({})
+ current.is_a?(Measurement::Current).should be_true
end
end
describe "building the forecast data" do
it "defines the build method" do
- WeatherService::Wunderground.respond_to?("build_forecast").should be_true
+ WeatherService::Wunderground.respond_to?("_build_forecast").should be_true
end
it "requires Hash input" do
- lambda { WeatherService::Wunderground.build_forecast }.should raise_error(ArgumentError)
- lambda { WeatherService::Wunderground.build_forecast({}) }.should_not raise_error(ArgumentError)
+ lambda { WeatherService::Wunderground._build_forecast }.should raise_error(ArgumentError)
+ lambda { WeatherService::Wunderground._build_forecast({}) }.should_not raise_error(ArgumentError)
end
it "returns Array object" do
- current = WeatherService::Wunderground.build_forecast({})
+ current = WeatherService::Wunderground._build_forecast({})
current.is_a?(Array).should be_true
end
end
describe "building the station data" do
it "defines the build method" do
- WeatherService::Wunderground.respond_to?("build_station").should be_true
+ WeatherService::Wunderground.respond_to?("_build_station").should be_true
end
it "requires Hash input" do
- lambda { WeatherService::Wunderground.build_station }.should raise_error(ArgumentError)
- lambda { WeatherService::Wunderground.build_station({}) }.should_not raise_error(ArgumentError)
+ lambda { WeatherService::Wunderground._build_station }.should raise_error(ArgumentError)
+ lambda { WeatherService::Wunderground._build_station({}) }.should_not raise_error(ArgumentError)
end
it "returns Barometer::Location object" do
- station = WeatherService::Wunderground.build_station({})
+ station = WeatherService::Wunderground._build_station({})
station.is_a?(Data::Location).should be_true
end
end
describe "building the location data" do
it "defines the build method" do
- WeatherService::Wunderground.respond_to?("build_location").should be_true
+ WeatherService::Wunderground.respond_to?("_build_location").should be_true
end
it "requires Hash input" do
- lambda { WeatherService::Wunderground.build_location }.should raise_error(ArgumentError)
- lambda { WeatherService::Wunderground.build_location({}) }.should_not raise_error(ArgumentError)
+ lambda { WeatherService::Wunderground._build_location }.should raise_error(ArgumentError)
+ lambda { WeatherService::Wunderground._build_location({}) }.should_not raise_error(ArgumentError)
end
it "returns Barometer::Location object" do
- location = WeatherService::Wunderground.build_location({})
+ location = WeatherService::Wunderground._build_location({})
location.is_a?(Data::Location).should be_true
end
end
describe "building the timezone" do
it "defines the build method" do
- WeatherService::Wunderground.respond_to?("build_timezone").should be_true
+ WeatherService::Wunderground.respond_to?("_parse_full_timezone").should be_true
end
it "requires Hash input" do
- lambda { WeatherService::Wunderground.build_timezone }.should raise_error(ArgumentError)
- lambda { WeatherService::Wunderground.build_timezone({}) }.should_not raise_error(ArgumentError)
+ lambda { WeatherService::Wunderground._parse_full_timezone }.should raise_error(ArgumentError)
+ lambda { WeatherService::Wunderground._parse_full_timezone({}) }.should_not raise_error(ArgumentError)
end
end
describe "building the sun data" do
- before(:each) do
- @zone = Data::Zone.new("Europe/Paris")
- end
-
it "defines the build method" do
- WeatherService::Wunderground.respond_to?("build_sun").should be_true
+ WeatherService::Wunderground.respond_to?("_build_sun").should be_true
end
it "requires Hash input" do
- lambda { WeatherService::Wunderground.build_sun }.should raise_error(ArgumentError)
- lambda { WeatherService::Wunderground.build_sun({},@zone) }.should_not raise_error(ArgumentError)
+ lambda { WeatherService::Wunderground._build_sun }.should raise_error(ArgumentError)
+ lambda { WeatherService::Wunderground._build_sun({}) }.should_not raise_error(ArgumentError)
end
it "requires Barometer::Zone input" do
- lambda { WeatherService::Wunderground.build_sun({}) }.should raise_error(ArgumentError)
- lambda { WeatherService::Wunderground.build_sun({}, "invalid") }.should raise_error(ArgumentError)
- lambda { WeatherService::Wunderground.build_sun({},@zone) }.should_not raise_error(ArgumentError)
+ lambda { WeatherService::Wunderground._build_sun({}, "invalid") }.should raise_error(ArgumentError)
+ lambda { WeatherService::Wunderground._build_sun({}) }.should_not raise_error(ArgumentError)
end
it "returns Barometer::Sun object" do
- sun = WeatherService::Wunderground.build_sun({},@zone)
+ sun = WeatherService::Wunderground._build_sun({})
sun.is_a?(Data::Sun).should be_true
end
end
describe "when measuring" do
before(:each) do
@query = Barometer::Query.new("Calgary,AB")
- @measurement = Data::Measurement.new
+ @measurement = Barometer::Measurement.new
FakeWeb.register_uri(:get,
"http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=#{CGI.escape(@query.q)}",
:string => File.read(File.join(File.dirname(__FILE__),
'../fixtures/services/wunderground',
@@ -180,118 +179,24 @@
lambda { WeatherService::Wunderground._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
end
it "returns a Barometer::Measurement object" do
result = WeatherService::Wunderground._measure(@measurement, @query)
- result.is_a?(Data::Measurement).should be_true
- result.current.is_a?(Data::CurrentMeasurement).should be_true
+ result.is_a?(Barometer::Measurement).should be_true
+ result.current.is_a?(Measurement::Current).should be_true
result.forecast.is_a?(Array).should be_true
-
- result.source.should == :wunderground
end
end
end
- describe "when answering the simple questions," do
-
- before(:each) do
- @measurement = Data::Measurement.new
- end
-
- describe "currently_wet_by_icon?" do
-
- before(:each) do
- @measurement.current = Data::CurrentMeasurement.new
- end
-
- it "returns true if matching icon code" do
- @measurement.current.icon = "rain"
- @measurement.current.icon?.should be_true
- WeatherService::Wunderground.currently_wet_by_icon?(@measurement.current).should be_true
- end
-
- it "returns false if NO matching icon code" do
- @measurement.current.icon = "sunny"
- @measurement.current.icon?.should be_true
- WeatherService::Wunderground.currently_wet_by_icon?(@measurement.current).should be_false
- end
-
- end
-
- describe "forecasted_wet_by_icon?" do
-
- before(:each) do
- @measurement.forecast = [Data::ForecastMeasurement.new]
- @measurement.forecast.first.date = Date.today
- @measurement.forecast.size.should == 1
- end
-
- it "returns true if matching icon code" do
- @measurement.forecast.first.icon = "rain"
- @measurement.forecast.first.icon?.should be_true
- WeatherService::Wunderground.forecasted_wet_by_icon?(@measurement.forecast.first).should be_true
- end
-
- it "returns false if NO matching icon code" do
- @measurement.forecast.first.icon = "sunny"
- @measurement.forecast.first.icon?.should be_true
- WeatherService::Wunderground.forecasted_wet_by_icon?(@measurement.forecast.first).should be_false
- end
-
- end
-
- describe "currently_sunny_by_icon?" do
-
- before(:each) do
- @measurement.current = Data::CurrentMeasurement.new
- end
-
- it "returns true if matching icon code" do
- @measurement.current.icon = "sunny"
- @measurement.current.icon?.should be_true
- WeatherService::Wunderground.currently_sunny_by_icon?(@measurement.current).should be_true
- end
-
- it "returns false if NO matching icon code" do
- @measurement.current.icon = "rain"
- @measurement.current.icon?.should be_true
- WeatherService::Wunderground.currently_sunny_by_icon?(@measurement.current).should be_false
- end
-
- end
-
- describe "forecasted_sunny_by_icon?" do
-
- before(:each) do
- @measurement.forecast = [Data::ForecastMeasurement.new]
- @measurement.forecast.first.date = Date.today
- @measurement.forecast.size.should == 1
- end
-
- it "returns true if matching icon code" do
- @measurement.forecast.first.icon = "sunny"
- @measurement.forecast.first.icon?.should be_true
- WeatherService::Wunderground.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_true
- end
-
- it "returns false if NO matching icon code" do
- @measurement.forecast.first.icon = "rain"
- @measurement.forecast.first.icon?.should be_true
- WeatherService::Wunderground.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_false
- end
-
- end
-
- end
-
describe "overall data correctness" do
before(:each) do
@query = Barometer::Query.new("Calgary,AB")
- @measurement = Data::Measurement.new
+ @measurement = Barometer::Measurement.new
FakeWeb.register_uri(:get,
"http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=#{CGI.escape(@query.q)}",
:string => File.read(File.join(File.dirname(__FILE__),
'../fixtures/services/wunderground',
@@ -310,10 +215,11 @@
# TODO: complete this
it "should correctly build the data" do
result = WeatherService::Wunderground._measure(@measurement, @query)
# build timezone
- @measurement.timezone.timezone.should == "America/Edmonton"
+ @measurement.timezone.zone_full.should == "America/Edmonton"
+ @measurement.timezone.current.should == "America/Edmonton"
# time = Time.local(2009, 4, 23, 18, 00, 0)
# rise = Time.local(time.year, time.month, time.day, 6, 23)
# set = Time.local(time.year, time.month, time.day, 20, 45)
# sun_rise = @measurement.timezone.tz.local_to_utc(rise)
\ No newline at end of file