attack-barometer 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +51 -9
- data/VERSION.yml +1 -1
- data/bin/barometer +57 -7
- data/lib/barometer/base.rb +3 -0
- data/lib/barometer/data/sun.rb +10 -0
- data/lib/barometer/data/zone.rb +79 -188
- data/lib/barometer/data.rb +11 -6
- 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/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/barometer.rb +11 -0
- data/lib/demometer/demometer.rb +28 -0
- data/lib/demometer/public/css/master.css +259 -1
- 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 +23 -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,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Forecast Measurement" do
|
4
|
+
|
5
|
+
describe "when initialized" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@forecast = Measurement::Forecast.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "responds to date" do
|
12
|
+
@forecast.date.should be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "responds to low" do
|
16
|
+
@forecast.low.should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "responds to high" do
|
20
|
+
@forecast.high.should be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "responds to pop" do
|
24
|
+
@forecast.pop.should be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "responds to night" do
|
28
|
+
@forecast.night.should be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "when writing data" do
|
34
|
+
|
35
|
+
before(:each) do
|
36
|
+
@forecast = Measurement::Forecast.new
|
37
|
+
end
|
38
|
+
|
39
|
+
it "only accepts Date for date" do
|
40
|
+
invalid_data = 1
|
41
|
+
invalid_data.class.should_not == Date
|
42
|
+
lambda { @forecast.date = invalid_data }.should raise_error(ArgumentError)
|
43
|
+
|
44
|
+
valid_data = Date.new
|
45
|
+
valid_data.class.should == Date
|
46
|
+
lambda { @forecast.date = valid_data }.should_not raise_error(ArgumentError)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "only accepts Data::Temperature for high" do
|
50
|
+
invalid_data = 1
|
51
|
+
invalid_data.class.should_not == Data::Temperature
|
52
|
+
lambda { @forecast.high = invalid_data }.should raise_error(ArgumentError)
|
53
|
+
|
54
|
+
valid_data = Data::Temperature.new
|
55
|
+
valid_data.class.should == Data::Temperature
|
56
|
+
lambda { @forecast.high = valid_data }.should_not raise_error(ArgumentError)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "only accepts Data::Temperature for low" do
|
60
|
+
invalid_data = 1
|
61
|
+
invalid_data.class.should_not == Data::Temperature
|
62
|
+
lambda { @forecast.low = invalid_data }.should raise_error(ArgumentError)
|
63
|
+
|
64
|
+
valid_data = Data::Temperature.new
|
65
|
+
valid_data.class.should == Data::Temperature
|
66
|
+
lambda { @forecast.low = valid_data }.should_not raise_error(ArgumentError)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "only accepts Fixnum for pop" do
|
70
|
+
invalid_data = "test"
|
71
|
+
invalid_data.class.should_not == Fixnum
|
72
|
+
lambda { @forecast.pop = invalid_data }.should raise_error(ArgumentError)
|
73
|
+
|
74
|
+
valid_data = 50
|
75
|
+
valid_data.class.should == Fixnum
|
76
|
+
lambda { @forecast.pop = valid_data }.should_not raise_error(ArgumentError)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "only accepts Measurement::ForecastNight for night" do
|
80
|
+
invalid_data = 1
|
81
|
+
invalid_data.class.should_not == Measurement::ForecastNight
|
82
|
+
lambda { @forecast.night = invalid_data }.should raise_error(ArgumentError)
|
83
|
+
|
84
|
+
valid_data = Measurement::ForecastNight.new
|
85
|
+
valid_data.class.should == Measurement::ForecastNight
|
86
|
+
lambda { @forecast.night = valid_data }.should_not raise_error(ArgumentError)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "answer simple questions, like" do
|
92
|
+
|
93
|
+
before(:each) do
|
94
|
+
@forecast = Measurement::Forecast.new
|
95
|
+
end
|
96
|
+
|
97
|
+
describe "wet?" do
|
98
|
+
|
99
|
+
describe "wet_by_pop?" do
|
100
|
+
|
101
|
+
it "requires real threshold number (or nil)" do
|
102
|
+
lambda { @forecast.send("_wet_by_pop?","invalid") }.should raise_error(ArgumentError)
|
103
|
+
lambda { @forecast.send("_wet_by_pop?") }.should_not raise_error(ArgumentError)
|
104
|
+
lambda { @forecast.send("_wet_by_pop?",50) }.should_not raise_error(ArgumentError)
|
105
|
+
end
|
106
|
+
|
107
|
+
it "returns nil when no pop" do
|
108
|
+
@forecast.pop?.should be_false
|
109
|
+
@forecast.send("_wet_by_pop?",50).should be_nil
|
110
|
+
@forecast.wet?.should be_nil
|
111
|
+
@forecast.pop = 60
|
112
|
+
@forecast.pop?.should be_true
|
113
|
+
@forecast.send("_wet_by_pop?",50).should_not be_nil
|
114
|
+
@forecast.wet?.should_not be_nil
|
115
|
+
end
|
116
|
+
|
117
|
+
it "return true when current pop over threshold" do
|
118
|
+
@forecast.pop = 60
|
119
|
+
@forecast.send("_wet_by_pop?",50).should be_true
|
120
|
+
@forecast.wet?.should be_true
|
121
|
+
end
|
122
|
+
|
123
|
+
it "return false when current pop under threshold" do
|
124
|
+
@forecast.pop = 40
|
125
|
+
@forecast.send("_wet_by_pop?",50).should be_false
|
126
|
+
@forecast.wet?.should be_false
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
end
|
@@ -5,7 +5,7 @@ describe "Measurement" do
|
|
5
5
|
describe "when initialized" do
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
@measurement =
|
8
|
+
@measurement = Barometer::Measurement.new
|
9
9
|
end
|
10
10
|
|
11
11
|
it "responds to source" do
|
@@ -14,7 +14,7 @@ describe "Measurement" do
|
|
14
14
|
|
15
15
|
it "stores the source" do
|
16
16
|
source = :wunderground
|
17
|
-
measurement =
|
17
|
+
measurement = Barometer::Measurement.new(source)
|
18
18
|
measurement.source.should_not be_nil
|
19
19
|
measurement.source.should == source
|
20
20
|
end
|
@@ -48,7 +48,7 @@ describe "Measurement" do
|
|
48
48
|
end
|
49
49
|
|
50
50
|
it "responds to current?" do
|
51
|
-
@measurement.current?.should
|
51
|
+
@measurement.current?.should be_true
|
52
52
|
end
|
53
53
|
|
54
54
|
it "responds to metric" do
|
@@ -76,7 +76,7 @@ describe "Measurement" do
|
|
76
76
|
describe "when writing data" do
|
77
77
|
|
78
78
|
before(:each) do
|
79
|
-
@measurement =
|
79
|
+
@measurement = Barometer::Measurement.new
|
80
80
|
end
|
81
81
|
|
82
82
|
it "only accepts Symbol for source" do
|
@@ -101,21 +101,21 @@ describe "Measurement" do
|
|
101
101
|
|
102
102
|
it "only accepts Data::CurrentMeasurement for current" do
|
103
103
|
invalid_data = "invalid"
|
104
|
-
invalid_data.class.should_not ==
|
104
|
+
invalid_data.class.should_not == Measurement::Current
|
105
105
|
lambda { @measurement.current = invalid_data }.should raise_error(ArgumentError)
|
106
106
|
|
107
|
-
valid_data =
|
108
|
-
valid_data.class.should ==
|
107
|
+
valid_data = Measurement::Current.new
|
108
|
+
valid_data.class.should == Measurement::Current
|
109
109
|
lambda { @measurement.current = valid_data }.should_not raise_error(ArgumentError)
|
110
110
|
end
|
111
111
|
|
112
|
-
it "only accepts
|
112
|
+
it "only accepts Data::ForecastArray for forecast" do
|
113
113
|
invalid_data = 1
|
114
|
-
invalid_data.class.should_not ==
|
114
|
+
invalid_data.class.should_not == Measurement::ForecastArray
|
115
115
|
lambda { @measurement.forecast = invalid_data }.should raise_error(ArgumentError)
|
116
116
|
|
117
|
-
valid_data =
|
118
|
-
valid_data.class.should ==
|
117
|
+
valid_data = Measurement::ForecastArray.new
|
118
|
+
valid_data.class.should == Measurement::ForecastArray
|
119
119
|
lambda { @measurement.forecast = valid_data }.should_not raise_error(ArgumentError)
|
120
120
|
end
|
121
121
|
|
@@ -184,7 +184,7 @@ describe "Measurement" do
|
|
184
184
|
describe "and the helpers" do
|
185
185
|
|
186
186
|
before(:each) do
|
187
|
-
@measurement =
|
187
|
+
@measurement = Barometer::Measurement.new
|
188
188
|
end
|
189
189
|
|
190
190
|
it "changes state to successful (if successful)" do
|
@@ -194,7 +194,7 @@ describe "Measurement" do
|
|
194
194
|
@measurement.current.should be_nil
|
195
195
|
@measurement.success.should be_false
|
196
196
|
|
197
|
-
@measurement.current =
|
197
|
+
@measurement.current = Measurement::Current.new
|
198
198
|
@measurement.current.temperature = Data::Temperature.new
|
199
199
|
@measurement.current.temperature.c = 10
|
200
200
|
@measurement.utc_time_stamp.should_not be_nil
|
@@ -203,7 +203,7 @@ describe "Measurement" do
|
|
203
203
|
end
|
204
204
|
|
205
205
|
it "returns successful state" do
|
206
|
-
@measurement.current =
|
206
|
+
@measurement.current = Measurement::Current.new
|
207
207
|
@measurement.current.temperature = Data::Temperature.new
|
208
208
|
@measurement.current.temperature.c = 10
|
209
209
|
@measurement.success!
|
@@ -224,11 +224,11 @@ describe "Measurement" do
|
|
224
224
|
|
225
225
|
it "indicates if current" do
|
226
226
|
@measurement.current.should be_nil
|
227
|
-
@measurement.current?.should
|
227
|
+
@measurement.current?.should be_true
|
228
228
|
|
229
|
-
@measurement.current =
|
229
|
+
@measurement.current = Measurement::Current.new
|
230
230
|
@measurement.current.current_at.should be_nil
|
231
|
-
@measurement.current?.should
|
231
|
+
@measurement.current?.should be_true
|
232
232
|
|
233
233
|
@measurement.current.current_at = Data::LocalTime.new(9,0,0)
|
234
234
|
@measurement.current?.should be_true
|
@@ -255,7 +255,7 @@ describe "Measurement" do
|
|
255
255
|
describe "changing units" do
|
256
256
|
|
257
257
|
before(:each) do
|
258
|
-
@measurement =
|
258
|
+
@measurement = Barometer::Measurement.new
|
259
259
|
end
|
260
260
|
|
261
261
|
it "indicates if metric?" do
|
@@ -286,13 +286,13 @@ describe "Measurement" do
|
|
286
286
|
describe "when searching forecasts using 'for'" do
|
287
287
|
|
288
288
|
before(:each) do
|
289
|
-
@measurement =
|
289
|
+
@measurement = Barometer::Measurement.new
|
290
290
|
|
291
291
|
# create a measurement object with a forecast array that includes
|
292
292
|
# dates for 4 consecutive days starting with tommorrow
|
293
|
-
@measurement.forecast =
|
293
|
+
@measurement.forecast = Measurement::ForecastArray.new
|
294
294
|
1.upto(4) do |i|
|
295
|
-
forecast_measurement =
|
295
|
+
forecast_measurement = Measurement::Forecast.new
|
296
296
|
forecast_measurement.date = Date.parse((Time.now + (i * 60 * 60 * 24)).to_s)
|
297
297
|
@measurement.forecast << forecast_measurement
|
298
298
|
end
|
@@ -302,7 +302,7 @@ describe "Measurement" do
|
|
302
302
|
end
|
303
303
|
|
304
304
|
it "returns nil when there are no forecasts" do
|
305
|
-
@measurement.forecast =
|
305
|
+
@measurement.forecast = Measurement::ForecastArray.new
|
306
306
|
@measurement.forecast.size.should == 0
|
307
307
|
@measurement.for.should be_nil
|
308
308
|
end
|
@@ -347,85 +347,70 @@ describe "Measurement" do
|
|
347
347
|
describe "when answering the simple questions," do
|
348
348
|
|
349
349
|
before(:each) do
|
350
|
-
@measurement =
|
350
|
+
@measurement = Barometer::Measurement.new(:wunderground)
|
351
|
+
@measurement.current = Measurement::Current.new
|
351
352
|
@now = Data::LocalDateTime.parse("2009-05-01 2:05 pm")
|
352
353
|
end
|
353
354
|
|
355
|
+
# def windy?(time_string=nil, threshold=10)
|
356
|
+
# local_time = Data::LocalTime.parse(time_string)
|
357
|
+
# if current?(local_time)
|
358
|
+
# return nil unless current
|
359
|
+
# current.windy?(threshold)
|
360
|
+
# else
|
361
|
+
# return nil unless forecast && (future = forecast[local_time])
|
362
|
+
# future.windy?(threshold)
|
363
|
+
# end
|
364
|
+
# end
|
365
|
+
|
354
366
|
describe "windy?" do
|
355
367
|
|
356
|
-
it "
|
357
|
-
|
358
|
-
|
359
|
-
lambda { @measurement.windy?(1.1) }.should_not raise_error(ArgumentError)
|
360
|
-
end
|
361
|
-
|
362
|
-
it "requires time as a Time object" do
|
363
|
-
#lambda { @measurement.windy?(1,false) }.should raise_error(ArgumentError)
|
364
|
-
lambda { @measurement.windy?(1,@now) }.should_not raise_error(ArgumentError)
|
365
|
-
end
|
366
|
-
|
367
|
-
it "returns true if a source returns true" do
|
368
|
-
module Barometer; class WeatherService
|
369
|
-
def self.windy?(a=nil,b=nil,c=nil); true; end
|
368
|
+
it "returns true if a current_measurement returns true" do
|
369
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
370
|
+
def windy?(a=nil); true; end
|
370
371
|
end; end
|
371
372
|
@measurement.windy?.should be_true
|
372
373
|
end
|
373
374
|
|
374
|
-
it "returns false if a
|
375
|
-
module Barometer; class
|
376
|
-
def
|
375
|
+
it "returns false if a current_measurement returns false" do
|
376
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
377
|
+
def windy?(a=nil); false; end
|
377
378
|
end; end
|
378
379
|
@measurement.windy?.should be_false
|
379
380
|
end
|
380
381
|
|
381
382
|
end
|
382
383
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
end
|
402
|
-
|
403
|
-
it "returns false if a measurement returns false" do
|
404
|
-
module Barometer; class WeatherService
|
405
|
-
def self.wet?(a=nil,b=nil,c=nil); false; end
|
406
|
-
end; end
|
407
|
-
@measurement.wet?.should be_false
|
408
|
-
end
|
409
|
-
|
410
|
-
end
|
411
|
-
|
384
|
+
describe "wet?" do
|
385
|
+
|
386
|
+
it "returns true if the current_measurement returns true" do
|
387
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
388
|
+
def wet?(a=nil,b=nil,c=nil); true; end
|
389
|
+
end; end
|
390
|
+
@measurement.wet?.should be_true
|
391
|
+
end
|
392
|
+
|
393
|
+
it "returns false if the current_measurement returns false" do
|
394
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
395
|
+
def wet?(a=nil,b=nil,c=nil); false; end
|
396
|
+
end; end
|
397
|
+
@measurement.wet?.should be_false
|
398
|
+
end
|
399
|
+
|
400
|
+
end
|
401
|
+
|
412
402
|
describe "day?" do
|
413
|
-
|
414
|
-
it "
|
415
|
-
|
416
|
-
|
417
|
-
end
|
418
|
-
|
419
|
-
it "returns true if a source returns true" do
|
420
|
-
module Barometer; class WeatherService
|
421
|
-
def self.day?(a=nil,b=nil); true; end
|
403
|
+
|
404
|
+
it "returns true if the current_measurement returns true" do
|
405
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
406
|
+
def day?(a=nil); true; end
|
422
407
|
end; end
|
423
408
|
@measurement.day?.should be_true
|
424
409
|
end
|
425
|
-
|
426
|
-
it "returns false if
|
427
|
-
module Barometer; class
|
428
|
-
def
|
410
|
+
|
411
|
+
it "returns false if the current_measurement returns false" do
|
412
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
413
|
+
def day?(a=nil); false; end
|
429
414
|
end; end
|
430
415
|
@measurement.day?.should be_false
|
431
416
|
end
|
@@ -434,45 +419,39 @@ describe "Measurement" do
|
|
434
419
|
|
435
420
|
describe "sunny?" do
|
436
421
|
|
437
|
-
it "
|
438
|
-
|
439
|
-
|
440
|
-
end
|
441
|
-
|
442
|
-
it "returns true if a source returns true" do
|
443
|
-
module Barometer; class WeatherService
|
444
|
-
def self.day?(a=nil,b=nil); true; end
|
422
|
+
it "returns true if the current_measurement returns true and day" do
|
423
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
424
|
+
def day?(a=nil); true; end
|
445
425
|
end; end
|
446
|
-
module Barometer; class
|
447
|
-
def
|
426
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
427
|
+
def sunny?(a=nil,b=nil); true; end
|
448
428
|
end; end
|
429
|
+
@measurement.day?.should be_true
|
449
430
|
@measurement.sunny?.should be_true
|
450
431
|
end
|
451
|
-
|
452
|
-
it "returns false if
|
453
|
-
module Barometer; class
|
454
|
-
def
|
432
|
+
|
433
|
+
it "returns false if the current_measurement returns false and day" do
|
434
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
435
|
+
def day?(a=nil); true; end
|
455
436
|
end; end
|
456
|
-
module Barometer; class
|
457
|
-
def
|
437
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
438
|
+
def sunny?(a=nil,b=nil); false; end
|
458
439
|
end; end
|
440
|
+
@measurement.day?.should be_true
|
459
441
|
@measurement.sunny?.should be_false
|
460
442
|
end
|
461
443
|
|
462
444
|
it "returns false if night time" do
|
463
|
-
module Barometer; class
|
464
|
-
def
|
445
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
446
|
+
def day?(a=nil); false; end
|
465
447
|
end; end
|
466
|
-
module Barometer; class
|
467
|
-
def
|
468
|
-
end; end
|
469
|
-
@measurement.sunny?.should be_true
|
470
|
-
module Barometer; class WeatherService
|
471
|
-
def self.day?(a=nil,b=nil); false; end
|
448
|
+
module Barometer; class Measurement::Current < Measurement::Common
|
449
|
+
def sunny?(a=nil,b=nil); true; end
|
472
450
|
end; end
|
451
|
+
@measurement.day?.should be_false
|
473
452
|
@measurement.sunny?.should be_false
|
474
453
|
end
|
475
|
-
|
454
|
+
|
476
455
|
end
|
477
456
|
|
478
457
|
end
|
@@ -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
|
|