spec/weather_services/yahoo_spec.rb in barometer-0.5.0 vs spec/weather_services/yahoo_spec.rb in barometer-0.6.1

- old
+ new

@@ -9,84 +9,88 @@ end describe "the class methods" do it "defines accepted_formats" do - WeatherService::Yahoo.accepted_formats.should == @accepted_formats + WeatherService::Yahoo._accepted_formats.should == @accepted_formats end + it "defines source_name" do + WeatherService::Yahoo._source_name.should == :yahoo + end + it "defines get_all" do - WeatherService::Yahoo.respond_to?("fetch").should be_true + WeatherService::Yahoo.respond_to?("_fetch").should be_true end end describe "building the current data" do it "defines the build method" do - WeatherService::Yahoo.respond_to?("build_current").should be_true + WeatherService::Yahoo.respond_to?("_build_current").should be_true end it "requires Hash input" do - lambda { WeatherService::Yahoo.build_current }.should raise_error(ArgumentError) - lambda { WeatherService::Yahoo.build_current({}) }.should_not raise_error(ArgumentError) + lambda { WeatherService::Yahoo._build_current }.should raise_error(ArgumentError) + lambda { WeatherService::Yahoo._build_current({}) }.should_not raise_error(ArgumentError) end it "returns Barometer::CurrentMeasurement object" do - current = WeatherService::Yahoo.build_current({}) - current.is_a?(Data::CurrentMeasurement).should be_true + current = WeatherService::Yahoo._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::Yahoo.respond_to?("build_forecast").should be_true + WeatherService::Yahoo.respond_to?("_build_forecast").should be_true end it "requires Hash input" do - lambda { WeatherService::Yahoo.build_forecast }.should raise_error(ArgumentError) - lambda { WeatherService::Yahoo.build_forecast({}) }.should_not raise_error(ArgumentError) + lambda { WeatherService::Yahoo._build_forecast }.should raise_error(ArgumentError) + lambda { WeatherService::Yahoo._build_forecast({}) }.should_not raise_error(ArgumentError) end it "returns Array object" do - current = WeatherService::Yahoo.build_forecast({}) + current = WeatherService::Yahoo._build_forecast({}) current.is_a?(Array).should be_true end end describe "building the location data" do it "defines the build method" do - WeatherService::Yahoo.respond_to?("build_location").should be_true + WeatherService::Yahoo.respond_to?("_build_location").should be_true end it "requires Hash input" do - lambda { WeatherService::Yahoo.build_location }.should raise_error(ArgumentError) - lambda { WeatherService::Yahoo.build_location({}) }.should_not raise_error(ArgumentError) + lambda { WeatherService::Yahoo._build_location }.should raise_error(ArgumentError) + lambda { WeatherService::Yahoo._build_location({}) }.should_not raise_error(ArgumentError) end it "requires Barometer::Geo input" do geo = Data::Geo.new({}) - lambda { WeatherService::Yahoo.build_location({}, {}) }.should raise_error(ArgumentError) - lambda { WeatherService::Yahoo.build_location({}, geo) }.should_not raise_error(ArgumentError) + lambda { WeatherService::Yahoo._build_location({}, {}) }.should raise_error(ArgumentError) + lambda { WeatherService::Yahoo._build_location({}, geo) }.should_not raise_error(ArgumentError) end it "returns Barometer::Location object" do - location = WeatherService::Yahoo.build_location({}) + location = WeatherService::Yahoo._build_location({}) location.is_a?(Data::Location).should be_true end end describe "when measuring" do before(:each) do @query = Barometer::Query.new("90210") - @measurement = Data::Measurement.new + @measurement = Barometer::Measurement.new FakeWeb.register_uri(:get, "http://weather.yahooapis.com:80/forecastrss?u=c&p=#{CGI.escape(@query.q)}", :string => File.read(File.join(File.dirname(__FILE__), '../fixtures/services/yahoo', @@ -109,123 +113,29 @@ end it "requires a Barometer::Query query" do lambda { WeatherService::Yahoo._measure }.should raise_error(ArgumentError) lambda { WeatherService::Yahoo._measure(@measurement, 1) }.should raise_error(ArgumentError) - + lambda { WeatherService::Yahoo._measure(@measurement, @query) }.should_not raise_error(ArgumentError) end it "returns a Barometer::Measurement object" do result = WeatherService::Yahoo._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 == :yahoo 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 = "4" - @measurement.current.icon?.should be_true - WeatherService::Yahoo.currently_wet_by_icon?(@measurement.current).should be_true - end - - it "returns false if NO matching icon code" do - @measurement.current.icon = "32" - @measurement.current.icon?.should be_true - WeatherService::Yahoo.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 = "4" - @measurement.forecast.first.icon?.should be_true - WeatherService::Yahoo.forecasted_wet_by_icon?(@measurement.forecast.first).should be_true - end - - it "returns false if NO matching icon code" do - @measurement.forecast.first.icon = "32" - @measurement.forecast.first.icon?.should be_true - WeatherService::Yahoo.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 = "32" - @measurement.current.icon?.should be_true - WeatherService::Yahoo.currently_sunny_by_icon?(@measurement.current).should be_true - end - - it "returns false if NO matching icon code" do - @measurement.current.icon = "4" - @measurement.current.icon?.should be_true - WeatherService::Yahoo.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 = "32" - @measurement.forecast.first.icon?.should be_true - WeatherService::Yahoo.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_true - end - - it "returns false if NO matching icon code" do - @measurement.forecast.first.icon = "4" - @measurement.forecast.first.icon?.should be_true - WeatherService::Yahoo.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("90210") - @measurement = Data::Measurement.new + @measurement = Barometer::Measurement.new FakeWeb.register_uri(:get, "http://weather.yahooapis.com:80/forecastrss?u=c&p=#{CGI.escape(@query.q)}", :string => File.read(File.join(File.dirname(__FILE__), '../fixtures/services/yahoo', \ No newline at end of file