barometer 0.5.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.rdoc +51 -9
- data/VERSION.yml +2 -2
- data/bin/barometer +57 -7
- data/lib/barometer.rb +11 -0
- data/lib/barometer/base.rb +3 -0
- data/lib/barometer/data.rb +11 -6
- data/lib/barometer/data/sun.rb +10 -0
- data/lib/barometer/data/zone.rb +79 -188
- data/lib/barometer/formats/coordinates.rb +4 -1
- data/lib/barometer/formats/geocode.rb +9 -7
- data/lib/barometer/formats/icao.rb +2 -2
- data/lib/barometer/formats/weather_id.rb +2 -2
- data/lib/barometer/measurements/common.rb +113 -0
- data/lib/barometer/{data → measurements}/current.rb +17 -42
- data/lib/barometer/measurements/forecast.rb +62 -0
- data/lib/barometer/measurements/forecast_array.rb +72 -0
- data/lib/barometer/{data → measurements}/measurement.rb +57 -45
- data/lib/barometer/measurements/night.rb +27 -0
- data/lib/barometer/query.rb +55 -5
- data/lib/barometer/services.rb +3 -1
- data/lib/barometer/translations/icao_country_codes.yml +274 -1
- data/lib/barometer/translations/weather_country_codes.yml +189 -6
- data/lib/barometer/translations/zone_codes.yml +360 -0
- data/lib/barometer/weather.rb +5 -4
- data/lib/barometer/weather_services/google.rb +19 -35
- data/lib/barometer/weather_services/service.rb +113 -255
- data/lib/barometer/weather_services/weather_bug.rb +291 -2
- data/lib/barometer/weather_services/weather_dot_com.rb +45 -54
- data/lib/barometer/weather_services/wunderground.rb +83 -89
- data/lib/barometer/weather_services/yahoo.rb +44 -91
- data/lib/barometer/web_services/geocode.rb +1 -0
- data/lib/barometer/web_services/timezone.rb +40 -0
- data/lib/barometer/web_services/weather_id.rb +17 -2
- data/lib/demometer/demometer.rb +28 -0
- data/lib/demometer/public/css/master.css +259 -1
- data/lib/demometer/public/css/print.css +94 -0
- data/lib/demometer/public/css/syntax.css +64 -0
- data/lib/demometer/public/images/link-out.gif +0 -0
- data/lib/demometer/views/about.erb +10 -0
- data/lib/demometer/views/index.erb +2 -0
- data/lib/demometer/views/layout.erb +3 -2
- data/lib/demometer/views/measurement.erb +4 -1
- data/lib/demometer/views/readme.erb +116 -88
- data/spec/data/sun_spec.rb +53 -0
- data/spec/data/zone_spec.rb +330 -100
- data/spec/fixtures/formats/weather_id/ksfo.xml +1 -0
- data/spec/fixtures/services/weather_bug/90210_current.xml +1 -0
- data/spec/fixtures/services/weather_bug/90210_forecast.xml +1 -0
- data/spec/formats/weather_id_spec.rb +10 -5
- data/spec/measurements/common_spec.rb +352 -0
- data/spec/{data → measurements}/current_spec.rb +40 -103
- data/spec/measurements/forecast_array_spec.rb +165 -0
- data/spec/measurements/forecast_spec.rb +135 -0
- data/spec/{data → measurements}/measurement_spec.rb +86 -107
- data/spec/measurements/night_measurement_spec.rb +49 -0
- data/spec/query_spec.rb +12 -2
- data/spec/spec_helper.rb +28 -1
- data/spec/weather_services/google_spec.rb +27 -117
- data/spec/weather_services/services_spec.rb +49 -1024
- data/spec/weather_services/weather_bug_spec.rb +274 -0
- data/spec/weather_services/weather_dot_com_spec.rb +45 -125
- data/spec/weather_services/wunderground_spec.rb +42 -136
- data/spec/weather_services/yahoo_spec.rb +26 -116
- data/spec/weather_spec.rb +45 -45
- metadata +27 -11
- data/lib/barometer/data/forecast.rb +0 -84
- data/lib/barometer/data/night.rb +0 -69
- data/lib/barometer/extensions/graticule.rb +0 -51
- data/spec/data/forecast_spec.rb +0 -192
- data/spec/data/night_measurement_spec.rb +0 -136
| @@ -0,0 +1,49 @@ | |
| 1 | 
            +
            require 'spec_helper'
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            describe "Forecasted Night Measurement" do
         | 
| 4 | 
            +
              
         | 
| 5 | 
            +
              describe "when initialized" do
         | 
| 6 | 
            +
                
         | 
| 7 | 
            +
                before(:each) do
         | 
| 8 | 
            +
                  @night = Measurement::ForecastNight.new
         | 
| 9 | 
            +
                end
         | 
| 10 | 
            +
                
         | 
| 11 | 
            +
                it "responds to date" do
         | 
| 12 | 
            +
                  @night.date.should be_nil
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
                
         | 
| 15 | 
            +
                it "responds to pop" do
         | 
| 16 | 
            +
                  @night.pop.should be_nil
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
             | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
              
         | 
| 21 | 
            +
              describe "when writing data" do
         | 
| 22 | 
            +
                
         | 
| 23 | 
            +
                before(:each) do
         | 
| 24 | 
            +
                  @night = Measurement::ForecastNight.new
         | 
| 25 | 
            +
                end
         | 
| 26 | 
            +
                
         | 
| 27 | 
            +
                it "only accepts Date for date" do
         | 
| 28 | 
            +
                  invalid_data = 1
         | 
| 29 | 
            +
                  invalid_data.class.should_not == Date
         | 
| 30 | 
            +
                  lambda { @night.date = invalid_data }.should raise_error(ArgumentError)
         | 
| 31 | 
            +
                  
         | 
| 32 | 
            +
                  valid_data = Date.new
         | 
| 33 | 
            +
                  valid_data.class.should == Date
         | 
| 34 | 
            +
                  lambda { @night.date = valid_data }.should_not raise_error(ArgumentError)
         | 
| 35 | 
            +
                end
         | 
| 36 | 
            +
                
         | 
| 37 | 
            +
                it "only accepts Fixnum for pop" do
         | 
| 38 | 
            +
                  invalid_data = "test"
         | 
| 39 | 
            +
                  invalid_data.class.should_not == Fixnum
         | 
| 40 | 
            +
                  lambda { @night.pop = invalid_data }.should raise_error(ArgumentError)
         | 
| 41 | 
            +
                  
         | 
| 42 | 
            +
                  valid_data = 50
         | 
| 43 | 
            +
                  valid_data.class.should == Fixnum
         | 
| 44 | 
            +
                  lambda { @night.pop = valid_data }.should_not raise_error(ArgumentError)
         | 
| 45 | 
            +
                end
         | 
| 46 | 
            +
                
         | 
| 47 | 
            +
              end
         | 
| 48 | 
            +
              
         | 
| 49 | 
            +
            end
         | 
    
        data/spec/query_spec.rb
    CHANGED
    
    | @@ -23,6 +23,7 @@ describe "Query" do | |
| 23 23 | 
             
                @coordinates_to_weather_id = "USNY0996"
         | 
| 24 24 | 
             
                @icao_to_coordinates = "37.615223,-122.389979"
         | 
| 25 25 | 
             
                @icao_to_geocode = "San Francisco Airport, USA"
         | 
| 26 | 
            +
                @icao_to_weather_id = "USCA0987"
         | 
| 26 27 |  | 
| 27 28 | 
             
                Barometer.google_geocode_key = nil
         | 
| 28 29 | 
             
                #Barometer.skip_graticule = true
         | 
| @@ -135,6 +136,14 @@ describe "Query" do | |
| 135 136 | 
             
                  @query.geo.should be_nil
         | 
| 136 137 | 
             
                end
         | 
| 137 138 |  | 
| 139 | 
            +
                it "responds to timezone" do
         | 
| 140 | 
            +
                  @query.timezone.should be_nil
         | 
| 141 | 
            +
                end
         | 
| 142 | 
            +
                
         | 
| 143 | 
            +
                it "responds to conversions" do
         | 
| 144 | 
            +
                  @query.conversions.should be_nil
         | 
| 145 | 
            +
                end
         | 
| 146 | 
            +
                
         | 
| 138 147 | 
             
              end
         | 
| 139 148 |  | 
| 140 149 | 
             
              describe "when returning the query to a Weather API" do
         | 
| @@ -371,10 +380,11 @@ describe "Query" do | |
| 371 380 | 
             
                      query.should be_nil
         | 
| 372 381 | 
             
                    end
         | 
| 373 382 |  | 
| 374 | 
            -
                    it " | 
| 383 | 
            +
                    it "converts to weather_id" do
         | 
| 375 384 | 
             
                      acceptable_formats = [:weather_id]
         | 
| 376 385 | 
             
                      query = @query.convert!(acceptable_formats)
         | 
| 377 | 
            -
                      query.should  | 
| 386 | 
            +
                      query.q.should == @icao_to_weather_id
         | 
| 387 | 
            +
                      query.country_code.should == "US"
         | 
| 378 388 | 
             
                    end
         | 
| 379 389 |  | 
| 380 390 | 
             
                    it "skips converting to zipcode" do
         | 
    
        data/spec/spec_helper.rb
    CHANGED
    
    | @@ -32,6 +32,9 @@ if File.exists?(KEY_FILE) | |
| 32 32 | 
             
              	WEATHER_PARTNER_KEY = keys["weather"]["partner"]
         | 
| 33 33 | 
             
              	WEATHER_LICENSE_KEY = keys["weather"]["license"]
         | 
| 34 34 | 
             
            	end
         | 
| 35 | 
            +
              if keys["weather_bug"]
         | 
| 36 | 
            +
              	WEATHERBUG_CODE = keys["weather_bug"]["code"]
         | 
| 37 | 
            +
            	end
         | 
| 35 38 |  | 
| 36 39 | 
             
            else
         | 
| 37 40 | 
             
              File.open(KEY_FILE, 'w') {|f| f << "google: geocode: YOUR_KEY_KERE" }
         | 
| @@ -39,7 +42,6 @@ else | |
| 39 42 | 
             
              exit
         | 
| 40 43 | 
             
            end
         | 
| 41 44 |  | 
| 42 | 
            -
             | 
| 43 45 | 
             
              #
         | 
| 44 46 | 
             
              # for geocoding
         | 
| 45 47 | 
             
              #
         | 
| @@ -147,6 +149,13 @@ end | |
| 147 149 | 
             
                  '90210.xml')
         | 
| 148 150 | 
             
                )
         | 
| 149 151 | 
             
              )
         | 
| 152 | 
            +
              FakeWeb.register_uri(:get, 
         | 
| 153 | 
            +
                "http://xoap.weather.com:80/search/search?where=San%20Francisco%20%2C%20USA",
         | 
| 154 | 
            +
                :string => File.read(File.join(File.dirname(__FILE__), 
         | 
| 155 | 
            +
                  'fixtures/formats/weather_id',
         | 
| 156 | 
            +
                  'ksfo.xml')
         | 
| 157 | 
            +
                )
         | 
| 158 | 
            +
              )
         | 
| 150 159 | 
             
              #
         | 
| 151 160 | 
             
              # for yahoo.com searches
         | 
| 152 161 | 
             
              #
         | 
| @@ -157,6 +166,24 @@ end | |
| 157 166 | 
             
                  'from_USGA0028.xml')
         | 
| 158 167 | 
             
                )
         | 
| 159 168 | 
             
              )
         | 
| 169 | 
            +
              
         | 
| 170 | 
            +
              #
         | 
| 171 | 
            +
              # For wunderground weather
         | 
| 172 | 
            +
              #
         | 
| 173 | 
            +
              FakeWeb.register_uri(:get, 
         | 
| 174 | 
            +
                "http://api.wunderground.com/auto/wui/geo/WXCurrentObXML/index.xml?query=51.055149%2C-114.062438",
         | 
| 175 | 
            +
                :string => File.read(File.join(File.dirname(__FILE__), 
         | 
| 176 | 
            +
                  'fixtures/services/wunderground',
         | 
| 177 | 
            +
                  'current_calgary_ab.xml')
         | 
| 178 | 
            +
                )
         | 
| 179 | 
            +
              )  
         | 
| 180 | 
            +
              FakeWeb.register_uri(:get, 
         | 
| 181 | 
            +
                "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?query=51.055149%2C-114.062438",
         | 
| 182 | 
            +
                :string => File.read(File.join(File.dirname(__FILE__), 
         | 
| 183 | 
            +
                  'fixtures/services/wunderground',
         | 
| 184 | 
            +
                  'forecast_calgary_ab.xml')
         | 
| 185 | 
            +
                )
         | 
| 186 | 
            +
              )
         | 
| 160 187 |  | 
| 161 188 | 
             
            Spec::Runner.configure do |config|
         | 
| 162 189 |  | 
| @@ -11,7 +11,11 @@ describe "Google" do | |
| 11 11 | 
             
              describe "the class methods" do
         | 
| 12 12 |  | 
| 13 13 | 
             
                it "defines accepted_formats" do
         | 
| 14 | 
            -
                  WeatherService::Google. | 
| 14 | 
            +
                  WeatherService::Google._accepted_formats.should == @accepted_formats
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
                
         | 
| 17 | 
            +
                it "defines source_name" do
         | 
| 18 | 
            +
                  WeatherService::Google._source_name.should == :google
         | 
| 15 19 | 
             
                end
         | 
| 16 20 |  | 
| 17 21 | 
             
                # it "defines base_uri" do
         | 
| @@ -19,7 +23,7 @@ describe "Google" do | |
| 19 23 | 
             
                # end
         | 
| 20 24 |  | 
| 21 25 | 
             
                it "defines get_all" do
         | 
| 22 | 
            -
                  WeatherService::Google.respond_to?(" | 
| 26 | 
            +
                  WeatherService::Google.respond_to?("_fetch").should be_true
         | 
| 23 27 | 
             
                end
         | 
| 24 28 |  | 
| 25 29 | 
             
              end
         | 
| @@ -27,17 +31,17 @@ describe "Google" do | |
| 27 31 | 
             
              describe "building the current data" do
         | 
| 28 32 |  | 
| 29 33 | 
             
                it "defines the build method" do
         | 
| 30 | 
            -
                  WeatherService::Google.respond_to?(" | 
| 34 | 
            +
                  WeatherService::Google.respond_to?("_build_current").should be_true
         | 
| 31 35 | 
             
                end
         | 
| 32 36 |  | 
| 33 37 | 
             
                it "requires Hash input" do
         | 
| 34 | 
            -
                  lambda { WeatherService::Google. | 
| 35 | 
            -
                  lambda { WeatherService::Google. | 
| 38 | 
            +
                  lambda { WeatherService::Google._build_current }.should raise_error(ArgumentError)
         | 
| 39 | 
            +
                  lambda { WeatherService::Google._build_current({}) }.should_not raise_error(ArgumentError)
         | 
| 36 40 | 
             
                end
         | 
| 37 41 |  | 
| 38 | 
            -
                it "returns  | 
| 39 | 
            -
                  current = WeatherService::Google. | 
| 40 | 
            -
                  current.is_a?( | 
| 42 | 
            +
                it "returns Measurement::Current object" do
         | 
| 43 | 
            +
                  current = WeatherService::Google._build_current({})
         | 
| 44 | 
            +
                  current.is_a?(Measurement::Current).should be_true
         | 
| 41 45 | 
             
                end
         | 
| 42 46 |  | 
| 43 47 | 
             
              end
         | 
| @@ -45,17 +49,17 @@ describe "Google" do | |
| 45 49 | 
             
              describe "building the forecast data" do
         | 
| 46 50 |  | 
| 47 51 | 
             
                it "defines the build method" do
         | 
| 48 | 
            -
                  WeatherService::Google.respond_to?(" | 
| 52 | 
            +
                  WeatherService::Google.respond_to?("_build_forecast").should be_true
         | 
| 49 53 | 
             
                end
         | 
| 50 54 |  | 
| 51 55 | 
             
                it "requires Hash input" do
         | 
| 52 | 
            -
                  lambda { WeatherService::Google. | 
| 53 | 
            -
                  lambda { WeatherService::Google. | 
| 56 | 
            +
                  lambda { WeatherService::Google._build_forecast }.should raise_error(ArgumentError)
         | 
| 57 | 
            +
                  lambda { WeatherService::Google._build_forecast({}) }.should_not raise_error(ArgumentError)
         | 
| 54 58 | 
             
                end
         | 
| 55 59 |  | 
| 56 60 | 
             
                it "returns Array object" do
         | 
| 57 | 
            -
                  current = WeatherService::Google. | 
| 58 | 
            -
                  current.is_a?( | 
| 61 | 
            +
                  current = WeatherService::Google._build_forecast({})
         | 
| 62 | 
            +
                  current.is_a?(Measurement::ForecastArray).should be_true
         | 
| 59 63 | 
             
                end
         | 
| 60 64 |  | 
| 61 65 | 
             
              end
         | 
| @@ -63,18 +67,18 @@ describe "Google" do | |
| 63 67 | 
             
              describe "building the location data" do
         | 
| 64 68 |  | 
| 65 69 | 
             
                it "defines the build method" do
         | 
| 66 | 
            -
                  WeatherService::Google.respond_to?(" | 
| 70 | 
            +
                  WeatherService::Google.respond_to?("_build_location").should be_true
         | 
| 67 71 | 
             
                end
         | 
| 68 72 |  | 
| 69 73 | 
             
                it "requires Barometer::Geo input" do
         | 
| 70 74 | 
             
                  geo = Data::Geo.new({})
         | 
| 71 | 
            -
                  lambda { WeatherService::Google. | 
| 72 | 
            -
                  lambda { WeatherService::Google. | 
| 75 | 
            +
                  lambda { WeatherService::Google._build_location(nil,{}) }.should raise_error(ArgumentError)
         | 
| 76 | 
            +
                  lambda { WeatherService::Google._build_location(nil,geo) }.should_not raise_error(ArgumentError)
         | 
| 73 77 | 
             
                end
         | 
| 74 78 |  | 
| 75 79 | 
             
                it "returns Barometer::Location object" do
         | 
| 76 80 | 
             
                  geo = Data::Geo.new({})
         | 
| 77 | 
            -
                  location = WeatherService::Google. | 
| 81 | 
            +
                  location = WeatherService::Google._build_location(nil,geo)
         | 
| 78 82 | 
             
                  location.is_a?(Data::Location).should be_true
         | 
| 79 83 | 
             
                end
         | 
| 80 84 |  | 
| @@ -97,7 +101,7 @@ describe "Google" do | |
| 97 101 |  | 
| 98 102 | 
             
                before(:each) do
         | 
| 99 103 | 
             
                  @query = Barometer::Query.new("Calgary,AB")
         | 
| 100 | 
            -
                  @measurement =  | 
| 104 | 
            +
                  @measurement = Barometer::Measurement.new
         | 
| 101 105 |  | 
| 102 106 | 
             
                  FakeWeb.register_uri(:get, 
         | 
| 103 107 | 
             
                    "http://google.com/ig/api?weather=#{CGI.escape(@query.q)}&hl=en-GB",
         | 
| @@ -116,8 +120,8 @@ describe "Google" do | |
| 116 120 |  | 
| 117 121 | 
             
                  it "requires a Barometer::Measurement object" do
         | 
| 118 122 | 
             
                    lambda { Barometer::WeatherService::Google._measure(nil, @query) }.should raise_error(ArgumentError)
         | 
| 119 | 
            -
                    lambda { Barometer::WeatherService::Google._measure(" | 
| 120 | 
            -
             | 
| 123 | 
            +
                    lambda { Barometer::WeatherService::Google._measure("invalid", @query) }.should raise_error(ArgumentError)
         | 
| 124 | 
            +
             | 
| 121 125 | 
             
                    lambda { Barometer::WeatherService::Google._measure(@measurement, @query) }.should_not raise_error(ArgumentError)
         | 
| 122 126 | 
             
                  end
         | 
| 123 127 |  | 
| @@ -130,109 +134,15 @@ describe "Google" do | |
| 130 134 |  | 
| 131 135 | 
             
                  it "returns a Barometer::Measurement object" do
         | 
| 132 136 | 
             
                    result = Barometer::WeatherService::Google._measure(@measurement, @query)
         | 
| 133 | 
            -
                    result.is_a?( | 
| 134 | 
            -
                    result.current.is_a?( | 
| 135 | 
            -
                    result.forecast.is_a?( | 
| 136 | 
            -
                    
         | 
| 137 | 
            -
                    result.source.should == :google
         | 
| 137 | 
            +
                    result.is_a?(Barometer::Measurement).should be_true
         | 
| 138 | 
            +
                    result.current.is_a?(Measurement::Current).should be_true
         | 
| 139 | 
            +
                    result.forecast.is_a?(Measurement::ForecastArray).should be_true
         | 
| 138 140 | 
             
                  end
         | 
| 139 141 |  | 
| 140 142 | 
             
                end
         | 
| 141 143 |  | 
| 142 144 | 
             
              end
         | 
| 143 145 |  | 
| 144 | 
            -
              describe "when answering the simple questions," do
         | 
| 145 | 
            -
                
         | 
| 146 | 
            -
                before(:each) do
         | 
| 147 | 
            -
                  @measurement = Data::Measurement.new
         | 
| 148 | 
            -
                end
         | 
| 149 | 
            -
                
         | 
| 150 | 
            -
                describe "currently_wet_by_icon?" do
         | 
| 151 | 
            -
                  
         | 
| 152 | 
            -
                  before(:each) do
         | 
| 153 | 
            -
                    @measurement.current = Data::CurrentMeasurement.new
         | 
| 154 | 
            -
                  end
         | 
| 155 | 
            -
                
         | 
| 156 | 
            -
                  it "returns true if matching icon code" do
         | 
| 157 | 
            -
                    @measurement.current.icon = "rain"
         | 
| 158 | 
            -
                    @measurement.current.icon?.should be_true
         | 
| 159 | 
            -
                    WeatherService::Google.currently_wet_by_icon?(@measurement.current).should be_true
         | 
| 160 | 
            -
                  end
         | 
| 161 | 
            -
                  
         | 
| 162 | 
            -
                  it "returns false if NO matching icon code" do
         | 
| 163 | 
            -
                    @measurement.current.icon = "sunny"
         | 
| 164 | 
            -
                    @measurement.current.icon?.should be_true
         | 
| 165 | 
            -
                    WeatherService::Google.currently_wet_by_icon?(@measurement.current).should be_false
         | 
| 166 | 
            -
                  end
         | 
| 167 | 
            -
                  
         | 
| 168 | 
            -
                end
         | 
| 169 | 
            -
                
         | 
| 170 | 
            -
                describe "forecasted_wet_by_icon?" do
         | 
| 171 | 
            -
                  
         | 
| 172 | 
            -
                  before(:each) do
         | 
| 173 | 
            -
                    @measurement.forecast = [Data::ForecastMeasurement.new]
         | 
| 174 | 
            -
                    @measurement.forecast.first.date = Date.today
         | 
| 175 | 
            -
                    @measurement.forecast.size.should == 1
         | 
| 176 | 
            -
                  end
         | 
| 177 | 
            -
                
         | 
| 178 | 
            -
                  it "returns true if matching icon code" do
         | 
| 179 | 
            -
                    @measurement.forecast.first.icon = "rain"
         | 
| 180 | 
            -
                    @measurement.forecast.first.icon?.should be_true
         | 
| 181 | 
            -
                    WeatherService::Google.forecasted_wet_by_icon?(@measurement.forecast.first).should be_true
         | 
| 182 | 
            -
                  end
         | 
| 183 | 
            -
                  
         | 
| 184 | 
            -
                  it "returns false if NO matching icon code" do
         | 
| 185 | 
            -
                    @measurement.forecast.first.icon = "sunny"
         | 
| 186 | 
            -
                    @measurement.forecast.first.icon?.should be_true
         | 
| 187 | 
            -
                    WeatherService::Google.forecasted_wet_by_icon?(@measurement.forecast.first).should be_false
         | 
| 188 | 
            -
                  end
         | 
| 189 | 
            -
                  
         | 
| 190 | 
            -
                end
         | 
| 191 | 
            -
                
         | 
| 192 | 
            -
                describe "currently_sunny_by_icon?" do
         | 
| 193 | 
            -
                  
         | 
| 194 | 
            -
                  before(:each) do
         | 
| 195 | 
            -
                    @measurement.current = Data::CurrentMeasurement.new
         | 
| 196 | 
            -
                  end
         | 
| 197 | 
            -
             | 
| 198 | 
            -
                  it "returns true if matching icon code" do
         | 
| 199 | 
            -
                    @measurement.current.icon = "sunny"
         | 
| 200 | 
            -
                    @measurement.current.icon?.should be_true
         | 
| 201 | 
            -
                    WeatherService::Google.currently_sunny_by_icon?(@measurement.current).should be_true
         | 
| 202 | 
            -
                  end
         | 
| 203 | 
            -
                  
         | 
| 204 | 
            -
                  it "returns false if NO matching icon code" do
         | 
| 205 | 
            -
                    @measurement.current.icon = "rain"
         | 
| 206 | 
            -
                    @measurement.current.icon?.should be_true
         | 
| 207 | 
            -
                    WeatherService::Google.currently_sunny_by_icon?(@measurement.current).should be_false
         | 
| 208 | 
            -
                  end
         | 
| 209 | 
            -
                  
         | 
| 210 | 
            -
                end
         | 
| 211 | 
            -
                
         | 
| 212 | 
            -
                describe "forecasted_sunny_by_icon?" do
         | 
| 213 | 
            -
                  
         | 
| 214 | 
            -
                  before(:each) do
         | 
| 215 | 
            -
                    @measurement.forecast = [Data::ForecastMeasurement.new]
         | 
| 216 | 
            -
                    @measurement.forecast.first.date = Date.today
         | 
| 217 | 
            -
                    @measurement.forecast.size.should == 1
         | 
| 218 | 
            -
                  end
         | 
| 219 | 
            -
             | 
| 220 | 
            -
                  it "returns true if matching icon code" do
         | 
| 221 | 
            -
                    @measurement.forecast.first.icon = "sunny"
         | 
| 222 | 
            -
                    @measurement.forecast.first.icon?.should be_true
         | 
| 223 | 
            -
                    WeatherService::Google.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_true
         | 
| 224 | 
            -
                  end
         | 
| 225 | 
            -
                  
         | 
| 226 | 
            -
                  it "returns false if NO matching icon code" do
         | 
| 227 | 
            -
                    @measurement.forecast.first.icon = "rain"
         | 
| 228 | 
            -
                    @measurement.forecast.first.icon?.should be_true
         | 
| 229 | 
            -
                    WeatherService::Google.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_false
         | 
| 230 | 
            -
                  end
         | 
| 231 | 
            -
                  
         | 
| 232 | 
            -
                end
         | 
| 233 | 
            -
                
         | 
| 234 | 
            -
              end
         | 
| 235 | 
            -
              
         | 
| 236 146 | 
             
              # describe "overall data correctness" do
         | 
| 237 147 | 
             
              #   
         | 
| 238 148 | 
             
              #   before(:each) do
         | 
| @@ -47,30 +47,64 @@ describe "WeatherServices" do | |
| 47 47 |  | 
| 48 48 | 
             
                before(:each) do
         | 
| 49 49 | 
             
                  @service = Barometer::WeatherService.new
         | 
| 50 | 
            +
                  @measurement = Barometer::Measurement.new
         | 
| 51 | 
            +
                  @query = Barometer::Query.new("test")
         | 
| 52 | 
            +
                end
         | 
| 53 | 
            +
                
         | 
| 54 | 
            +
                it "defaults _meets_requirements?" do
         | 
| 55 | 
            +
                  Barometer::WeatherService.send("_meets_requirements?").should be_true
         | 
| 56 | 
            +
                end
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                it "stubs _source_name" do
         | 
| 59 | 
            +
                  lambda { Barometer::WeatherService.send("_source_name") }.should raise_error(NotImplementedError)
         | 
| 60 | 
            +
                end
         | 
| 61 | 
            +
             | 
| 62 | 
            +
                it "stubs _accepted_formats" do
         | 
| 63 | 
            +
                  lambda { Barometer::WeatherService.send("_accepted_formats") }.should raise_error(NotImplementedError)
         | 
| 50 64 | 
             
                end
         | 
| 51 65 |  | 
| 52 66 | 
             
                it "stubs _measure" do
         | 
| 53 | 
            -
                   | 
| 67 | 
            +
                  Barometer::WeatherService._measure(@measurement,@query,true).is_a?(Barometer::Measurement).should be_true
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
                
         | 
| 70 | 
            +
                it "stubs _build_extra" do
         | 
| 71 | 
            +
                  Barometer::WeatherService._build_extra.should be_nil
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
                
         | 
| 74 | 
            +
                it "stubs _fetch" do
         | 
| 75 | 
            +
                  Barometer::WeatherService._fetch.should be_nil
         | 
| 54 76 | 
             
                end
         | 
| 55 77 |  | 
| 56 | 
            -
                it "stubs  | 
| 57 | 
            -
                   | 
| 78 | 
            +
                it "stubs _build_current" do
         | 
| 79 | 
            +
                  Barometer::WeatherService._build_current.should be_nil
         | 
| 58 80 | 
             
                end
         | 
| 59 81 |  | 
| 60 | 
            -
                it " | 
| 61 | 
            -
                  Barometer::WeatherService. | 
| 82 | 
            +
                it "stubs _build_forecast" do
         | 
| 83 | 
            +
                  Barometer::WeatherService._build_forecast.should be_nil
         | 
| 62 84 | 
             
                end
         | 
| 63 85 |  | 
| 64 | 
            -
                it " | 
| 65 | 
            -
                  Barometer::WeatherService. | 
| 86 | 
            +
                it "stubs _build_location" do
         | 
| 87 | 
            +
                  Barometer::WeatherService._build_location.should be_nil
         | 
| 66 88 | 
             
                end
         | 
| 67 89 |  | 
| 68 | 
            -
                it " | 
| 69 | 
            -
                  Barometer::WeatherService. | 
| 90 | 
            +
                it "stubs _build_sun" do
         | 
| 91 | 
            +
                  Barometer::WeatherService._build_sun.should be_nil
         | 
| 70 92 | 
             
                end
         | 
| 71 93 |  | 
| 72 | 
            -
                it " | 
| 73 | 
            -
                   | 
| 94 | 
            +
                it "stubs _build_links" do
         | 
| 95 | 
            +
                  Barometer::WeatherService._build_links.should == {}
         | 
| 96 | 
            +
                end
         | 
| 97 | 
            +
                
         | 
| 98 | 
            +
                it "defaults _supports_country?" do
         | 
| 99 | 
            +
                  Barometer::WeatherService._supports_country?.should be_true
         | 
| 100 | 
            +
                end
         | 
| 101 | 
            +
                
         | 
| 102 | 
            +
                it "defaults _requires_keys?" do
         | 
| 103 | 
            +
                  Barometer::WeatherService._requires_keys?.should be_false
         | 
| 104 | 
            +
                end
         | 
| 105 | 
            +
                
         | 
| 106 | 
            +
                it "defaults _has_keys?" do
         | 
| 107 | 
            +
                  lambda { Barometer::WeatherService._has_keys? }.should raise_error(NotImplementedError)
         | 
| 74 108 | 
             
                end
         | 
| 75 109 |  | 
| 76 110 | 
             
              end
         | 
| @@ -81,7 +115,7 @@ describe "WeatherServices" do | |
| 81 115 | 
             
                  Barometer::WeatherService.respond_to?("measure").should be_true
         | 
| 82 116 | 
             
                end
         | 
| 83 117 |  | 
| 84 | 
            -
                # since Barometer::WeatherService defines the measure method, you could  | 
| 118 | 
            +
                # since Barometer::WeatherService defines the measure method, you could actually just
         | 
| 85 119 | 
             
                # call Barometer::WeatherService.measure ... but this will not invoke a specific
         | 
| 86 120 | 
             
                # weather API driver.  Make sure this usage raises an error.
         | 
| 87 121 | 
             
                it "requires an actuall driver" do
         | 
| @@ -94,1025 +128,16 @@ describe "WeatherServices" do | |
| 94 128 | 
             
                  lambda { Barometer::WeatherService.measure(@query) }.should_not raise_error(ArgumentError)
         | 
| 95 129 | 
             
                end
         | 
| 96 130 |  | 
| 97 | 
            -
                it "returns a  | 
| 98 | 
            -
                  @service.measure(@query).is_a?( | 
| 131 | 
            +
                it "returns a Barometer::Measurement object" do
         | 
| 132 | 
            +
                  @service.measure(@query).is_a?(Barometer::Measurement).should be_true
         | 
| 99 133 | 
             
                end
         | 
| 100 134 |  | 
| 101 135 | 
             
                it "returns current and future" do
         | 
| 102 136 | 
             
                  measurement = @service.measure(@query)
         | 
| 103 | 
            -
                  measurement.current.is_a?( | 
| 137 | 
            +
                  measurement.current.is_a?(Measurement::Current).should be_true
         | 
| 104 138 | 
             
                  measurement.forecast.is_a?(Array).should be_true
         | 
| 105 139 | 
             
                end
         | 
| 106 140 |  | 
| 107 141 | 
             
              end
         | 
| 108 142 |  | 
| 109 | 
            -
              describe "when answering the simple questions," do
         | 
| 110 | 
            -
                
         | 
| 111 | 
            -
                before(:each) do
         | 
| 112 | 
            -
                  # the function being tested was monkey patched in an earlier test
         | 
| 113 | 
            -
                  # so the original file must be reloaded
         | 
| 114 | 
            -
                  load 'lib/barometer/weather_services/service.rb'
         | 
| 115 | 
            -
                  
         | 
| 116 | 
            -
                  @measurement = Data::Measurement.new
         | 
| 117 | 
            -
                  @now = Data::LocalDateTime.parse("01-jan-2009 2:05 pm")
         | 
| 118 | 
            -
                end
         | 
| 119 | 
            -
                
         | 
| 120 | 
            -
                describe "windy?" do
         | 
| 121 | 
            -
                  
         | 
| 122 | 
            -
                  it "requires a measurement object" do
         | 
| 123 | 
            -
                    lambda { Barometer::WeatherService.windy? }.should raise_error(ArgumentError)
         | 
| 124 | 
            -
                    lambda { Barometer::WeatherService.windy?("a") }.should raise_error(ArgumentError)
         | 
| 125 | 
            -
                    lambda { Barometer::WeatherService.windy?(@measurement) }.should_not raise_error(ArgumentError)
         | 
| 126 | 
            -
                  end
         | 
| 127 | 
            -
                  
         | 
| 128 | 
            -
                  it "requires threshold as a number" do
         | 
| 129 | 
            -
                    lambda { Barometer::WeatherService.windy?(@measurement,"a") }.should raise_error(ArgumentError)
         | 
| 130 | 
            -
                    lambda { Barometer::WeatherService.windy?(@measurement,1) }.should_not raise_error(ArgumentError)
         | 
| 131 | 
            -
                    lambda { Barometer::WeatherService.windy?(@measurement,1.1) }.should_not raise_error(ArgumentError)
         | 
| 132 | 
            -
                  end
         | 
| 133 | 
            -
                  
         | 
| 134 | 
            -
                  it "requires time as a Data::LocalTime object" do
         | 
| 135 | 
            -
                    #lambda { Barometer::WeatherService.windy?(@measurement,1,"a") }.should raise_error(ArgumentError)
         | 
| 136 | 
            -
                    lambda { Barometer::WeatherService.windy?(@measurement,1,@now) }.should_not raise_error(ArgumentError)
         | 
| 137 | 
            -
                  end
         | 
| 138 | 
            -
             | 
| 139 | 
            -
                  it "stubs forecasted_windy?" do
         | 
| 140 | 
            -
                    Barometer::WeatherService.forecasted_windy?(@measurement,nil,nil).should be_nil
         | 
| 141 | 
            -
                  end
         | 
| 142 | 
            -
                  
         | 
| 143 | 
            -
                  describe "and is current" do
         | 
| 144 | 
            -
                    
         | 
| 145 | 
            -
                    before(:each) do
         | 
| 146 | 
            -
                      module Barometer; class Data::Measurement
         | 
| 147 | 
            -
                        def current?(a=nil); true; end
         | 
| 148 | 
            -
                      end; end
         | 
| 149 | 
            -
                    end
         | 
| 150 | 
            -
                  
         | 
| 151 | 
            -
                    it "returns nil" do
         | 
| 152 | 
            -
                      Barometer::WeatherService.windy?(@measurement).should be_nil
         | 
| 153 | 
            -
                    end
         | 
| 154 | 
            -
                    
         | 
| 155 | 
            -
                    it "returns true if currently_windy?" do
         | 
| 156 | 
            -
                      module Barometer; class WeatherService
         | 
| 157 | 
            -
                        def self.currently_windy?(a=nil,b=nil); true; end
         | 
| 158 | 
            -
                      end; end
         | 
| 159 | 
            -
                      Barometer::WeatherService.windy?(@measurement).should be_true
         | 
| 160 | 
            -
                    end
         | 
| 161 | 
            -
             | 
| 162 | 
            -
                    it "returns false if !currently_windy?" do
         | 
| 163 | 
            -
                      module Barometer; class WeatherService
         | 
| 164 | 
            -
                        def self.currently_windy?(a=nil,b=nil); false; end
         | 
| 165 | 
            -
                      end; end
         | 
| 166 | 
            -
                      Barometer::WeatherService.windy?(@measurement).should be_false
         | 
| 167 | 
            -
                    end
         | 
| 168 | 
            -
                    
         | 
| 169 | 
            -
                  end
         | 
| 170 | 
            -
                  
         | 
| 171 | 
            -
                  describe "and is NOT current" do
         | 
| 172 | 
            -
                    
         | 
| 173 | 
            -
                    before(:each) do
         | 
| 174 | 
            -
                      module Barometer; class Data::Measurement
         | 
| 175 | 
            -
                        def current?(a=nil); false; end
         | 
| 176 | 
            -
                      end; end
         | 
| 177 | 
            -
                    end
         | 
| 178 | 
            -
                  
         | 
| 179 | 
            -
                    it "returns nil" do
         | 
| 180 | 
            -
                      Barometer::WeatherService.windy?(@measurement).should be_nil
         | 
| 181 | 
            -
                    end
         | 
| 182 | 
            -
                    
         | 
| 183 | 
            -
                    it "returns true if forecasted_windy?" do
         | 
| 184 | 
            -
                      module Barometer; class WeatherService
         | 
| 185 | 
            -
                        def self.forecasted_windy?(a=nil,b=nil,c=nil); true; end
         | 
| 186 | 
            -
                      end; end
         | 
| 187 | 
            -
                      Barometer::WeatherService.windy?(@measurement).should be_true
         | 
| 188 | 
            -
                    end
         | 
| 189 | 
            -
             | 
| 190 | 
            -
                    it "returns false if !forecasted_windy?" do
         | 
| 191 | 
            -
                      module Barometer; class WeatherService
         | 
| 192 | 
            -
                        def self.forecasted_windy?(a=nil,b=nil,c=nil); false; end
         | 
| 193 | 
            -
                      end; end
         | 
| 194 | 
            -
                      Barometer::WeatherService.windy?(@measurement).should be_false
         | 
| 195 | 
            -
                    end
         | 
| 196 | 
            -
                    
         | 
| 197 | 
            -
                  end
         | 
| 198 | 
            -
                  
         | 
| 199 | 
            -
                end
         | 
| 200 | 
            -
                
         | 
| 201 | 
            -
                describe "currently_windy?" do
         | 
| 202 | 
            -
             | 
| 203 | 
            -
                  before(:each) do
         | 
| 204 | 
            -
                    # the function being tested was monkey patched in an earlier test
         | 
| 205 | 
            -
                    # so the original file must be reloaded
         | 
| 206 | 
            -
                    load 'lib/barometer/weather_services/service.rb'
         | 
| 207 | 
            -
                    
         | 
| 208 | 
            -
                    @measurement = Data::Measurement.new
         | 
| 209 | 
            -
                    @threshold = 10
         | 
| 210 | 
            -
                  end
         | 
| 211 | 
            -
             | 
| 212 | 
            -
                  it "requires a measurement object" do
         | 
| 213 | 
            -
                    lambda { Barometer::WeatherService.currently_windy? }.should raise_error(ArgumentError)
         | 
| 214 | 
            -
                    lambda { Barometer::WeatherService.currently_windy?("a") }.should raise_error(ArgumentError)
         | 
| 215 | 
            -
                    lambda { Barometer::WeatherService.currently_windy?(@measurement) }.should_not raise_error(ArgumentError)
         | 
| 216 | 
            -
                  end
         | 
| 217 | 
            -
             | 
| 218 | 
            -
                  it "requires threshold as a number" do
         | 
| 219 | 
            -
                    lambda { Barometer::WeatherService.currently_windy?(@measurement,"a") }.should raise_error(ArgumentError)
         | 
| 220 | 
            -
                    lambda { Barometer::WeatherService.currently_windy?(@measurement,1) }.should_not raise_error(ArgumentError)
         | 
| 221 | 
            -
                    lambda { Barometer::WeatherService.currently_windy?(@measurement,1.1) }.should_not raise_error(ArgumentError)
         | 
| 222 | 
            -
                  end
         | 
| 223 | 
            -
             | 
| 224 | 
            -
                  it "returns nil when value unavailable" do
         | 
| 225 | 
            -
                    measurement = Data::Measurement.new
         | 
| 226 | 
            -
                    Barometer::WeatherService.currently_windy?(measurement,@threshold).should be_nil
         | 
| 227 | 
            -
                    measurement.current = Data::CurrentMeasurement.new
         | 
| 228 | 
            -
                    Barometer::WeatherService.currently_windy?(measurement,@threshold).should be_nil
         | 
| 229 | 
            -
                    measurement.current.wind = Data::Speed.new
         | 
| 230 | 
            -
                    Barometer::WeatherService.currently_windy?(measurement,@threshold).should be_nil
         | 
| 231 | 
            -
                  end
         | 
| 232 | 
            -
             | 
| 233 | 
            -
                  describe "when metric" do
         | 
| 234 | 
            -
             | 
| 235 | 
            -
                    before(:each) do
         | 
| 236 | 
            -
                      @measurement = Data::Measurement.new
         | 
| 237 | 
            -
                      @measurement.current = Data::CurrentMeasurement.new
         | 
| 238 | 
            -
                      @measurement.current.wind = Data::Speed.new
         | 
| 239 | 
            -
                      @measurement.metric!
         | 
| 240 | 
            -
                      @measurement.metric?.should be_true
         | 
| 241 | 
            -
                    end
         | 
| 242 | 
            -
             | 
| 243 | 
            -
                    # measurement.current.wind.kph.to_f
         | 
| 244 | 
            -
                    it "returns true when wind speed (kph) above threshold" do
         | 
| 245 | 
            -
                      @measurement.current.wind.kph = @threshold + 1
         | 
| 246 | 
            -
                      Barometer::WeatherService.currently_windy?(@measurement,@threshold).should be_true
         | 
| 247 | 
            -
                    end
         | 
| 248 | 
            -
             | 
| 249 | 
            -
                    it "returns false when wind speed (kph) below threshold" do
         | 
| 250 | 
            -
                      @measurement.current.wind.kph = @threshold - 1
         | 
| 251 | 
            -
                      Barometer::WeatherService.currently_windy?(@measurement,@threshold).should be_false
         | 
| 252 | 
            -
                    end
         | 
| 253 | 
            -
             | 
| 254 | 
            -
                  end
         | 
| 255 | 
            -
             | 
| 256 | 
            -
                  describe "when imperial" do
         | 
| 257 | 
            -
             | 
| 258 | 
            -
                    before(:each) do
         | 
| 259 | 
            -
                      @measurement = Data::Measurement.new
         | 
| 260 | 
            -
                      @measurement.current = Data::CurrentMeasurement.new
         | 
| 261 | 
            -
                      @measurement.current.wind = Data::Speed.new
         | 
| 262 | 
            -
                      @measurement.imperial!
         | 
| 263 | 
            -
                      @measurement.metric?.should be_false
         | 
| 264 | 
            -
                    end
         | 
| 265 | 
            -
             | 
| 266 | 
            -
                    it "returns true when wind speed (mph) above threshold" do
         | 
| 267 | 
            -
                      @measurement.current.wind.mph = @threshold - 1
         | 
| 268 | 
            -
                      Barometer::WeatherService.currently_windy?(@measurement,@threshold).should be_false
         | 
| 269 | 
            -
                    end
         | 
| 270 | 
            -
             | 
| 271 | 
            -
                    it "returns false when wind speed (mph) below threshold" do
         | 
| 272 | 
            -
                      @measurement.current.wind.mph = @threshold - 1
         | 
| 273 | 
            -
                      Barometer::WeatherService.currently_windy?(@measurement,@threshold).should be_false
         | 
| 274 | 
            -
                    end
         | 
| 275 | 
            -
             | 
| 276 | 
            -
                  end
         | 
| 277 | 
            -
             | 
| 278 | 
            -
                end
         | 
| 279 | 
            -
                
         | 
| 280 | 
            -
                describe "wet?" do
         | 
| 281 | 
            -
                  
         | 
| 282 | 
            -
                  it "requires a measurement object" do
         | 
| 283 | 
            -
                    lambda { Barometer::WeatherService.wet? }.should raise_error(ArgumentError)
         | 
| 284 | 
            -
                    lambda { Barometer::WeatherService.wet?("a") }.should raise_error(ArgumentError)
         | 
| 285 | 
            -
                    lambda { Barometer::WeatherService.wet?(@measurement) }.should_not raise_error(ArgumentError)
         | 
| 286 | 
            -
                  end
         | 
| 287 | 
            -
                  
         | 
| 288 | 
            -
                  it "requires threshold as a number" do
         | 
| 289 | 
            -
                    lambda { Barometer::WeatherService.wet?(@measurement,"a") }.should raise_error(ArgumentError)
         | 
| 290 | 
            -
                    lambda { Barometer::WeatherService.wet?(@measurement,1) }.should_not raise_error(ArgumentError)
         | 
| 291 | 
            -
                    lambda { Barometer::WeatherService.wet?(@measurement,1.1) }.should_not raise_error(ArgumentError)
         | 
| 292 | 
            -
                  end
         | 
| 293 | 
            -
                  
         | 
| 294 | 
            -
                  it "requires time as a Data::LocalTime object" do
         | 
| 295 | 
            -
                    #lambda { Barometer::WeatherService.wet?(@measurement,1,"a") }.should raise_error(ArgumentError)
         | 
| 296 | 
            -
                    lambda { Barometer::WeatherService.wet?(@measurement,1,@now) }.should_not raise_error(ArgumentError)
         | 
| 297 | 
            -
                  end
         | 
| 298 | 
            -
             | 
| 299 | 
            -
                  describe "and is current" do
         | 
| 300 | 
            -
                    
         | 
| 301 | 
            -
                    before(:each) do
         | 
| 302 | 
            -
                      module Barometer; class Data::Measurement
         | 
| 303 | 
            -
                        def current?(a=nil); true; end
         | 
| 304 | 
            -
                      end; end
         | 
| 305 | 
            -
                    end
         | 
| 306 | 
            -
                  
         | 
| 307 | 
            -
                    it "returns nil" do
         | 
| 308 | 
            -
                      Barometer::WeatherService.wet?(@measurement).should be_nil
         | 
| 309 | 
            -
                    end
         | 
| 310 | 
            -
                    
         | 
| 311 | 
            -
                    it "returns true if currently_wet?" do
         | 
| 312 | 
            -
                      module Barometer; class WeatherService
         | 
| 313 | 
            -
                        def self.currently_wet?(a=nil,b=nil); true; end
         | 
| 314 | 
            -
                      end; end
         | 
| 315 | 
            -
                      Barometer::WeatherService.wet?(@measurement).should be_true
         | 
| 316 | 
            -
                    end
         | 
| 317 | 
            -
             | 
| 318 | 
            -
                    it "returns false if !currently_wet?" do
         | 
| 319 | 
            -
                      module Barometer; class WeatherService
         | 
| 320 | 
            -
                        def self.currently_wet?(a=nil,b=nil); false; end
         | 
| 321 | 
            -
                      end; end
         | 
| 322 | 
            -
                      Barometer::WeatherService.wet?(@measurement).should be_false
         | 
| 323 | 
            -
                    end
         | 
| 324 | 
            -
                    
         | 
| 325 | 
            -
                  end
         | 
| 326 | 
            -
                  
         | 
| 327 | 
            -
                  describe "and is NOT current" do
         | 
| 328 | 
            -
                    
         | 
| 329 | 
            -
                    before(:each) do
         | 
| 330 | 
            -
                      module Barometer; class Data::Measurement
         | 
| 331 | 
            -
                        def current?(a=nil); false; end
         | 
| 332 | 
            -
                      end; end
         | 
| 333 | 
            -
                    end
         | 
| 334 | 
            -
                  
         | 
| 335 | 
            -
                    it "returns nil" do
         | 
| 336 | 
            -
                      Barometer::WeatherService.wet?(@measurement).should be_nil
         | 
| 337 | 
            -
                    end
         | 
| 338 | 
            -
                    
         | 
| 339 | 
            -
                    it "returns true if forecasted_wet?" do
         | 
| 340 | 
            -
                      module Barometer; class WeatherService
         | 
| 341 | 
            -
                        def self.forecasted_wet?(a=nil,b=nil,c=nil); true; end
         | 
| 342 | 
            -
                      end; end
         | 
| 343 | 
            -
                      Barometer::WeatherService.wet?(@measurement).should be_true
         | 
| 344 | 
            -
                    end
         | 
| 345 | 
            -
             | 
| 346 | 
            -
                    it "returns false if !forecasted_wet?" do
         | 
| 347 | 
            -
                      module Barometer; class WeatherService
         | 
| 348 | 
            -
                        def self.forecasted_wet?(a=nil,b=nil,c=nil); false; end
         | 
| 349 | 
            -
                      end; end
         | 
| 350 | 
            -
                      Barometer::WeatherService.wet?(@measurement).should be_false
         | 
| 351 | 
            -
                    end
         | 
| 352 | 
            -
                    
         | 
| 353 | 
            -
                  end
         | 
| 354 | 
            -
                  
         | 
| 355 | 
            -
                end
         | 
| 356 | 
            -
                
         | 
| 357 | 
            -
                describe "currently_wet?" do
         | 
| 358 | 
            -
                
         | 
| 359 | 
            -
                  before(:each) do
         | 
| 360 | 
            -
                    # the function being tested was monkey patched in an earlier test
         | 
| 361 | 
            -
                    # so the original file must be reloaded
         | 
| 362 | 
            -
                    load 'lib/barometer/weather_services/service.rb'
         | 
| 363 | 
            -
                    
         | 
| 364 | 
            -
                    @measurement = Data::Measurement.new
         | 
| 365 | 
            -
                    @threshold = 10
         | 
| 366 | 
            -
                    @temperature = 15
         | 
| 367 | 
            -
                  end
         | 
| 368 | 
            -
                
         | 
| 369 | 
            -
                  it "requires a measurement object" do
         | 
| 370 | 
            -
                    lambda { Barometer::WeatherService.currently_wet? }.should raise_error(ArgumentError)
         | 
| 371 | 
            -
                    lambda { Barometer::WeatherService.currently_wet?("a") }.should raise_error(ArgumentError)
         | 
| 372 | 
            -
                    lambda { Barometer::WeatherService.currently_wet?(@measurement) }.should_not raise_error(ArgumentError)
         | 
| 373 | 
            -
                  end
         | 
| 374 | 
            -
                
         | 
| 375 | 
            -
                  it "requires threshold as a number" do
         | 
| 376 | 
            -
                    lambda { Barometer::WeatherService.currently_wet?(@measurement,"a") }.should raise_error(ArgumentError)
         | 
| 377 | 
            -
                    lambda { Barometer::WeatherService.currently_wet?(@measurement,1) }.should_not raise_error(ArgumentError)
         | 
| 378 | 
            -
                    lambda { Barometer::WeatherService.currently_wet?(@measurement,1.1) }.should_not raise_error(ArgumentError)
         | 
| 379 | 
            -
                  end
         | 
| 380 | 
            -
                
         | 
| 381 | 
            -
                  it "returns nil when value unavailable" do
         | 
| 382 | 
            -
                    measurement = Data::Measurement.new
         | 
| 383 | 
            -
                    Barometer::WeatherService.currently_wet?(measurement,@threshold).should be_nil
         | 
| 384 | 
            -
                    measurement.current = Data::CurrentMeasurement.new
         | 
| 385 | 
            -
                    Barometer::WeatherService.currently_wet?(measurement,@threshold).should be_nil
         | 
| 386 | 
            -
                    measurement.current.wind = Data::Speed.new
         | 
| 387 | 
            -
                    Barometer::WeatherService.currently_wet?(measurement,@threshold).should be_nil
         | 
| 388 | 
            -
                  end
         | 
| 389 | 
            -
                  
         | 
| 390 | 
            -
                  describe "currently_wet_by_icon?" do
         | 
| 391 | 
            -
             | 
| 392 | 
            -
                    before(:each) do
         | 
| 393 | 
            -
                      @measurement.current = Data::CurrentMeasurement.new
         | 
| 394 | 
            -
                    end
         | 
| 395 | 
            -
             | 
| 396 | 
            -
                    it "requires a Barometer::Measurement object" do
         | 
| 397 | 
            -
                      lambda { Barometer::WeatherService.currently_wet_by_icon?(nil) }.should raise_error(ArgumentError)
         | 
| 398 | 
            -
                      lambda { Barometer::WeatherService.currently_wet_by_icon?("invlaid") }.should raise_error(ArgumentError)
         | 
| 399 | 
            -
             | 
| 400 | 
            -
                      lambda { Barometer::WeatherService.currently_wet_by_icon?(@measurement.current) }.should_not raise_error(ArgumentError)
         | 
| 401 | 
            -
                    end
         | 
| 402 | 
            -
             | 
| 403 | 
            -
                    it "returns nil if no icon" do
         | 
| 404 | 
            -
                      @measurement.current.icon?.should be_false
         | 
| 405 | 
            -
                      Barometer::WeatherService.currently_wet_by_icon?(@measurement.current).should be_nil
         | 
| 406 | 
            -
                    end
         | 
| 407 | 
            -
             | 
| 408 | 
            -
                    it "returns true if matching icon code" do
         | 
| 409 | 
            -
                      module Barometer; class WeatherService; def self.wet_icon_codes
         | 
| 410 | 
            -
                        ["rain"]
         | 
| 411 | 
            -
                      end; end; end
         | 
| 412 | 
            -
                      @measurement.current.icon = "rain"
         | 
| 413 | 
            -
                      @measurement.current.icon?.should be_true
         | 
| 414 | 
            -
                      Barometer::WeatherService.currently_wet_by_icon?(@measurement.current).should be_true
         | 
| 415 | 
            -
                    end
         | 
| 416 | 
            -
             | 
| 417 | 
            -
                    it "returns false if NO matching icon code" do
         | 
| 418 | 
            -
                      module Barometer; class WeatherService; def self.wet_icon_codes
         | 
| 419 | 
            -
                        ["rain"]
         | 
| 420 | 
            -
                      end; end; end
         | 
| 421 | 
            -
                      @measurement.current.icon = "sunny"
         | 
| 422 | 
            -
                      @measurement.current.icon?.should be_true
         | 
| 423 | 
            -
                      Barometer::WeatherService.currently_wet_by_icon?(@measurement.current).should be_false
         | 
| 424 | 
            -
                    end
         | 
| 425 | 
            -
             | 
| 426 | 
            -
                  end
         | 
| 427 | 
            -
                  
         | 
| 428 | 
            -
                  describe "and currently_wet_by_dewpoint?" do
         | 
| 429 | 
            -
                    
         | 
| 430 | 
            -
                    describe "when metric" do
         | 
| 431 | 
            -
             
         | 
| 432 | 
            -
                      before(:each) do
         | 
| 433 | 
            -
                        @measurement = Data::Measurement.new
         | 
| 434 | 
            -
                        @measurement.current = Data::CurrentMeasurement.new
         | 
| 435 | 
            -
                        @measurement.current.temperature = Data::Temperature.new
         | 
| 436 | 
            -
                        @measurement.current.dew_point = Data::Temperature.new
         | 
| 437 | 
            -
                        @measurement.metric!
         | 
| 438 | 
            -
                        @measurement.metric?.should be_true
         | 
| 439 | 
            -
                      end
         | 
| 440 | 
            -
                      
         | 
| 441 | 
            -
                      it "returns true when temperature < dew_point" do
         | 
| 442 | 
            -
                        @measurement.current.temperature.c = @temperature
         | 
| 443 | 
            -
                        @measurement.current.dew_point.c = @temperature + 1
         | 
| 444 | 
            -
                        Barometer::WeatherService.currently_wet_by_dewpoint?(@measurement).should be_true
         | 
| 445 | 
            -
                      end
         | 
| 446 | 
            -
                    
         | 
| 447 | 
            -
                      it "returns false when temperature > dew_point" do
         | 
| 448 | 
            -
                        @measurement.current.temperature.c = @temperature
         | 
| 449 | 
            -
                        @measurement.current.dew_point.c = @temperature - 1
         | 
| 450 | 
            -
                        Barometer::WeatherService.currently_wet_by_dewpoint?(@measurement).should be_false
         | 
| 451 | 
            -
                      end
         | 
| 452 | 
            -
                      
         | 
| 453 | 
            -
                    end
         | 
| 454 | 
            -
                    
         | 
| 455 | 
            -
                    describe "when imperial" do
         | 
| 456 | 
            -
                      
         | 
| 457 | 
            -
                      before(:each) do
         | 
| 458 | 
            -
                        @measurement = Data::Measurement.new
         | 
| 459 | 
            -
                        @measurement.current = Data::CurrentMeasurement.new
         | 
| 460 | 
            -
                        @measurement.current.temperature = Data::Temperature.new
         | 
| 461 | 
            -
                        @measurement.current.dew_point = Data::Temperature.new
         | 
| 462 | 
            -
                        @measurement.imperial!
         | 
| 463 | 
            -
                        @measurement.metric?.should be_false
         | 
| 464 | 
            -
                      end
         | 
| 465 | 
            -
             | 
| 466 | 
            -
                      it "returns true when temperature < dew_point" do
         | 
| 467 | 
            -
                        @measurement.current.temperature.f = @temperature
         | 
| 468 | 
            -
                        @measurement.current.dew_point.f = @temperature + 1
         | 
| 469 | 
            -
                        Barometer::WeatherService.currently_wet_by_dewpoint?(@measurement).should be_true
         | 
| 470 | 
            -
                      end
         | 
| 471 | 
            -
             | 
| 472 | 
            -
                      it "returns false when temperature > dew_point" do
         | 
| 473 | 
            -
                        @measurement.current.temperature.f = @temperature
         | 
| 474 | 
            -
                        @measurement.current.dew_point.f = @temperature - 1
         | 
| 475 | 
            -
                        Barometer::WeatherService.currently_wet_by_dewpoint?(@measurement).should be_false
         | 
| 476 | 
            -
                      end
         | 
| 477 | 
            -
             | 
| 478 | 
            -
                    end
         | 
| 479 | 
            -
                  
         | 
| 480 | 
            -
                  end
         | 
| 481 | 
            -
                  
         | 
| 482 | 
            -
                  describe "and currently_wet_by_humidity?" do
         | 
| 483 | 
            -
                    
         | 
| 484 | 
            -
                    before(:each) do
         | 
| 485 | 
            -
                      @measurement = Data::Measurement.new
         | 
| 486 | 
            -
                      @measurement.current = Data::CurrentMeasurement.new
         | 
| 487 | 
            -
                    end
         | 
| 488 | 
            -
                    
         | 
| 489 | 
            -
                    it "returns true when humidity >= 99%" do
         | 
| 490 | 
            -
                      @measurement.current.humidity = 99
         | 
| 491 | 
            -
                      Barometer::WeatherService.currently_wet_by_humidity?(@measurement.current).should be_true
         | 
| 492 | 
            -
                      @measurement.current.humidity = 100
         | 
| 493 | 
            -
                      Barometer::WeatherService.currently_wet_by_humidity?(@measurement.current).should be_true
         | 
| 494 | 
            -
                    end
         | 
| 495 | 
            -
                  
         | 
| 496 | 
            -
                    it "returns false when humidity < 99%" do
         | 
| 497 | 
            -
                      @measurement.current.humidity = 98
         | 
| 498 | 
            -
                      Barometer::WeatherService.currently_wet_by_humidity?(@measurement.current).should be_false
         | 
| 499 | 
            -
                    end
         | 
| 500 | 
            -
                    
         | 
| 501 | 
            -
                  end
         | 
| 502 | 
            -
                  
         | 
| 503 | 
            -
                  describe "and currently_wet_by_pop?" do
         | 
| 504 | 
            -
                    
         | 
| 505 | 
            -
                    before(:each) do
         | 
| 506 | 
            -
                      @measurement = Data::Measurement.new
         | 
| 507 | 
            -
                      @measurement.forecast = [Data::ForecastMeasurement.new]
         | 
| 508 | 
            -
                      @measurement.forecast.first.date = Date.today
         | 
| 509 | 
            -
                      @measurement.forecast.size.should == 1
         | 
| 510 | 
            -
                    end
         | 
| 511 | 
            -
                    
         | 
| 512 | 
            -
                    it "returns true when pop (%) above threshold" do
         | 
| 513 | 
            -
                      @measurement.forecast.first.pop = @threshold + 1
         | 
| 514 | 
            -
                      Barometer::WeatherService.currently_wet_by_pop?(@measurement, @threshold).should be_true
         | 
| 515 | 
            -
                    end
         | 
| 516 | 
            -
             | 
| 517 | 
            -
                    it "returns false when pop (%) below threshold" do
         | 
| 518 | 
            -
                      @measurement.forecast.first.pop = @threshold - 1
         | 
| 519 | 
            -
                      Barometer::WeatherService.currently_wet_by_pop?(@measurement, @threshold).should be_false
         | 
| 520 | 
            -
                    end
         | 
| 521 | 
            -
                    
         | 
| 522 | 
            -
                  end
         | 
| 523 | 
            -
                
         | 
| 524 | 
            -
                end
         | 
| 525 | 
            -
                
         | 
| 526 | 
            -
                describe "forecasted_wet?" do
         | 
| 527 | 
            -
                
         | 
| 528 | 
            -
                  before(:each) do
         | 
| 529 | 
            -
                    # the function being tested was monkey patched in an earlier test
         | 
| 530 | 
            -
                    # so the original file must be reloaded
         | 
| 531 | 
            -
                    load 'lib/barometer/weather_services/service.rb'
         | 
| 532 | 
            -
                    
         | 
| 533 | 
            -
                    @measurement = Data::Measurement.new
         | 
| 534 | 
            -
                    @threshold = 10
         | 
| 535 | 
            -
                    @temperature = 15
         | 
| 536 | 
            -
                  end
         | 
| 537 | 
            -
                
         | 
| 538 | 
            -
                  it "requires a measurement object" do
         | 
| 539 | 
            -
                    lambda { Barometer::WeatherService.forecasted_wet? }.should raise_error(ArgumentError)
         | 
| 540 | 
            -
                    lambda { Barometer::WeatherService.forecasted_wet?("a") }.should raise_error(ArgumentError)
         | 
| 541 | 
            -
                    lambda { Barometer::WeatherService.forecasted_wet?(@measurement) }.should_not raise_error(ArgumentError)
         | 
| 542 | 
            -
                  end
         | 
| 543 | 
            -
             | 
| 544 | 
            -
                  it "requires threshold as a number" do
         | 
| 545 | 
            -
                    lambda { Barometer::WeatherService.forecasted_wet?(@measurement,"a") }.should raise_error(ArgumentError)
         | 
| 546 | 
            -
                    lambda { Barometer::WeatherService.forecasted_wet?(@measurement,1) }.should_not raise_error(ArgumentError)
         | 
| 547 | 
            -
                    lambda { Barometer::WeatherService.forecasted_wet?(@measurement,1.1) }.should_not raise_error(ArgumentError)
         | 
| 548 | 
            -
                  end
         | 
| 549 | 
            -
             | 
| 550 | 
            -
                  it "requires utc_time as a Data::LocalTime object" do
         | 
| 551 | 
            -
                    #lambda { Barometer::WeatherService.forecasted_wet?(@measurement,1,"string") }.should raise_error(ArgumentError)
         | 
| 552 | 
            -
                    lambda { Barometer::WeatherService.forecasted_wet?(@measurement,1,@now) }.should_not raise_error(ArgumentError)
         | 
| 553 | 
            -
                  end
         | 
| 554 | 
            -
             | 
| 555 | 
            -
                  it "returns nil when value unavailable" do
         | 
| 556 | 
            -
                    measurement = Data::Measurement.new
         | 
| 557 | 
            -
                    Barometer::WeatherService.forecasted_wet?(measurement,@threshold).should be_nil
         | 
| 558 | 
            -
                    measurement.forecast = [Data::ForecastMeasurement.new]
         | 
| 559 | 
            -
                    Barometer::WeatherService.forecasted_wet?(measurement,@threshold).should be_nil
         | 
| 560 | 
            -
                  end
         | 
| 561 | 
            -
                  
         | 
| 562 | 
            -
                  describe "forecasted_wet_by_icon?" do
         | 
| 563 | 
            -
             | 
| 564 | 
            -
                    before(:each) do
         | 
| 565 | 
            -
                      @measurement.forecast = [Data::ForecastMeasurement.new]
         | 
| 566 | 
            -
                      @measurement.forecast.first.date = Date.today
         | 
| 567 | 
            -
                      @measurement.forecast.size.should == 1
         | 
| 568 | 
            -
                    end
         | 
| 569 | 
            -
             | 
| 570 | 
            -
                    it "requires a Barometer::Measurement object" do
         | 
| 571 | 
            -
                      lambda { Barometer::WeatherService.forecasted_wet_by_icon?(nil) }.should raise_error(ArgumentError)
         | 
| 572 | 
            -
                      lambda { Barometer::WeatherService.forecasted_wet_by_icon?("invlaid") }.should raise_error(ArgumentError)
         | 
| 573 | 
            -
             | 
| 574 | 
            -
                      lambda { Barometer::WeatherService.forecasted_wet_by_icon?(@measurement.forecast.first) }.should_not raise_error(ArgumentError)
         | 
| 575 | 
            -
                    end
         | 
| 576 | 
            -
             | 
| 577 | 
            -
                    it "returns nil if no icon" do
         | 
| 578 | 
            -
                      @measurement.forecast.first.icon?.should be_false
         | 
| 579 | 
            -
                      Barometer::WeatherService.forecasted_wet_by_icon?(@measurement.forecast.first).should be_nil
         | 
| 580 | 
            -
                    end
         | 
| 581 | 
            -
             | 
| 582 | 
            -
                    it "returns true if matching icon code" do
         | 
| 583 | 
            -
                      module Barometer; class WeatherService; def self.wet_icon_codes
         | 
| 584 | 
            -
                        ["rain"]
         | 
| 585 | 
            -
                      end; end; end
         | 
| 586 | 
            -
                      @measurement.forecast.first.icon = "rain"
         | 
| 587 | 
            -
                      @measurement.forecast.first.icon?.should be_true
         | 
| 588 | 
            -
                      Barometer::WeatherService.forecasted_wet_by_icon?(@measurement.forecast.first).should be_true
         | 
| 589 | 
            -
                    end
         | 
| 590 | 
            -
             | 
| 591 | 
            -
                    it "returns false if NO matching icon code" do
         | 
| 592 | 
            -
                      module Barometer; class WeatherService; def self.wet_icon_codes
         | 
| 593 | 
            -
                        ["rain"]
         | 
| 594 | 
            -
                      end; end; end
         | 
| 595 | 
            -
                      @measurement.forecast.first.icon = "sunny"
         | 
| 596 | 
            -
                      @measurement.forecast.first.icon?.should be_true
         | 
| 597 | 
            -
                      Barometer::WeatherService.forecasted_wet_by_icon?(@measurement.forecast.first).should be_false
         | 
| 598 | 
            -
                    end
         | 
| 599 | 
            -
             | 
| 600 | 
            -
                    after(:each) do
         | 
| 601 | 
            -
                      # the function being tested was monkey patched in an earlier test
         | 
| 602 | 
            -
                      # so the original file must be reloaded
         | 
| 603 | 
            -
                      load 'lib/barometer/weather_services/service.rb'
         | 
| 604 | 
            -
                    end
         | 
| 605 | 
            -
             | 
| 606 | 
            -
                  end
         | 
| 607 | 
            -
             | 
| 608 | 
            -
                  describe "and forecasted_wet_by_pop?" do
         | 
| 609 | 
            -
                    
         | 
| 610 | 
            -
                    before(:each) do
         | 
| 611 | 
            -
                      @measurement = Data::Measurement.new
         | 
| 612 | 
            -
                      @measurement.forecast = [Data::ForecastMeasurement.new]
         | 
| 613 | 
            -
                      @measurement.forecast.first.date = Date.today
         | 
| 614 | 
            -
                      @measurement.forecast.size.should == 1
         | 
| 615 | 
            -
                    end
         | 
| 616 | 
            -
                    
         | 
| 617 | 
            -
                    it "returns true when pop (%) above threshold" do
         | 
| 618 | 
            -
                      @measurement.forecast.first.pop = @threshold + 1
         | 
| 619 | 
            -
                      Barometer::WeatherService.forecasted_wet_by_pop?(@measurement.forecast.first, @threshold).should be_true
         | 
| 620 | 
            -
                    end
         | 
| 621 | 
            -
             | 
| 622 | 
            -
                    it "returns false when pop (%) below threshold" do
         | 
| 623 | 
            -
                      @measurement.forecast.first.pop = @threshold - 1
         | 
| 624 | 
            -
                      Barometer::WeatherService.forecasted_wet_by_pop?(@measurement.forecast.first, @threshold).should be_false
         | 
| 625 | 
            -
                    end
         | 
| 626 | 
            -
                    
         | 
| 627 | 
            -
                  end
         | 
| 628 | 
            -
             | 
| 629 | 
            -
                end
         | 
| 630 | 
            -
                
         | 
| 631 | 
            -
                describe "day?" do
         | 
| 632 | 
            -
                  
         | 
| 633 | 
            -
                  it "requires a measurement object" do
         | 
| 634 | 
            -
                    lambda { Barometer::WeatherService.day? }.should raise_error(ArgumentError)
         | 
| 635 | 
            -
                    lambda { Barometer::WeatherService.day?("a") }.should raise_error(ArgumentError)
         | 
| 636 | 
            -
                    lambda { Barometer::WeatherService.day?(@measurement) }.should_not raise_error(ArgumentError)
         | 
| 637 | 
            -
                  end
         | 
| 638 | 
            -
                  
         | 
| 639 | 
            -
                  it "requires time as a Data::LocalTime object" do
         | 
| 640 | 
            -
                    #lambda { Barometer::WeatherService.day?(@measurement,"a") }.should raise_error(ArgumentError)
         | 
| 641 | 
            -
                    lambda { Barometer::WeatherService.day?(@measurement,@now) }.should_not raise_error(ArgumentError)
         | 
| 642 | 
            -
                  end
         | 
| 643 | 
            -
                  
         | 
| 644 | 
            -
                  describe "and is current" do
         | 
| 645 | 
            -
                    
         | 
| 646 | 
            -
                    before(:each) do
         | 
| 647 | 
            -
                      module Barometer; class Data::Measurement
         | 
| 648 | 
            -
                        def current?(a=nil); true; end
         | 
| 649 | 
            -
                      end; end
         | 
| 650 | 
            -
                    end
         | 
| 651 | 
            -
                  
         | 
| 652 | 
            -
                    it "returns nil" do
         | 
| 653 | 
            -
                      Barometer::WeatherService.day?(@measurement).should be_nil
         | 
| 654 | 
            -
                    end
         | 
| 655 | 
            -
                    
         | 
| 656 | 
            -
                    it "returns true if currently_day?" do
         | 
| 657 | 
            -
                      module Barometer; class WeatherService
         | 
| 658 | 
            -
                        def self.currently_day?(a=nil); true; end
         | 
| 659 | 
            -
                      end; end
         | 
| 660 | 
            -
                      Barometer::WeatherService.day?(@measurement).should be_true
         | 
| 661 | 
            -
                    end
         | 
| 662 | 
            -
             | 
| 663 | 
            -
                    it "returns false if !currently_day?" do
         | 
| 664 | 
            -
                      module Barometer; class WeatherService
         | 
| 665 | 
            -
                        def self.currently_day?(a=nil); false; end
         | 
| 666 | 
            -
                      end; end
         | 
| 667 | 
            -
                      Barometer::WeatherService.day?(@measurement).should be_false
         | 
| 668 | 
            -
                    end
         | 
| 669 | 
            -
                    
         | 
| 670 | 
            -
                  end
         | 
| 671 | 
            -
                  
         | 
| 672 | 
            -
                  describe "and is NOT current" do
         | 
| 673 | 
            -
                    
         | 
| 674 | 
            -
                    before(:each) do
         | 
| 675 | 
            -
                      module Barometer; class Data::Measurement
         | 
| 676 | 
            -
                        def current?(a=nil); false; end
         | 
| 677 | 
            -
                      end; end
         | 
| 678 | 
            -
                    end
         | 
| 679 | 
            -
                  
         | 
| 680 | 
            -
                    it "returns nil" do
         | 
| 681 | 
            -
                      Barometer::WeatherService.day?(@measurement).should be_nil
         | 
| 682 | 
            -
                    end
         | 
| 683 | 
            -
                    
         | 
| 684 | 
            -
                    it "returns true if forecasted_day?" do
         | 
| 685 | 
            -
                      module Barometer; class WeatherService
         | 
| 686 | 
            -
                        def self.forecasted_day?(a=nil,b=nil); true; end
         | 
| 687 | 
            -
                      end; end
         | 
| 688 | 
            -
                      Barometer::WeatherService.day?(@measurement).should be_true
         | 
| 689 | 
            -
                    end
         | 
| 690 | 
            -
             | 
| 691 | 
            -
                    it "returns false if !forecasted_day?" do
         | 
| 692 | 
            -
                      module Barometer; class WeatherService
         | 
| 693 | 
            -
                        def self.forecasted_day?(a=nil,b=nil); false; end
         | 
| 694 | 
            -
                      end; end
         | 
| 695 | 
            -
                      Barometer::WeatherService.day?(@measurement).should be_false
         | 
| 696 | 
            -
                    end
         | 
| 697 | 
            -
                    
         | 
| 698 | 
            -
                  end
         | 
| 699 | 
            -
                  
         | 
| 700 | 
            -
                end
         | 
| 701 | 
            -
                
         | 
| 702 | 
            -
                describe "currently_day?" do
         | 
| 703 | 
            -
             | 
| 704 | 
            -
                  before(:each) do
         | 
| 705 | 
            -
                    # the function being tested was monkey patched in an earlier test
         | 
| 706 | 
            -
                    # so the original file must be reloaded
         | 
| 707 | 
            -
                    load 'lib/barometer/weather_services/service.rb'
         | 
| 708 | 
            -
                    
         | 
| 709 | 
            -
                    @measurement = Data::Measurement.new
         | 
| 710 | 
            -
                  end
         | 
| 711 | 
            -
             | 
| 712 | 
            -
                  it "requires a measurement object" do
         | 
| 713 | 
            -
                    lambda { Barometer::WeatherService.currently_day? }.should raise_error(ArgumentError)
         | 
| 714 | 
            -
                    lambda { Barometer::WeatherService.currently_day?("a") }.should raise_error(ArgumentError)
         | 
| 715 | 
            -
                    lambda { Barometer::WeatherService.currently_day?(@measurement) }.should_not raise_error(ArgumentError)
         | 
| 716 | 
            -
                  end
         | 
| 717 | 
            -
                  
         | 
| 718 | 
            -
                  it "returns nil when value unavailable" do
         | 
| 719 | 
            -
                    measurement = Data::Measurement.new
         | 
| 720 | 
            -
                    Barometer::WeatherService.currently_day?(measurement).should be_nil
         | 
| 721 | 
            -
                  end
         | 
| 722 | 
            -
                  
         | 
| 723 | 
            -
                  describe "and currently_after_sunrise?" do
         | 
| 724 | 
            -
                    
         | 
| 725 | 
            -
                    before(:each) do
         | 
| 726 | 
            -
                      @measurement = Data::CurrentMeasurement.new
         | 
| 727 | 
            -
                      @now = Data::LocalTime.parse("2:02 pm")
         | 
| 728 | 
            -
                      @past = @now - (60*60)
         | 
| 729 | 
            -
                      @future = @now + (60*60)
         | 
| 730 | 
            -
                    end
         | 
| 731 | 
            -
                    
         | 
| 732 | 
            -
                    it "returns true when now is past sun_rise" do
         | 
| 733 | 
            -
                      @measurement.sun = Data::Sun.new(@past)
         | 
| 734 | 
            -
                      @measurement.current_at.should be_nil
         | 
| 735 | 
            -
                      Barometer::WeatherService.currently_after_sunrise?(@measurement).should be_nil
         | 
| 736 | 
            -
                      
         | 
| 737 | 
            -
                      @measurement.current_at = @now
         | 
| 738 | 
            -
                      @measurement.current_at.should_not be_nil
         | 
| 739 | 
            -
                      Barometer::WeatherService.currently_after_sunrise?(@measurement).should be_true
         | 
| 740 | 
            -
                    end
         | 
| 741 | 
            -
             | 
| 742 | 
            -
                    it "returns false when now if before sun_rise" do
         | 
| 743 | 
            -
                      @measurement.sun = Data::Sun.new(@future)
         | 
| 744 | 
            -
                      @measurement.current_at.should be_nil
         | 
| 745 | 
            -
                      Barometer::WeatherService.currently_after_sunrise?(@measurement).should be_nil
         | 
| 746 | 
            -
                      
         | 
| 747 | 
            -
                      @measurement.current_at = @now
         | 
| 748 | 
            -
                      @measurement.current_at.should_not be_nil
         | 
| 749 | 
            -
                      Barometer::WeatherService.currently_after_sunrise?(@measurement).should be_false
         | 
| 750 | 
            -
                    end
         | 
| 751 | 
            -
                    
         | 
| 752 | 
            -
                  end
         | 
| 753 | 
            -
                  
         | 
| 754 | 
            -
                  describe "and currently_before_sunset?" do
         | 
| 755 | 
            -
                    
         | 
| 756 | 
            -
                    before(:each) do
         | 
| 757 | 
            -
                      @measurement = Data::CurrentMeasurement.new
         | 
| 758 | 
            -
                      @now = Data::LocalTime.parse("2:02 pm")
         | 
| 759 | 
            -
                      @past = @now - (60*60)
         | 
| 760 | 
            -
                      @future = @now + (60*60)
         | 
| 761 | 
            -
                    end
         | 
| 762 | 
            -
                    
         | 
| 763 | 
            -
                    it "returns true when now is before sun_set" do
         | 
| 764 | 
            -
                      @measurement.sun = Data::Sun.new(nil,@future)
         | 
| 765 | 
            -
                      @measurement.current_at.should be_nil
         | 
| 766 | 
            -
                      Barometer::WeatherService.currently_before_sunset?(@measurement).should be_nil
         | 
| 767 | 
            -
                      
         | 
| 768 | 
            -
                      @measurement.current_at = @now
         | 
| 769 | 
            -
                      @measurement.current_at.should_not be_nil
         | 
| 770 | 
            -
                      Barometer::WeatherService.currently_before_sunset?(@measurement).should be_true
         | 
| 771 | 
            -
                    end
         | 
| 772 | 
            -
             | 
| 773 | 
            -
                    it "returns false when now if after sun_set" do
         | 
| 774 | 
            -
                      @measurement.sun = Data::Sun.new(nil,@past)
         | 
| 775 | 
            -
                      @measurement.current_at.should be_nil
         | 
| 776 | 
            -
                      Barometer::WeatherService.currently_before_sunset?(@measurement).should be_nil
         | 
| 777 | 
            -
                      
         | 
| 778 | 
            -
                      @measurement.current_at = @now
         | 
| 779 | 
            -
                      @measurement.current_at.should_not be_nil
         | 
| 780 | 
            -
                      Barometer::WeatherService.currently_before_sunset?(@measurement).should be_false
         | 
| 781 | 
            -
                    end
         | 
| 782 | 
            -
                    
         | 
| 783 | 
            -
                  end
         | 
| 784 | 
            -
                  
         | 
| 785 | 
            -
                end
         | 
| 786 | 
            -
                
         | 
| 787 | 
            -
                describe "forecasted_day?" do
         | 
| 788 | 
            -
             | 
| 789 | 
            -
                  before(:each) do
         | 
| 790 | 
            -
                    # the function being tested was monkey patched in an earlier test
         | 
| 791 | 
            -
                    # so the original file must be reloaded
         | 
| 792 | 
            -
                    load 'lib/barometer/weather_services/service.rb'
         | 
| 793 | 
            -
                    
         | 
| 794 | 
            -
                    @measurement = Data::Measurement.new
         | 
| 795 | 
            -
                  end
         | 
| 796 | 
            -
             | 
| 797 | 
            -
                  it "requires a measurement object" do
         | 
| 798 | 
            -
                    lambda { Barometer::WeatherService.forecasted_day? }.should raise_error(ArgumentError)
         | 
| 799 | 
            -
                    lambda { Barometer::WeatherService.forecasted_day?("a") }.should raise_error(ArgumentError)
         | 
| 800 | 
            -
                    lambda { Barometer::WeatherService.forecasted_day?(@measurement) }.should_not raise_error(ArgumentError)
         | 
| 801 | 
            -
                  end
         | 
| 802 | 
            -
                  
         | 
| 803 | 
            -
                  it "requires time as a Data::LocalTime object" do
         | 
| 804 | 
            -
                    #lambda { Barometer::WeatherService.forecasted_day?(@measurement,"a") }.should raise_error(ArgumentError)
         | 
| 805 | 
            -
                    lambda { Barometer::WeatherService.forecasted_day?(@measurement,@now) }.should_not raise_error(ArgumentError)
         | 
| 806 | 
            -
                  end
         | 
| 807 | 
            -
             | 
| 808 | 
            -
                  it "returns nil when value unavailable" do
         | 
| 809 | 
            -
                    measurement = Data::Measurement.new
         | 
| 810 | 
            -
                    Barometer::WeatherService.forecasted_day?(measurement).should be_nil
         | 
| 811 | 
            -
                  end
         | 
| 812 | 
            -
                  
         | 
| 813 | 
            -
                  describe "and forecasted_after_sunrise?" do
         | 
| 814 | 
            -
                    
         | 
| 815 | 
            -
                    before(:each) do
         | 
| 816 | 
            -
                      @measurement = Data::ForecastMeasurement.new
         | 
| 817 | 
            -
                      @now = Data::LocalDateTime.parse("2:02 pm")
         | 
| 818 | 
            -
                      @past = @now - (60*60)
         | 
| 819 | 
            -
                      @future = @now + (60*60)
         | 
| 820 | 
            -
                    end
         | 
| 821 | 
            -
                    
         | 
| 822 | 
            -
                    it "returns true when now is past sun_rise" do
         | 
| 823 | 
            -
                      @measurement.sun = Data::Sun.new(@past)
         | 
| 824 | 
            -
                      Barometer::WeatherService.forecasted_after_sunrise?(@measurement, @now).should be_true
         | 
| 825 | 
            -
                    end
         | 
| 826 | 
            -
                  
         | 
| 827 | 
            -
                    it "returns false when now if before sun_rise" do
         | 
| 828 | 
            -
                      @measurement.sun = Data::Sun.new(@future)
         | 
| 829 | 
            -
                      Barometer::WeatherService.forecasted_after_sunrise?(@measurement, @now).should be_false
         | 
| 830 | 
            -
                    end
         | 
| 831 | 
            -
                    
         | 
| 832 | 
            -
                  end
         | 
| 833 | 
            -
                  
         | 
| 834 | 
            -
                  describe "and forecasted_before_sunset?" do
         | 
| 835 | 
            -
                    
         | 
| 836 | 
            -
                    before(:each) do
         | 
| 837 | 
            -
                      @measurement = Data::ForecastMeasurement.new
         | 
| 838 | 
            -
                      @now = Data::LocalDateTime.parse("2:02 pm")
         | 
| 839 | 
            -
                      @past = @now - (60*60)
         | 
| 840 | 
            -
                      @future = @now + (60*60)
         | 
| 841 | 
            -
                    end
         | 
| 842 | 
            -
                    
         | 
| 843 | 
            -
                    it "returns true when now is before sun_set" do
         | 
| 844 | 
            -
                      @measurement.sun = Data::Sun.new(nil,@future)
         | 
| 845 | 
            -
                      Barometer::WeatherService.forecasted_before_sunset?(@measurement,@now).should be_true
         | 
| 846 | 
            -
                    end
         | 
| 847 | 
            -
                  
         | 
| 848 | 
            -
                    it "returns false when now if after sun_set" do
         | 
| 849 | 
            -
                      @measurement.sun = Data::Sun.new(nil,@past)
         | 
| 850 | 
            -
                      Barometer::WeatherService.forecasted_before_sunset?(@measurement,@now).should be_false
         | 
| 851 | 
            -
                    end
         | 
| 852 | 
            -
                    
         | 
| 853 | 
            -
                  end
         | 
| 854 | 
            -
                  
         | 
| 855 | 
            -
                end
         | 
| 856 | 
            -
                
         | 
| 857 | 
            -
                describe "sunny?" do
         | 
| 858 | 
            -
                  
         | 
| 859 | 
            -
                  it "requires a measurement object" do
         | 
| 860 | 
            -
                    lambda { Barometer::WeatherService.sunny? }.should raise_error(ArgumentError)
         | 
| 861 | 
            -
                    lambda { Barometer::WeatherService.sunny?("a") }.should raise_error(ArgumentError)
         | 
| 862 | 
            -
                    lambda { Barometer::WeatherService.sunny?(@measurement) }.should_not raise_error(ArgumentError)
         | 
| 863 | 
            -
                  end
         | 
| 864 | 
            -
                  
         | 
| 865 | 
            -
                  it "requires time as a Data::LocalTime object" do
         | 
| 866 | 
            -
                    #lambda { Barometer::WeatherService.sunny?(@measurement,"a") }.should raise_error(ArgumentError)
         | 
| 867 | 
            -
                    lambda { Barometer::WeatherService.sunny?(@measurement,@now) }.should_not raise_error(ArgumentError)
         | 
| 868 | 
            -
                  end
         | 
| 869 | 
            -
             | 
| 870 | 
            -
                  it "draws attention to this spot to fix this test"
         | 
| 871 | 
            -
                  # it "returns false if night time" do
         | 
| 872 | 
            -
                  #   @measurement.forecast = [Data::ForecastMeasurement.new]
         | 
| 873 | 
            -
                  #   @measurement.forecast.size.should == 1
         | 
| 874 | 
            -
                  #   @measurement.forecast[0].date = Date.today
         | 
| 875 | 
            -
                  #   module Barometer; class WeatherService; def self.day?(a=nil, b=nil)
         | 
| 876 | 
            -
                  #     true
         | 
| 877 | 
            -
                  #   end; end; end
         | 
| 878 | 
            -
                  #   Barometer::WeatherService.forecasted_sunny?(@measurement).should be_true
         | 
| 879 | 
            -
                  #   module Barometer; class WeatherService; def self.day?(a=nil, b=nil)
         | 
| 880 | 
            -
                  #     false
         | 
| 881 | 
            -
                  #   end; end; end
         | 
| 882 | 
            -
                  #   Barometer::WeatherService.forecasted_sunny?(@measurement).should be_false
         | 
| 883 | 
            -
                  # end
         | 
| 884 | 
            -
             | 
| 885 | 
            -
                  describe "and is current" do
         | 
| 886 | 
            -
                    
         | 
| 887 | 
            -
                    before(:each) do
         | 
| 888 | 
            -
                      module Barometer; class Data::Measurement
         | 
| 889 | 
            -
                        def current?(a=nil); true; end
         | 
| 890 | 
            -
                      end; end
         | 
| 891 | 
            -
                    end
         | 
| 892 | 
            -
                  
         | 
| 893 | 
            -
                    it "returns nil" do
         | 
| 894 | 
            -
                      Barometer::WeatherService.sunny?(@measurement).should be_nil
         | 
| 895 | 
            -
                    end
         | 
| 896 | 
            -
                    
         | 
| 897 | 
            -
                    it "returns true if currently_sunny?" do
         | 
| 898 | 
            -
                      module Barometer; class WeatherService
         | 
| 899 | 
            -
                        def self.currently_sunny?(a=nil); true; end
         | 
| 900 | 
            -
                      end; end
         | 
| 901 | 
            -
                      Barometer::WeatherService.sunny?(@measurement).should be_true
         | 
| 902 | 
            -
                    end
         | 
| 903 | 
            -
             | 
| 904 | 
            -
                    it "returns false if !currently_sunny?" do
         | 
| 905 | 
            -
                      module Barometer; class WeatherService
         | 
| 906 | 
            -
                        def self.currently_sunny?(a=nil); false; end
         | 
| 907 | 
            -
                      end; end
         | 
| 908 | 
            -
                      Barometer::WeatherService.sunny?(@measurement).should be_false
         | 
| 909 | 
            -
                    end
         | 
| 910 | 
            -
                    
         | 
| 911 | 
            -
                  end
         | 
| 912 | 
            -
                  
         | 
| 913 | 
            -
                  describe "and is NOT current" do
         | 
| 914 | 
            -
                    
         | 
| 915 | 
            -
                    before(:each) do
         | 
| 916 | 
            -
                      module Barometer; class Data::Measurement
         | 
| 917 | 
            -
                        def current?(a=nil); false; end
         | 
| 918 | 
            -
                      end; end
         | 
| 919 | 
            -
                    end
         | 
| 920 | 
            -
                  
         | 
| 921 | 
            -
                    it "returns nil" do
         | 
| 922 | 
            -
                      Barometer::WeatherService.sunny?(@measurement).should be_nil
         | 
| 923 | 
            -
                    end
         | 
| 924 | 
            -
                    
         | 
| 925 | 
            -
                    it "returns true if forecasted_sunny?" do
         | 
| 926 | 
            -
                      module Barometer; class WeatherService
         | 
| 927 | 
            -
                        def self.forecasted_sunny?(a=nil,b=nil); true; end
         | 
| 928 | 
            -
                      end; end
         | 
| 929 | 
            -
                      Barometer::WeatherService.sunny?(@measurement).should be_true
         | 
| 930 | 
            -
                    end
         | 
| 931 | 
            -
             | 
| 932 | 
            -
                    it "returns false if !forecasted_wet?" do
         | 
| 933 | 
            -
                      module Barometer; class WeatherService
         | 
| 934 | 
            -
                        def self.forecasted_sunny?(a=nil,b=nil); false; end
         | 
| 935 | 
            -
                      end; end
         | 
| 936 | 
            -
                      Barometer::WeatherService.sunny?(@measurement).should be_false
         | 
| 937 | 
            -
                    end
         | 
| 938 | 
            -
                    
         | 
| 939 | 
            -
                  end
         | 
| 940 | 
            -
                  
         | 
| 941 | 
            -
                end
         | 
| 942 | 
            -
                
         | 
| 943 | 
            -
                describe "currently_sunny?" do
         | 
| 944 | 
            -
                
         | 
| 945 | 
            -
                  before(:each) do
         | 
| 946 | 
            -
                    # the function being tested was monkey patched in an earlier test
         | 
| 947 | 
            -
                    # so the original file must be reloaded
         | 
| 948 | 
            -
                    load 'lib/barometer/weather_services/service.rb'
         | 
| 949 | 
            -
                    
         | 
| 950 | 
            -
                    @measurement = Data::Measurement.new
         | 
| 951 | 
            -
                  end
         | 
| 952 | 
            -
                
         | 
| 953 | 
            -
                  it "requires a measurement object" do
         | 
| 954 | 
            -
                    lambda { Barometer::WeatherService.currently_sunny? }.should raise_error(ArgumentError)
         | 
| 955 | 
            -
                    lambda { Barometer::WeatherService.currently_sunny?("a") }.should raise_error(ArgumentError)
         | 
| 956 | 
            -
                    lambda { Barometer::WeatherService.currently_sunny?(@measurement) }.should_not raise_error(ArgumentError)
         | 
| 957 | 
            -
                  end
         | 
| 958 | 
            -
                
         | 
| 959 | 
            -
                  it "returns nil when value unavailable" do
         | 
| 960 | 
            -
                    measurement = Data::Measurement.new
         | 
| 961 | 
            -
                    Barometer::WeatherService.currently_sunny?(measurement).should be_nil
         | 
| 962 | 
            -
                    measurement.current = Data::CurrentMeasurement.new
         | 
| 963 | 
            -
                    Barometer::WeatherService.currently_sunny?(measurement).should be_nil
         | 
| 964 | 
            -
                  end
         | 
| 965 | 
            -
                  
         | 
| 966 | 
            -
                  it "returns false if night time" do
         | 
| 967 | 
            -
                    @measurement.current = Data::CurrentMeasurement.new
         | 
| 968 | 
            -
                    module Barometer; class WeatherService; def self.currently_day?(a=nil)
         | 
| 969 | 
            -
                      true
         | 
| 970 | 
            -
                    end; end; end
         | 
| 971 | 
            -
                    module Barometer; class WeatherService; def self.currently_sunny_by_icon?(a=nil)
         | 
| 972 | 
            -
                      true
         | 
| 973 | 
            -
                    end; end; end
         | 
| 974 | 
            -
                    Barometer::WeatherService.currently_sunny?(@measurement).should be_true
         | 
| 975 | 
            -
                    module Barometer; class WeatherService; def self.currently_day?(a=nil)
         | 
| 976 | 
            -
                      false
         | 
| 977 | 
            -
                    end; end; end
         | 
| 978 | 
            -
                    Barometer::WeatherService.currently_sunny?(@measurement).should be_false
         | 
| 979 | 
            -
                  end
         | 
| 980 | 
            -
             | 
| 981 | 
            -
                  describe "currently_sunny_by_icon?" do
         | 
| 982 | 
            -
             | 
| 983 | 
            -
                    before(:each) do
         | 
| 984 | 
            -
                      @measurement.current = Data::CurrentMeasurement.new
         | 
| 985 | 
            -
                    end
         | 
| 986 | 
            -
             | 
| 987 | 
            -
                    it "requires a Barometer::Measurement object" do
         | 
| 988 | 
            -
                      lambda { Barometer::WeatherService.currently_sunny_by_icon?(nil) }.should raise_error(ArgumentError)
         | 
| 989 | 
            -
                      lambda { Barometer::WeatherService.currently_sunny_by_icon?("invlaid") }.should raise_error(ArgumentError)
         | 
| 990 | 
            -
             | 
| 991 | 
            -
                      lambda { Barometer::WeatherService.currently_sunny_by_icon?(@measurement.current) }.should_not raise_error(ArgumentError)
         | 
| 992 | 
            -
                    end
         | 
| 993 | 
            -
             | 
| 994 | 
            -
                    it "returns nil if no icon" do
         | 
| 995 | 
            -
                      @measurement.current.icon?.should be_false
         | 
| 996 | 
            -
                      Barometer::WeatherService.currently_sunny_by_icon?(@measurement.current).should be_nil
         | 
| 997 | 
            -
                    end
         | 
| 998 | 
            -
             | 
| 999 | 
            -
                    it "returns true if matching icon code" do
         | 
| 1000 | 
            -
                      module Barometer; class WeatherService; def self.sunny_icon_codes
         | 
| 1001 | 
            -
                        ["sunny"]
         | 
| 1002 | 
            -
                      end; end; end
         | 
| 1003 | 
            -
                      @measurement.current.icon = "sunny"
         | 
| 1004 | 
            -
                      @measurement.current.icon?.should be_true
         | 
| 1005 | 
            -
                      Barometer::WeatherService.currently_sunny_by_icon?(@measurement.current).should be_true
         | 
| 1006 | 
            -
                    end
         | 
| 1007 | 
            -
             | 
| 1008 | 
            -
                    it "returns false if NO matching icon code" do
         | 
| 1009 | 
            -
                      module Barometer; class WeatherService; def self.sunny_icon_codes
         | 
| 1010 | 
            -
                        ["sunny"]
         | 
| 1011 | 
            -
                      end; end; end
         | 
| 1012 | 
            -
                      @measurement.current.icon = "rain"
         | 
| 1013 | 
            -
                      @measurement.current.icon?.should be_true
         | 
| 1014 | 
            -
                      Barometer::WeatherService.currently_sunny_by_icon?(@measurement.current).should be_false
         | 
| 1015 | 
            -
                    end
         | 
| 1016 | 
            -
             | 
| 1017 | 
            -
                  end
         | 
| 1018 | 
            -
                  
         | 
| 1019 | 
            -
                end
         | 
| 1020 | 
            -
                
         | 
| 1021 | 
            -
                describe "forecasted_sunny?" do
         | 
| 1022 | 
            -
                
         | 
| 1023 | 
            -
                  before(:each) do
         | 
| 1024 | 
            -
                    # the function being tested was monkey patched in an earlier test
         | 
| 1025 | 
            -
                    # so the original file must be reloaded
         | 
| 1026 | 
            -
                    load 'lib/barometer/weather_services/service.rb'
         | 
| 1027 | 
            -
                    
         | 
| 1028 | 
            -
                    @measurement = Data::Measurement.new
         | 
| 1029 | 
            -
                  end
         | 
| 1030 | 
            -
                
         | 
| 1031 | 
            -
                  it "requires a measurement object" do
         | 
| 1032 | 
            -
                    lambda { Barometer::WeatherService.forecasted_sunny? }.should raise_error(ArgumentError)
         | 
| 1033 | 
            -
                    lambda { Barometer::WeatherService.forecasted_sunny?("a") }.should raise_error(ArgumentError)
         | 
| 1034 | 
            -
                    lambda { Barometer::WeatherService.forecasted_sunny?(@measurement) }.should_not raise_error(ArgumentError)
         | 
| 1035 | 
            -
                  end
         | 
| 1036 | 
            -
             | 
| 1037 | 
            -
                  it "requires utc_time as a Data::LocalTime object" do
         | 
| 1038 | 
            -
                    #lambda { Barometer::WeatherService.forecasted_sunny?(@measurement,"string") }.should raise_error(ArgumentError)
         | 
| 1039 | 
            -
                    lambda { Barometer::WeatherService.forecasted_sunny?(@measurement,@now) }.should_not raise_error(ArgumentError)
         | 
| 1040 | 
            -
                  end
         | 
| 1041 | 
            -
             | 
| 1042 | 
            -
                  it "returns nil when value unavailable" do
         | 
| 1043 | 
            -
                    measurement = Data::Measurement.new
         | 
| 1044 | 
            -
                    Barometer::WeatherService.forecasted_sunny?(measurement).should be_nil
         | 
| 1045 | 
            -
                    measurement.forecast = [Data::ForecastMeasurement.new]
         | 
| 1046 | 
            -
                    measurement.forecast.size.should == 1
         | 
| 1047 | 
            -
                    Barometer::WeatherService.forecasted_sunny?(measurement).should be_nil
         | 
| 1048 | 
            -
                  end
         | 
| 1049 | 
            -
             | 
| 1050 | 
            -
                  it "returns false if night time" do
         | 
| 1051 | 
            -
                    @measurement.forecast = [Data::ForecastMeasurement.new]
         | 
| 1052 | 
            -
                    @measurement.forecast.size.should == 1
         | 
| 1053 | 
            -
                    target_date = Date.today
         | 
| 1054 | 
            -
                    @measurement.forecast[0].date = target_date
         | 
| 1055 | 
            -
                    module Barometer; class WeatherService; def self.forecasted_day?(a=nil, b=nil)
         | 
| 1056 | 
            -
                      true
         | 
| 1057 | 
            -
                    end; end; end
         | 
| 1058 | 
            -
                    module Barometer; class WeatherService; def self.forecasted_sunny_by_icon?(a=nil, b=nil)
         | 
| 1059 | 
            -
                      true
         | 
| 1060 | 
            -
                    end; end; end
         | 
| 1061 | 
            -
                    Barometer::WeatherService.forecasted_sunny?(@measurement, target_date).should be_true
         | 
| 1062 | 
            -
                    module Barometer; class WeatherService; def self.forecasted_day?(a=nil, b=nil)
         | 
| 1063 | 
            -
                      false
         | 
| 1064 | 
            -
                    end; end; end
         | 
| 1065 | 
            -
                    Barometer::WeatherService.forecasted_sunny?(@measurement).should be_false
         | 
| 1066 | 
            -
                  end
         | 
| 1067 | 
            -
                  
         | 
| 1068 | 
            -
                  describe "forecasted_sunny_by_icon?" do
         | 
| 1069 | 
            -
             | 
| 1070 | 
            -
                    before(:each) do
         | 
| 1071 | 
            -
                      @measurement.forecast = [Data::ForecastMeasurement.new]
         | 
| 1072 | 
            -
                      @measurement.forecast.first.date = Date.today
         | 
| 1073 | 
            -
                      @measurement.forecast.size.should == 1
         | 
| 1074 | 
            -
                    end
         | 
| 1075 | 
            -
             | 
| 1076 | 
            -
                    it "requires a Barometer::Measurement object" do
         | 
| 1077 | 
            -
                      lambda { Barometer::WeatherService.forecasted_sunny_by_icon?(nil) }.should raise_error(ArgumentError)
         | 
| 1078 | 
            -
                      lambda { Barometer::WeatherService.forecasted_sunny_by_icon?("invlaid") }.should raise_error(ArgumentError)
         | 
| 1079 | 
            -
             | 
| 1080 | 
            -
                      lambda { Barometer::WeatherService.forecasted_sunny_by_icon?(@measurement.forecast.first) }.should_not raise_error(ArgumentError)
         | 
| 1081 | 
            -
                    end
         | 
| 1082 | 
            -
             | 
| 1083 | 
            -
                    it "returns nil if no icon" do
         | 
| 1084 | 
            -
                      @measurement.forecast.first.icon?.should be_false
         | 
| 1085 | 
            -
                      Barometer::WeatherService.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_nil
         | 
| 1086 | 
            -
                    end
         | 
| 1087 | 
            -
             | 
| 1088 | 
            -
                    it "returns true if matching icon code" do
         | 
| 1089 | 
            -
                      module Barometer; class WeatherService; def self.sunny_icon_codes
         | 
| 1090 | 
            -
                        ["sunny"]
         | 
| 1091 | 
            -
                      end; end; end
         | 
| 1092 | 
            -
                      @measurement.forecast.first.icon = "sunny"
         | 
| 1093 | 
            -
                      @measurement.forecast.first.icon?.should be_true
         | 
| 1094 | 
            -
                      Barometer::WeatherService.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_true
         | 
| 1095 | 
            -
                    end
         | 
| 1096 | 
            -
             | 
| 1097 | 
            -
                    it "returns false if NO matching icon code" do
         | 
| 1098 | 
            -
                      module Barometer; class WeatherService; def self.sunny_icon_codes
         | 
| 1099 | 
            -
                        ["sunny"]
         | 
| 1100 | 
            -
                      end; end; end
         | 
| 1101 | 
            -
                      @measurement.forecast.first.icon = "rain"
         | 
| 1102 | 
            -
                      @measurement.forecast.first.icon?.should be_true
         | 
| 1103 | 
            -
                      Barometer::WeatherService.forecasted_sunny_by_icon?(@measurement.forecast.first).should be_false
         | 
| 1104 | 
            -
                    end
         | 
| 1105 | 
            -
             | 
| 1106 | 
            -
                    after(:each) do
         | 
| 1107 | 
            -
                      # the function being tested was monkey patched in an earlier test
         | 
| 1108 | 
            -
                      # so the original file must be reloaded
         | 
| 1109 | 
            -
                      load 'lib/barometer/weather_services/service.rb'
         | 
| 1110 | 
            -
                    end
         | 
| 1111 | 
            -
             | 
| 1112 | 
            -
                  end
         | 
| 1113 | 
            -
             | 
| 1114 | 
            -
                end
         | 
| 1115 | 
            -
                
         | 
| 1116 | 
            -
              end
         | 
| 1117 | 
            -
              
         | 
| 1118 143 | 
             
            end
         |