barometer 0.3.2 → 0.5.0
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 +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
@@ -5,7 +5,7 @@ describe "Location" do
|
|
5
5
|
describe "when initialized" do
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
@location =
|
8
|
+
@location = Data::Location.new
|
9
9
|
end
|
10
10
|
|
11
11
|
it "responds to id" do
|
@@ -54,6 +54,17 @@ describe "Location" do
|
|
54
54
|
@location.coordinates.should == [@location.latitude, @location.longitude].join(',')
|
55
55
|
end
|
56
56
|
|
57
|
+
it "should print a string" do
|
58
|
+
@location = Data::Location.new
|
59
|
+
@location.to_s.should == ""
|
60
|
+
@location.name = "name"
|
61
|
+
@location.to_s.should == "name"
|
62
|
+
@location.city = "city"
|
63
|
+
@location.to_s.should == "name, city"
|
64
|
+
@location.country_code = "code"
|
65
|
+
@location.to_s.should == "name, city, code"
|
66
|
+
end
|
67
|
+
|
57
68
|
end
|
58
69
|
|
59
70
|
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 = Data::Measurement.new
|
9
9
|
end
|
10
10
|
|
11
11
|
it "responds to source" do
|
@@ -14,13 +14,13 @@ describe "Measurement" do
|
|
14
14
|
|
15
15
|
it "stores the source" do
|
16
16
|
source = :wunderground
|
17
|
-
measurement =
|
17
|
+
measurement = Data::Measurement.new(source)
|
18
18
|
measurement.source.should_not be_nil
|
19
19
|
measurement.source.should == source
|
20
20
|
end
|
21
21
|
|
22
|
-
it "responds to
|
23
|
-
@measurement.
|
22
|
+
it "responds to utc_time_stamp" do
|
23
|
+
@measurement.utc_time_stamp.should be_nil
|
24
24
|
end
|
25
25
|
|
26
26
|
it "responds to current" do
|
@@ -55,12 +55,28 @@ describe "Measurement" do
|
|
55
55
|
@measurement.metric.should be_true
|
56
56
|
end
|
57
57
|
|
58
|
+
it "responds to weight" do
|
59
|
+
@measurement.weight.should == 1
|
60
|
+
end
|
61
|
+
|
62
|
+
it "responds to links" do
|
63
|
+
@measurement.links.should == {}
|
64
|
+
end
|
65
|
+
|
66
|
+
it "responds to measured_at" do
|
67
|
+
@measurement.measured_at.should be_nil
|
68
|
+
end
|
69
|
+
|
70
|
+
# it "responds to measured_for" do
|
71
|
+
# @measurement.links.should == {}
|
72
|
+
# end
|
73
|
+
|
58
74
|
end
|
59
75
|
|
60
76
|
describe "when writing data" do
|
61
77
|
|
62
78
|
before(:each) do
|
63
|
-
@measurement =
|
79
|
+
@measurement = Data::Measurement.new
|
64
80
|
end
|
65
81
|
|
66
82
|
it "only accepts Symbol for source" do
|
@@ -73,23 +89,23 @@ describe "Measurement" do
|
|
73
89
|
lambda { @measurement.source = valid_data }.should_not raise_error(ArgumentError)
|
74
90
|
end
|
75
91
|
|
76
|
-
it "only accepts Time for
|
92
|
+
it "only accepts Time for utc_time_stamp" do
|
77
93
|
invalid_data = 1
|
78
94
|
invalid_data.class.should_not == Time
|
79
|
-
lambda { @measurement.
|
95
|
+
lambda { @measurement.utc_time_stamp = invalid_data }.should raise_error(ArgumentError)
|
80
96
|
|
81
97
|
valid_data = Time.now.utc
|
82
98
|
valid_data.class.should == Time
|
83
|
-
lambda { @measurement.
|
99
|
+
lambda { @measurement.utc_time_stamp = valid_data }.should_not raise_error(ArgumentError)
|
84
100
|
end
|
85
101
|
|
86
|
-
it "only accepts
|
102
|
+
it "only accepts Data::CurrentMeasurement for current" do
|
87
103
|
invalid_data = "invalid"
|
88
|
-
invalid_data.class.should_not ==
|
104
|
+
invalid_data.class.should_not == Data::CurrentMeasurement
|
89
105
|
lambda { @measurement.current = invalid_data }.should raise_error(ArgumentError)
|
90
106
|
|
91
|
-
valid_data =
|
92
|
-
valid_data.class.should ==
|
107
|
+
valid_data = Data::CurrentMeasurement.new
|
108
|
+
valid_data.class.should == Data::CurrentMeasurement
|
93
109
|
lambda { @measurement.current = valid_data }.should_not raise_error(ArgumentError)
|
94
110
|
end
|
95
111
|
|
@@ -103,62 +119,92 @@ describe "Measurement" do
|
|
103
119
|
lambda { @measurement.forecast = valid_data }.should_not raise_error(ArgumentError)
|
104
120
|
end
|
105
121
|
|
106
|
-
it "only accepts
|
122
|
+
it "only accepts Data::Zone for timezone" do
|
107
123
|
invalid_data = 1
|
108
|
-
invalid_data.class.should_not ==
|
124
|
+
invalid_data.class.should_not == Data::Zone
|
109
125
|
lambda { @measurement.timezone = invalid_data }.should raise_error(ArgumentError)
|
110
126
|
|
111
|
-
valid_data =
|
112
|
-
valid_data.class.should ==
|
127
|
+
valid_data = Data::Zone.new("Europe/Paris")
|
128
|
+
valid_data.class.should == Data::Zone
|
113
129
|
lambda { @measurement.timezone = valid_data }.should_not raise_error(ArgumentError)
|
114
130
|
end
|
115
131
|
|
116
|
-
it "only accepts
|
132
|
+
it "only accepts Data::Location for station" do
|
117
133
|
invalid_data = 1
|
118
|
-
invalid_data.class.should_not ==
|
134
|
+
invalid_data.class.should_not == Data::Location
|
119
135
|
lambda { @measurement.station = invalid_data }.should raise_error(ArgumentError)
|
120
136
|
|
121
|
-
valid_data =
|
122
|
-
valid_data.class.should ==
|
137
|
+
valid_data = Data::Location.new
|
138
|
+
valid_data.class.should == Data::Location
|
123
139
|
lambda { @measurement.station = valid_data }.should_not raise_error(ArgumentError)
|
124
140
|
end
|
125
141
|
|
126
|
-
it "only accepts
|
142
|
+
it "only accepts Data::Location for location" do
|
127
143
|
invalid_data = 1
|
128
|
-
invalid_data.class.should_not ==
|
144
|
+
invalid_data.class.should_not == Data::Location
|
129
145
|
lambda { @measurement.location = invalid_data }.should raise_error(ArgumentError)
|
130
146
|
|
131
|
-
valid_data =
|
132
|
-
valid_data.class.should ==
|
147
|
+
valid_data = Data::Location.new
|
148
|
+
valid_data.class.should == Data::Location
|
133
149
|
lambda { @measurement.location = valid_data }.should_not raise_error(ArgumentError)
|
134
150
|
end
|
135
151
|
|
152
|
+
it "only accepts Fixnum for weight" do
|
153
|
+
invalid_data = "test"
|
154
|
+
invalid_data.class.should_not == Fixnum
|
155
|
+
lambda { @measurement.weight = invalid_data }.should raise_error(ArgumentError)
|
156
|
+
|
157
|
+
valid_data = 1
|
158
|
+
valid_data.class.should == Fixnum
|
159
|
+
lambda { @measurement.weight = valid_data }.should_not raise_error(ArgumentError)
|
160
|
+
end
|
161
|
+
|
162
|
+
it "only accepts Array for links" do
|
163
|
+
invalid_data = 1
|
164
|
+
invalid_data.class.should_not == Hash
|
165
|
+
lambda { @measurement.links = invalid_data }.should raise_error(ArgumentError)
|
166
|
+
|
167
|
+
valid_data = {1 => nil}
|
168
|
+
valid_data.class.should == Hash
|
169
|
+
lambda { @measurement.links = valid_data }.should_not raise_error(ArgumentError)
|
170
|
+
end
|
171
|
+
|
172
|
+
it "only accepts Data::LocalTime for measured_at" do
|
173
|
+
invalid_data = 1
|
174
|
+
invalid_data.class.should_not == Data::LocalTime
|
175
|
+
lambda { @measurement.measured_at = invalid_data }.should raise_error(ArgumentError)
|
176
|
+
|
177
|
+
valid_data = Data::LocalTime.new
|
178
|
+
valid_data.class.should == Data::LocalTime
|
179
|
+
lambda { @measurement.measured_at = valid_data }.should_not raise_error(ArgumentError)
|
180
|
+
end
|
181
|
+
|
136
182
|
end
|
137
183
|
|
138
184
|
describe "and the helpers" do
|
139
185
|
|
140
186
|
before(:each) do
|
141
|
-
@measurement =
|
187
|
+
@measurement = Data::Measurement.new
|
142
188
|
end
|
143
189
|
|
144
190
|
it "changes state to successful (if successful)" do
|
145
191
|
@measurement.success.should be_false
|
146
192
|
@measurement.success!
|
147
|
-
@measurement.
|
193
|
+
@measurement.utc_time_stamp.should be_nil
|
148
194
|
@measurement.current.should be_nil
|
149
195
|
@measurement.success.should be_false
|
150
196
|
|
151
|
-
@measurement.current =
|
152
|
-
@measurement.current.temperature =
|
197
|
+
@measurement.current = Data::CurrentMeasurement.new
|
198
|
+
@measurement.current.temperature = Data::Temperature.new
|
153
199
|
@measurement.current.temperature.c = 10
|
154
|
-
@measurement.
|
200
|
+
@measurement.utc_time_stamp.should_not be_nil
|
155
201
|
@measurement.success!
|
156
202
|
@measurement.success.should be_true
|
157
203
|
end
|
158
204
|
|
159
205
|
it "returns successful state" do
|
160
|
-
@measurement.current =
|
161
|
-
@measurement.current.temperature =
|
206
|
+
@measurement.current = Data::CurrentMeasurement.new
|
207
|
+
@measurement.current.temperature = Data::Temperature.new
|
162
208
|
@measurement.current.temperature.c = 10
|
163
209
|
@measurement.success!
|
164
210
|
@measurement.success.should be_true
|
@@ -170,30 +216,46 @@ describe "Measurement" do
|
|
170
216
|
@measurement.success?.should be_false
|
171
217
|
end
|
172
218
|
|
173
|
-
it "stamps the
|
174
|
-
@measurement.
|
219
|
+
it "stamps the utc_time_stamp" do
|
220
|
+
@measurement.utc_time_stamp.should be_nil
|
175
221
|
@measurement.stamp!
|
176
|
-
@measurement.
|
222
|
+
@measurement.utc_time_stamp.should_not be_nil
|
177
223
|
end
|
178
224
|
|
179
225
|
it "indicates if current" do
|
180
|
-
@measurement.
|
226
|
+
@measurement.current.should be_nil
|
181
227
|
@measurement.current?.should be_false
|
182
|
-
@measurement.stamp!
|
183
|
-
@measurement.time.should_not be_nil
|
184
|
-
@measurement.current?.should be_true
|
185
228
|
|
186
|
-
@measurement.
|
229
|
+
@measurement.current = Data::CurrentMeasurement.new
|
230
|
+
@measurement.current.current_at.should be_nil
|
231
|
+
@measurement.current?.should be_false
|
232
|
+
|
233
|
+
@measurement.current.current_at = Data::LocalTime.new(9,0,0)
|
187
234
|
@measurement.current?.should be_true
|
235
|
+
@measurement.current?("9:00 am").should be_true
|
236
|
+
|
188
237
|
|
189
|
-
@measurement.time -= (60*60*5)
|
190
|
-
@measurement.current?.should be_false
|
191
238
|
end
|
239
|
+
|
240
|
+
|
241
|
+
# it "indicates if current" do
|
242
|
+
# #@measurement.time.should be_nil
|
243
|
+
# @measurement.current?.should be_false
|
244
|
+
# @measurement.stamp!
|
245
|
+
# @measurement.time.should_not be_nil
|
246
|
+
# @measurement.current?.should be_true
|
247
|
+
#
|
248
|
+
# @measurement.time -= (60*60*3)
|
249
|
+
# @measurement.current?.should be_true
|
250
|
+
#
|
251
|
+
# @measurement.time -= (60*60*5)
|
252
|
+
# @measurement.current?.should be_false
|
253
|
+
# end
|
192
254
|
|
193
255
|
describe "changing units" do
|
194
256
|
|
195
257
|
before(:each) do
|
196
|
-
@measurement =
|
258
|
+
@measurement = Data::Measurement.new
|
197
259
|
end
|
198
260
|
|
199
261
|
it "indicates if metric?" do
|
@@ -224,13 +286,13 @@ describe "Measurement" do
|
|
224
286
|
describe "when searching forecasts using 'for'" do
|
225
287
|
|
226
288
|
before(:each) do
|
227
|
-
@measurement =
|
289
|
+
@measurement = Data::Measurement.new
|
228
290
|
|
229
291
|
# create a measurement object with a forecast array that includes
|
230
292
|
# dates for 4 consecutive days starting with tommorrow
|
231
293
|
@measurement.forecast = []
|
232
294
|
1.upto(4) do |i|
|
233
|
-
forecast_measurement =
|
295
|
+
forecast_measurement = Data::ForecastMeasurement.new
|
234
296
|
forecast_measurement.date = Date.parse((Time.now + (i * 60 * 60 * 24)).to_s)
|
235
297
|
@measurement.forecast << forecast_measurement
|
236
298
|
end
|
@@ -268,6 +330,12 @@ describe "Measurement" do
|
|
268
330
|
@measurement.for(@tommorrow).should == @measurement.forecast.first
|
269
331
|
end
|
270
332
|
|
333
|
+
it "fidns the date using Data::LocalDateTime" do
|
334
|
+
tommorrow = Data::LocalDateTime.parse(@tommorrow.to_s)
|
335
|
+
tommorrow.class.should == Data::LocalDateTime
|
336
|
+
@measurement.for(tommorrow).should == @measurement.forecast.first
|
337
|
+
end
|
338
|
+
|
271
339
|
it "finds nothing when there is not a match" do
|
272
340
|
yesterday = (Time.now - (60 * 60 * 24))
|
273
341
|
yesterday.class.should == Time
|
@@ -279,7 +347,8 @@ describe "Measurement" do
|
|
279
347
|
describe "when answering the simple questions," do
|
280
348
|
|
281
349
|
before(:each) do
|
282
|
-
@measurement =
|
350
|
+
@measurement = Data::Measurement.new(:wunderground)
|
351
|
+
@now = Data::LocalDateTime.parse("2009-05-01 2:05 pm")
|
283
352
|
end
|
284
353
|
|
285
354
|
describe "windy?" do
|
@@ -291,19 +360,19 @@ describe "Measurement" do
|
|
291
360
|
end
|
292
361
|
|
293
362
|
it "requires time as a Time object" do
|
294
|
-
lambda { @measurement.windy?(1,
|
295
|
-
lambda { @measurement.windy?(1
|
363
|
+
#lambda { @measurement.windy?(1,false) }.should raise_error(ArgumentError)
|
364
|
+
lambda { @measurement.windy?(1,@now) }.should_not raise_error(ArgumentError)
|
296
365
|
end
|
297
366
|
|
298
367
|
it "returns true if a source returns true" do
|
299
|
-
module Barometer; class
|
368
|
+
module Barometer; class WeatherService
|
300
369
|
def self.windy?(a=nil,b=nil,c=nil); true; end
|
301
370
|
end; end
|
302
371
|
@measurement.windy?.should be_true
|
303
372
|
end
|
304
373
|
|
305
374
|
it "returns false if a measurement returns false" do
|
306
|
-
module Barometer; class
|
375
|
+
module Barometer; class WeatherService
|
307
376
|
def self.windy?(a=nil,b=nil,c=nil); false; end
|
308
377
|
end; end
|
309
378
|
@measurement.windy?.should be_false
|
@@ -320,19 +389,19 @@ describe "Measurement" do
|
|
320
389
|
end
|
321
390
|
|
322
391
|
it "requires time as a Time object" do
|
323
|
-
lambda { @measurement.wet?(1,"a") }.should raise_error(ArgumentError)
|
324
|
-
lambda { @measurement.wet?(1
|
392
|
+
#lambda { @measurement.wet?(1,"a") }.should raise_error(ArgumentError)
|
393
|
+
lambda { @measurement.wet?(1,@now) }.should_not raise_error(ArgumentError)
|
325
394
|
end
|
326
395
|
|
327
396
|
it "returns true if a source returns true" do
|
328
|
-
module Barometer; class
|
397
|
+
module Barometer; class WeatherService
|
329
398
|
def self.wet?(a=nil,b=nil,c=nil); true; end
|
330
399
|
end; end
|
331
400
|
@measurement.wet?.should be_true
|
332
401
|
end
|
333
402
|
|
334
403
|
it "returns false if a measurement returns false" do
|
335
|
-
module Barometer; class
|
404
|
+
module Barometer; class WeatherService
|
336
405
|
def self.wet?(a=nil,b=nil,c=nil); false; end
|
337
406
|
end; end
|
338
407
|
@measurement.wet?.should be_false
|
@@ -343,19 +412,19 @@ describe "Measurement" do
|
|
343
412
|
describe "day?" do
|
344
413
|
|
345
414
|
it "requires time as a Time object" do
|
346
|
-
lambda { @measurement.day?("a") }.should raise_error(ArgumentError)
|
347
|
-
lambda { @measurement.day?(
|
415
|
+
#lambda { @measurement.day?("a") }.should raise_error(ArgumentError)
|
416
|
+
lambda { @measurement.day?(@now) }.should_not raise_error(ArgumentError)
|
348
417
|
end
|
349
418
|
|
350
419
|
it "returns true if a source returns true" do
|
351
|
-
module Barometer; class
|
420
|
+
module Barometer; class WeatherService
|
352
421
|
def self.day?(a=nil,b=nil); true; end
|
353
422
|
end; end
|
354
423
|
@measurement.day?.should be_true
|
355
424
|
end
|
356
425
|
|
357
426
|
it "returns false if a measurement returns false" do
|
358
|
-
module Barometer; class
|
427
|
+
module Barometer; class WeatherService
|
359
428
|
def self.day?(a=nil,b=nil); false; end
|
360
429
|
end; end
|
361
430
|
@measurement.day?.should be_false
|
@@ -366,39 +435,39 @@ describe "Measurement" do
|
|
366
435
|
describe "sunny?" do
|
367
436
|
|
368
437
|
it "requires time as a Time object" do
|
369
|
-
lambda { @measurement.sunny?("a") }.should raise_error(ArgumentError)
|
370
|
-
lambda { @measurement.sunny?(
|
438
|
+
#lambda { @measurement.sunny?("a") }.should raise_error(ArgumentError)
|
439
|
+
lambda { @measurement.sunny?(@now) }.should_not raise_error(ArgumentError)
|
371
440
|
end
|
372
441
|
|
373
442
|
it "returns true if a source returns true" do
|
374
|
-
module Barometer; class
|
443
|
+
module Barometer; class WeatherService
|
375
444
|
def self.day?(a=nil,b=nil); true; end
|
376
445
|
end; end
|
377
|
-
module Barometer; class
|
446
|
+
module Barometer; class WeatherService
|
378
447
|
def self.sunny?(a=nil,b=nil); true; end
|
379
448
|
end; end
|
380
449
|
@measurement.sunny?.should be_true
|
381
450
|
end
|
382
451
|
|
383
452
|
it "returns false if a measurement returns false" do
|
384
|
-
module Barometer; class
|
453
|
+
module Barometer; class WeatherService
|
385
454
|
def self.day?(a=nil,b=nil); true; end
|
386
455
|
end; end
|
387
|
-
module Barometer; class
|
456
|
+
module Barometer; class WeatherService
|
388
457
|
def self.sunny?(a=nil,b=nil); false; end
|
389
458
|
end; end
|
390
459
|
@measurement.sunny?.should be_false
|
391
460
|
end
|
392
461
|
|
393
462
|
it "returns false if night time" do
|
394
|
-
module Barometer; class
|
463
|
+
module Barometer; class WeatherService
|
395
464
|
def self.day?(a=nil,b=nil); true; end
|
396
465
|
end; end
|
397
|
-
module Barometer; class
|
466
|
+
module Barometer; class WeatherService
|
398
467
|
def self.sunny?(a=nil,b=nil); true; end
|
399
468
|
end; end
|
400
469
|
@measurement.sunny?.should be_true
|
401
|
-
module Barometer; class
|
470
|
+
module Barometer; class WeatherService
|
402
471
|
def self.day?(a=nil,b=nil); false; end
|
403
472
|
end; end
|
404
473
|
@measurement.sunny?.should be_false
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe "Forecasted Night Measurement" do
|
4
|
+
|
5
|
+
describe "when initialized" do
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@night = Data::NightMeasurement.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it "responds to date" do
|
12
|
+
@night.date.should be_nil
|
13
|
+
end
|
14
|
+
|
15
|
+
it "responds to icon" do
|
16
|
+
@night.icon.should be_nil
|
17
|
+
end
|
18
|
+
|
19
|
+
it "responds to condition" do
|
20
|
+
@night.condition.should be_nil
|
21
|
+
end
|
22
|
+
|
23
|
+
it "responds to pop" do
|
24
|
+
@night.pop.should be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "responds to humidity" do
|
28
|
+
@night.humidity.should be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it "responds to wind" do
|
32
|
+
@night.wind.should be_nil
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "when writing data" do
|
38
|
+
|
39
|
+
before(:each) do
|
40
|
+
@night = Data::NightMeasurement.new
|
41
|
+
end
|
42
|
+
|
43
|
+
it "only accepts Date for date" do
|
44
|
+
invalid_data = 1
|
45
|
+
invalid_data.class.should_not == Date
|
46
|
+
lambda { @night.date = invalid_data }.should raise_error(ArgumentError)
|
47
|
+
|
48
|
+
valid_data = Date.new
|
49
|
+
valid_data.class.should == Date
|
50
|
+
lambda { @night.date = valid_data }.should_not raise_error(ArgumentError)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "only accepts String for icon" do
|
54
|
+
invalid_data = 1
|
55
|
+
invalid_data.class.should_not == String
|
56
|
+
lambda { @night.icon = invalid_data }.should raise_error(ArgumentError)
|
57
|
+
|
58
|
+
valid_data = "valid"
|
59
|
+
valid_data.class.should == String
|
60
|
+
lambda { @night.icon = valid_data }.should_not raise_error(ArgumentError)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "only accepts String for condition" do
|
64
|
+
invalid_data = 1
|
65
|
+
invalid_data.class.should_not == String
|
66
|
+
lambda { @night.condition = invalid_data }.should raise_error(ArgumentError)
|
67
|
+
|
68
|
+
valid_data = "valid"
|
69
|
+
valid_data.class.should == String
|
70
|
+
lambda { @night.condition = valid_data }.should_not raise_error(ArgumentError)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "only accepts Fixnum for pop" do
|
74
|
+
invalid_data = "test"
|
75
|
+
invalid_data.class.should_not == Fixnum
|
76
|
+
lambda { @night.pop = invalid_data }.should raise_error(ArgumentError)
|
77
|
+
|
78
|
+
valid_data = 50
|
79
|
+
valid_data.class.should == Fixnum
|
80
|
+
lambda { @night.pop = valid_data }.should_not raise_error(ArgumentError)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "only accepts Data::Speed for wind" do
|
84
|
+
invalid_data = "test"
|
85
|
+
invalid_data.class.should_not == Data::Speed
|
86
|
+
lambda { @night.wind = invalid_data }.should raise_error(ArgumentError)
|
87
|
+
|
88
|
+
valid_data = Data::Speed.new
|
89
|
+
valid_data.class.should == Data::Speed
|
90
|
+
lambda { @night.wind = valid_data }.should_not raise_error(ArgumentError)
|
91
|
+
end
|
92
|
+
|
93
|
+
it "only accepts Fixnum for humidity" do
|
94
|
+
invalid_data = "test"
|
95
|
+
invalid_data.class.should_not == Fixnum
|
96
|
+
lambda { @night.humidity = invalid_data }.should raise_error(ArgumentError)
|
97
|
+
|
98
|
+
valid_data = 50
|
99
|
+
valid_data.class.should == Fixnum
|
100
|
+
lambda { @night.humidity = valid_data }.should_not raise_error(ArgumentError)
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "method missing" do
|
106
|
+
|
107
|
+
before(:each) do
|
108
|
+
@night = Data::NightMeasurement.new
|
109
|
+
end
|
110
|
+
|
111
|
+
it "responds to method + ?" do
|
112
|
+
valid_method = "pop"
|
113
|
+
@night.respond_to?(valid_method).should be_true
|
114
|
+
lambda { @night.send(valid_method + "?") }.should_not raise_error(NoMethodError)
|
115
|
+
end
|
116
|
+
|
117
|
+
it "ignores non_method + ?" do
|
118
|
+
invalid_method = "humid"
|
119
|
+
@night.respond_to?(invalid_method).should be_false
|
120
|
+
lambda { @night.send(invalid_method + "?") }.should raise_error(NoMethodError)
|
121
|
+
end
|
122
|
+
|
123
|
+
it "returns true if set" do
|
124
|
+
@night.pop = 10
|
125
|
+
@night.pop.should_not be_nil
|
126
|
+
@night.pop?.should be_true
|
127
|
+
end
|
128
|
+
|
129
|
+
it "returns false if not set" do
|
130
|
+
@night.pop.should be_nil
|
131
|
+
@night.pop?.should be_false
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|