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