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
@@ -5,11 +5,7 @@ describe "Current Measurement" do
|
|
5
5
|
describe "when initialized" do
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
@current =
|
9
|
-
end
|
10
|
-
|
11
|
-
it "responds to time" do
|
12
|
-
@current.time.should be_nil
|
8
|
+
@current = Data::CurrentMeasurement.new
|
13
9
|
end
|
14
10
|
|
15
11
|
it "responds to humidity" do
|
@@ -56,24 +52,22 @@ describe "Current Measurement" do
|
|
56
52
|
@current.sun.should be_nil
|
57
53
|
end
|
58
54
|
|
55
|
+
it "responds to current_at" do
|
56
|
+
@current.current_at.should be_nil
|
57
|
+
end
|
58
|
+
|
59
|
+
it "responds to updated_at" do
|
60
|
+
@current.updated_at.should be_nil
|
61
|
+
end
|
62
|
+
|
59
63
|
end
|
60
64
|
|
61
65
|
describe "when writing data" do
|
62
66
|
|
63
67
|
before(:each) do
|
64
|
-
@current =
|
68
|
+
@current = Data::CurrentMeasurement.new
|
65
69
|
end
|
66
70
|
|
67
|
-
# it "only accepts Time for time" do
|
68
|
-
# invalid_data = 1
|
69
|
-
# invalid_data.class.should_not == Time
|
70
|
-
# lambda { @current.time = invalid_data }.should raise_error(ArgumentError)
|
71
|
-
#
|
72
|
-
# valid_data = Time.new
|
73
|
-
# valid_data.class.should == Time
|
74
|
-
# lambda { @current.time = valid_data }.should_not raise_error(ArgumentError)
|
75
|
-
# end
|
76
|
-
|
77
71
|
it "only accepts Fixnum or Float for humidity" do
|
78
72
|
invalid_data = "invalid"
|
79
73
|
invalid_data.class.should_not == Fixnum
|
@@ -109,92 +103,122 @@ describe "Current Measurement" do
|
|
109
103
|
lambda { @current.condition = valid_data }.should_not raise_error(ArgumentError)
|
110
104
|
end
|
111
105
|
|
112
|
-
it "only accepts
|
106
|
+
it "only accepts Data::Temperature for temperature" do
|
113
107
|
invalid_data = 1
|
114
|
-
invalid_data.class.should_not ==
|
108
|
+
invalid_data.class.should_not == Data::Temperature
|
115
109
|
lambda { @current.temperature = invalid_data }.should raise_error(ArgumentError)
|
116
110
|
|
117
|
-
valid_data =
|
118
|
-
valid_data.class.should ==
|
111
|
+
valid_data = Data::Temperature.new
|
112
|
+
valid_data.class.should == Data::Temperature
|
119
113
|
lambda { @current.temperature = valid_data }.should_not raise_error(ArgumentError)
|
120
114
|
end
|
121
115
|
|
122
|
-
it "only accepts
|
116
|
+
it "only accepts Data::Temperature for dew_point" do
|
123
117
|
invalid_data = 1
|
124
|
-
invalid_data.class.should_not ==
|
118
|
+
invalid_data.class.should_not == Data::Temperature
|
125
119
|
lambda { @current.dew_point = invalid_data }.should raise_error(ArgumentError)
|
126
120
|
|
127
|
-
valid_data =
|
128
|
-
valid_data.class.should ==
|
121
|
+
valid_data = Data::Temperature.new
|
122
|
+
valid_data.class.should == Data::Temperature
|
129
123
|
lambda { @current.dew_point = valid_data }.should_not raise_error(ArgumentError)
|
130
124
|
end
|
131
125
|
|
132
|
-
it "only accepts
|
126
|
+
it "only accepts Data::Temperature for heat_index" do
|
133
127
|
invalid_data = 1
|
134
|
-
invalid_data.class.should_not ==
|
128
|
+
invalid_data.class.should_not == Data::Temperature
|
135
129
|
lambda { @current.heat_index = invalid_data }.should raise_error(ArgumentError)
|
136
130
|
|
137
|
-
valid_data =
|
138
|
-
valid_data.class.should ==
|
131
|
+
valid_data = Data::Temperature.new
|
132
|
+
valid_data.class.should == Data::Temperature
|
139
133
|
lambda { @current.heat_index = valid_data }.should_not raise_error(ArgumentError)
|
140
134
|
end
|
141
135
|
|
142
|
-
it "only accepts
|
136
|
+
it "only accepts Data::Temperature for wind_chill" do
|
143
137
|
invalid_data = 1
|
144
|
-
invalid_data.class.should_not ==
|
138
|
+
invalid_data.class.should_not == Data::Temperature
|
145
139
|
lambda { @current.wind_chill = invalid_data }.should raise_error(ArgumentError)
|
146
140
|
|
147
|
-
valid_data =
|
148
|
-
valid_data.class.should ==
|
141
|
+
valid_data = Data::Temperature.new
|
142
|
+
valid_data.class.should == Data::Temperature
|
149
143
|
lambda { @current.wind_chill = valid_data }.should_not raise_error(ArgumentError)
|
150
144
|
end
|
151
145
|
|
152
|
-
it "only accepts
|
146
|
+
it "only accepts Data::Speed for wind" do
|
153
147
|
invalid_data = 1
|
154
|
-
invalid_data.class.should_not ==
|
148
|
+
invalid_data.class.should_not == Data::Speed
|
155
149
|
lambda { @current.wind = invalid_data }.should raise_error(ArgumentError)
|
156
150
|
|
157
|
-
valid_data =
|
158
|
-
valid_data.class.should ==
|
151
|
+
valid_data = Data::Speed.new
|
152
|
+
valid_data.class.should == Data::Speed
|
159
153
|
lambda { @current.wind = valid_data }.should_not raise_error(ArgumentError)
|
160
154
|
end
|
161
155
|
|
162
|
-
it "only accepts
|
156
|
+
it "only accepts Data::Pressure for pressure" do
|
163
157
|
invalid_data = 1
|
164
|
-
invalid_data.class.should_not ==
|
158
|
+
invalid_data.class.should_not == Data::Pressure
|
165
159
|
lambda { @current.pressure = invalid_data }.should raise_error(ArgumentError)
|
166
160
|
|
167
|
-
valid_data =
|
168
|
-
valid_data.class.should ==
|
161
|
+
valid_data = Data::Pressure.new
|
162
|
+
valid_data.class.should == Data::Pressure
|
169
163
|
lambda { @current.pressure = valid_data }.should_not raise_error(ArgumentError)
|
170
164
|
end
|
171
165
|
|
172
|
-
it "only accepts
|
166
|
+
it "only accepts Data::Distance for visibility" do
|
173
167
|
invalid_data = 1
|
174
|
-
invalid_data.class.should_not ==
|
168
|
+
invalid_data.class.should_not == Data::Distance
|
175
169
|
lambda { @current.visibility = invalid_data }.should raise_error(ArgumentError)
|
176
170
|
|
177
|
-
valid_data =
|
178
|
-
valid_data.class.should ==
|
171
|
+
valid_data = Data::Distance.new
|
172
|
+
valid_data.class.should == Data::Distance
|
179
173
|
lambda { @current.visibility = valid_data }.should_not raise_error(ArgumentError)
|
180
174
|
end
|
181
175
|
|
182
|
-
it "only accepts
|
176
|
+
it "only accepts Data::Sun for sun" do
|
183
177
|
invalid_data = 1
|
184
|
-
invalid_data.class.should_not ==
|
178
|
+
invalid_data.class.should_not == Data::Sun
|
185
179
|
lambda { @current.sun = invalid_data }.should raise_error(ArgumentError)
|
186
180
|
|
187
|
-
valid_data =
|
188
|
-
valid_data.class.should ==
|
181
|
+
valid_data = Data::Sun.new
|
182
|
+
valid_data.class.should == Data::Sun
|
189
183
|
lambda { @current.sun = valid_data }.should_not raise_error(ArgumentError)
|
190
184
|
end
|
191
185
|
|
186
|
+
it "only accepts Data::LocalTime || Data::LocalDateTime current_at" do
|
187
|
+
invalid_data = 1
|
188
|
+
invalid_data.class.should_not == Data::LocalTime
|
189
|
+
invalid_data.class.should_not == Data::LocalDateTime
|
190
|
+
lambda { @current.current_at = invalid_data }.should raise_error(ArgumentError)
|
191
|
+
|
192
|
+
valid_data = Data::LocalTime.new
|
193
|
+
valid_data.class.should == Data::LocalTime
|
194
|
+
lambda { @current.current_at = valid_data }.should_not raise_error(ArgumentError)
|
195
|
+
|
196
|
+
valid_data = Data::LocalDateTime.new(2009,1,1)
|
197
|
+
valid_data.class.should == Data::LocalDateTime
|
198
|
+
lambda { @current.current_at = valid_data }.should_not raise_error(ArgumentError)
|
199
|
+
end
|
200
|
+
|
201
|
+
it "only accepts Data::LocalTime || Data::LocalDateTime current_at" do
|
202
|
+
invalid_data = 1
|
203
|
+
invalid_data.class.should_not == Data::LocalTime
|
204
|
+
invalid_data.class.should_not == Data::LocalDateTime
|
205
|
+
lambda { @current.updated_at = invalid_data }.should raise_error(ArgumentError)
|
206
|
+
|
207
|
+
valid_data = Data::LocalTime.new
|
208
|
+
valid_data.class.should == Data::LocalTime
|
209
|
+
lambda { @current.updated_at = valid_data }.should_not raise_error(ArgumentError)
|
210
|
+
|
211
|
+
valid_data = Data::LocalDateTime.new(2009,1,1)
|
212
|
+
valid_data.class.should == Data::LocalDateTime
|
213
|
+
lambda { @current.updated_at = valid_data }.should_not raise_error(ArgumentError)
|
214
|
+
end
|
215
|
+
|
192
216
|
end
|
193
217
|
|
194
218
|
describe "method missing" do
|
195
219
|
|
196
220
|
before(:each) do
|
197
|
-
@current =
|
221
|
+
@current = Data::CurrentMeasurement.new
|
198
222
|
end
|
199
223
|
|
200
224
|
it "responds to method + ?" do
|
@@ -1,21 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe "Distance" do
|
3
|
+
describe "Data::Distance" do
|
4
4
|
|
5
5
|
describe "when initialized" do
|
6
6
|
|
7
7
|
it "defines METRIC_UNITS" do
|
8
|
-
|
9
|
-
|
8
|
+
Data::Distance.const_defined?("METRIC_UNITS").should be_true
|
9
|
+
Data::Distance::METRIC_UNITS.should == "km"
|
10
10
|
end
|
11
11
|
|
12
12
|
it "defines IMPERIAL_UNITS" do
|
13
|
-
|
14
|
-
|
13
|
+
Data::Distance.const_defined?("IMPERIAL_UNITS").should be_true
|
14
|
+
Data::Distance::IMPERIAL_UNITS.should == "m"
|
15
15
|
end
|
16
16
|
|
17
17
|
before(:each) do
|
18
|
-
@distance =
|
18
|
+
@distance = Data::Distance.new
|
19
19
|
end
|
20
20
|
|
21
21
|
it "responds to kilometers" do
|
@@ -52,20 +52,20 @@ describe "Distance" do
|
|
52
52
|
end
|
53
53
|
|
54
54
|
it "requires a value, that is either Integer or Float" do
|
55
|
-
|
56
|
-
|
55
|
+
Data::Distance.km_to_m(nil).should be_nil
|
56
|
+
Data::Distance.m_to_km(nil).should be_nil
|
57
57
|
|
58
58
|
not_float_or_integer = "string"
|
59
|
-
|
60
|
-
|
59
|
+
Data::Distance.km_to_m(not_float_or_integer).should be_nil
|
60
|
+
Data::Distance.m_to_km(not_float_or_integer).should be_nil
|
61
61
|
end
|
62
62
|
|
63
63
|
it "converts KM to M" do
|
64
|
-
((
|
64
|
+
((Data::Distance.km_to_m(@km)*10).round/10.0).should == @m
|
65
65
|
end
|
66
66
|
|
67
67
|
it "converts M to KM" do
|
68
|
-
((
|
68
|
+
((Data::Distance.m_to_km(@m)*10).round/10.0).should == @km
|
69
69
|
end
|
70
70
|
|
71
71
|
end
|
@@ -73,7 +73,7 @@ describe "Distance" do
|
|
73
73
|
describe "updating" do
|
74
74
|
|
75
75
|
before(:each) do
|
76
|
-
@distance =
|
76
|
+
@distance = Data::Distance.new
|
77
77
|
@m = 26.2
|
78
78
|
@km = 42.2
|
79
79
|
end
|
@@ -123,7 +123,7 @@ describe "Distance" do
|
|
123
123
|
describe "storing" do
|
124
124
|
|
125
125
|
before(:each) do
|
126
|
-
@distance =
|
126
|
+
@distance = Data::Distance.new
|
127
127
|
@m = 26.2
|
128
128
|
@km = 42.2
|
129
129
|
end
|
@@ -165,7 +165,7 @@ describe "Distance" do
|
|
165
165
|
describe "retrieving" do
|
166
166
|
|
167
167
|
before(:each) do
|
168
|
-
@distance =
|
168
|
+
@distance = Data::Distance.new
|
169
169
|
@m = 26.2
|
170
170
|
@km = 42.16
|
171
171
|
end
|
@@ -233,52 +233,52 @@ describe "Distance" do
|
|
233
233
|
before(:each) do
|
234
234
|
@m = 26.2
|
235
235
|
@km = 42.16
|
236
|
-
@distance_low =
|
236
|
+
@distance_low = Data::Distance.new
|
237
237
|
@distance_low.km = (@m - 1.0)
|
238
|
-
@distance_high =
|
238
|
+
@distance_high = Data::Distance.new
|
239
239
|
@distance_high.km = (@km + 1.0)
|
240
|
-
@distance =
|
240
|
+
@distance = Data::Distance.new
|
241
241
|
@distance.km = @km
|
242
|
-
@distance_same =
|
242
|
+
@distance_same = Data::Distance.new
|
243
243
|
@distance_same.km = @km
|
244
244
|
end
|
245
245
|
|
246
246
|
it "defines <=>" do
|
247
|
-
|
247
|
+
Data::Distance.method_defined?("<=>").should be_true
|
248
248
|
(@distance_low <=> @distance_high).should == -1
|
249
249
|
(@distance_high <=> @distance_low).should == 1
|
250
250
|
(@distance <=> @distance_same).should == 0
|
251
251
|
end
|
252
252
|
|
253
253
|
it "defines <" do
|
254
|
-
|
254
|
+
Data::Distance.method_defined?("<").should be_true
|
255
255
|
@distance_low.should < @distance_high
|
256
256
|
@distance_high.should_not < @distance_low
|
257
257
|
@distance.should_not < @distance_same
|
258
258
|
end
|
259
259
|
|
260
260
|
it "defines >" do
|
261
|
-
|
261
|
+
Data::Distance.method_defined?(">").should be_true
|
262
262
|
@distance_low.should_not > @distance_high
|
263
263
|
@distance_high.should > @distance_low
|
264
264
|
@distance.should_not > @distance_same
|
265
265
|
end
|
266
266
|
|
267
267
|
it "defines ==" do
|
268
|
-
|
268
|
+
Data::Distance.method_defined?("==").should be_true
|
269
269
|
@distance_low.should_not == @distance_high
|
270
270
|
@distance.should == @distance_same
|
271
271
|
end
|
272
272
|
|
273
273
|
it "defines <=" do
|
274
|
-
|
274
|
+
Data::Distance.method_defined?("<=").should be_true
|
275
275
|
@distance_low.should <= @distance_high
|
276
276
|
@distance_high.should_not <= @distance_low
|
277
277
|
@distance.should <= @distance_same
|
278
278
|
end
|
279
279
|
|
280
280
|
it "defines >=" do
|
281
|
-
|
281
|
+
Data::Distance.method_defined?(">=").should be_true
|
282
282
|
@distance_low.should_not >= @distance_high
|
283
283
|
@distance_high.should >= @distance_low
|
284
284
|
@distance.should >= @distance_same
|
@@ -291,7 +291,7 @@ describe "Distance" do
|
|
291
291
|
before(:each) do
|
292
292
|
@m = 26.2
|
293
293
|
@km = 42.16
|
294
|
-
@distance =
|
294
|
+
@distance = Data::Distance.new
|
295
295
|
@distance.km = @km
|
296
296
|
end
|
297
297
|
|
@@ -315,20 +315,20 @@ describe "Distance" do
|
|
315
315
|
|
316
316
|
it "returns just the integer value with units" do
|
317
317
|
@distance.metric?.should be_true
|
318
|
-
@distance.to_s.should == "#{@km.to_i} #{
|
318
|
+
@distance.to_s.should == "#{@km.to_i} #{Data::Distance::METRIC_UNITS}"
|
319
319
|
|
320
320
|
@distance.imperial!
|
321
321
|
@distance.metric?.should be_false
|
322
|
-
@distance.to_s.should == "#{@m.to_i} #{
|
322
|
+
@distance.to_s.should == "#{@m.to_i} #{Data::Distance::IMPERIAL_UNITS}"
|
323
323
|
end
|
324
324
|
|
325
325
|
it "returns just the units" do
|
326
326
|
@distance.metric?.should be_true
|
327
|
-
@distance.units.should ==
|
327
|
+
@distance.units.should == Data::Distance::METRIC_UNITS
|
328
328
|
|
329
329
|
@distance.imperial!
|
330
330
|
@distance.metric?.should be_false
|
331
|
-
@distance.units.should ==
|
331
|
+
@distance.units.should == Data::Distance::IMPERIAL_UNITS
|
332
332
|
end
|
333
333
|
|
334
334
|
end
|
@@ -5,7 +5,7 @@ describe "Forecast Measurement" do
|
|
5
5
|
describe "when initialized" do
|
6
6
|
|
7
7
|
before(:each) do
|
8
|
-
@forecast =
|
8
|
+
@forecast = Data::ForecastMeasurement.new
|
9
9
|
end
|
10
10
|
|
11
11
|
it "responds to date" do
|
@@ -32,16 +32,28 @@ describe "Forecast Measurement" do
|
|
32
32
|
@forecast.pop.should be_nil
|
33
33
|
end
|
34
34
|
|
35
|
+
it "responds to humidity" do
|
36
|
+
@forecast.humidity.should be_nil
|
37
|
+
end
|
38
|
+
|
39
|
+
it "responds to wind" do
|
40
|
+
@forecast.wind.should be_nil
|
41
|
+
end
|
42
|
+
|
35
43
|
it "responds to sun" do
|
36
44
|
@forecast.sun.should be_nil
|
37
45
|
end
|
38
46
|
|
47
|
+
it "responds to night" do
|
48
|
+
@forecast.night.should be_nil
|
49
|
+
end
|
50
|
+
|
39
51
|
end
|
40
52
|
|
41
53
|
describe "when writing data" do
|
42
54
|
|
43
55
|
before(:each) do
|
44
|
-
@forecast =
|
56
|
+
@forecast = Data::ForecastMeasurement.new
|
45
57
|
end
|
46
58
|
|
47
59
|
it "only accepts Date for date" do
|
@@ -74,23 +86,23 @@ describe "Forecast Measurement" do
|
|
74
86
|
lambda { @forecast.condition = valid_data }.should_not raise_error(ArgumentError)
|
75
87
|
end
|
76
88
|
|
77
|
-
it "only accepts
|
89
|
+
it "only accepts Data::Temperature for high" do
|
78
90
|
invalid_data = 1
|
79
|
-
invalid_data.class.should_not ==
|
91
|
+
invalid_data.class.should_not == Data::Temperature
|
80
92
|
lambda { @forecast.high = invalid_data }.should raise_error(ArgumentError)
|
81
93
|
|
82
|
-
valid_data =
|
83
|
-
valid_data.class.should ==
|
94
|
+
valid_data = Data::Temperature.new
|
95
|
+
valid_data.class.should == Data::Temperature
|
84
96
|
lambda { @forecast.high = valid_data }.should_not raise_error(ArgumentError)
|
85
97
|
end
|
86
98
|
|
87
|
-
it "only accepts
|
99
|
+
it "only accepts Data::Temperature for low" do
|
88
100
|
invalid_data = 1
|
89
|
-
invalid_data.class.should_not ==
|
101
|
+
invalid_data.class.should_not == Data::Temperature
|
90
102
|
lambda { @forecast.low = invalid_data }.should raise_error(ArgumentError)
|
91
103
|
|
92
|
-
valid_data =
|
93
|
-
valid_data.class.should ==
|
104
|
+
valid_data = Data::Temperature.new
|
105
|
+
valid_data.class.should == Data::Temperature
|
94
106
|
lambda { @forecast.low = valid_data }.should_not raise_error(ArgumentError)
|
95
107
|
end
|
96
108
|
|
@@ -104,22 +116,52 @@ describe "Forecast Measurement" do
|
|
104
116
|
lambda { @forecast.pop = valid_data }.should_not raise_error(ArgumentError)
|
105
117
|
end
|
106
118
|
|
107
|
-
it "only accepts
|
119
|
+
it "only accepts Data::Speed for wind" do
|
120
|
+
invalid_data = "test"
|
121
|
+
invalid_data.class.should_not == Data::Speed
|
122
|
+
lambda { @forecast.wind = invalid_data }.should raise_error(ArgumentError)
|
123
|
+
|
124
|
+
valid_data = Data::Speed.new
|
125
|
+
valid_data.class.should == Data::Speed
|
126
|
+
lambda { @forecast.wind = valid_data }.should_not raise_error(ArgumentError)
|
127
|
+
end
|
128
|
+
|
129
|
+
it "only accepts Fixnum for humidity" do
|
130
|
+
invalid_data = "test"
|
131
|
+
invalid_data.class.should_not == Fixnum
|
132
|
+
lambda { @forecast.humidity = invalid_data }.should raise_error(ArgumentError)
|
133
|
+
|
134
|
+
valid_data = 50
|
135
|
+
valid_data.class.should == Fixnum
|
136
|
+
lambda { @forecast.humidity = valid_data }.should_not raise_error(ArgumentError)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "only accepts Data::Sun for sun" do
|
108
140
|
invalid_data = 1
|
109
|
-
invalid_data.class.should_not ==
|
141
|
+
invalid_data.class.should_not == Data::Sun
|
110
142
|
lambda { @forecast.sun = invalid_data }.should raise_error(ArgumentError)
|
111
143
|
|
112
|
-
valid_data =
|
113
|
-
valid_data.class.should ==
|
144
|
+
valid_data = Data::Sun.new
|
145
|
+
valid_data.class.should == Data::Sun
|
114
146
|
lambda { @forecast.sun = valid_data }.should_not raise_error(ArgumentError)
|
115
147
|
end
|
116
148
|
|
149
|
+
it "only accepts Data::NightMeasurement for sun" do
|
150
|
+
invalid_data = 1
|
151
|
+
invalid_data.class.should_not == Data::NightMeasurement
|
152
|
+
lambda { @forecast.night = invalid_data }.should raise_error(ArgumentError)
|
153
|
+
|
154
|
+
valid_data = Data::NightMeasurement.new
|
155
|
+
valid_data.class.should == Data::NightMeasurement
|
156
|
+
lambda { @forecast.night = valid_data }.should_not raise_error(ArgumentError)
|
157
|
+
end
|
158
|
+
|
117
159
|
end
|
118
160
|
|
119
161
|
describe "method missing" do
|
120
162
|
|
121
163
|
before(:each) do
|
122
|
-
@forecast =
|
164
|
+
@forecast = Data::ForecastMeasurement.new
|
123
165
|
end
|
124
166
|
|
125
167
|
it "responds to method + ?" do
|