File tree Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Expand file tree Collapse file tree 2 files changed +28
-2
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ Add the following to your **Gemfile**
34
34
OpenWeather::Forecast.city("Cochin, IN")
35
35
36
36
# get weather forecast by city name in fahrenheit
37
- OpenWeather::Forecast.city("Cochin, IN", units: 'fahrenheit ')
37
+ OpenWeather::Forecast.city("Cochin, IN", units: 'imperial ')
38
38
39
39
# get weather forecast by city id
40
40
OpenWeather::Forecast.city_id("1273874")
Original file line number Diff line number Diff line change 67
67
response [ 'cod' ] . should eq ( "404" )
68
68
end
69
69
end
70
+
71
+ context 'units option' do
72
+ it 'returns the current temperature in requested units' do
73
+ response = OpenWeather ::Current . city ( 'Cochin, In' , units : 'metric' )
74
+ temp_metric = response [ 'main' ] [ 'temp' ]
75
+
76
+ response = OpenWeather ::Current . city ( 'Cochin, In' , units : 'imperial' )
77
+ temp_imperial = response [ 'main' ] [ 'temp' ]
78
+ farenheit_to_celsius = ( ( temp_imperial - 32 ) / 1.8000 )
79
+
80
+ expect ( farenheit_to_celsius ) . to be_within ( 0.01 ) . of ( temp_metric )
81
+ end
82
+ end
70
83
end
71
84
72
85
describe 'Open weather Forecast API' do
105
118
response [ 'cod' ] . to_s . should eq ( "404" )
106
119
end
107
120
end
108
- end
121
+
122
+ context 'units option' do
123
+ it 'returns the forecast in requested units' do
124
+ response = OpenWeather ::Forecast . city ( 'Cochin, In' , units : 'metric' )
125
+ temp_metric = response [ 'list' ] . first [ 'main' ] [ 'temp' ]
126
+
127
+ response = OpenWeather ::Forecast . city ( 'Cochin, In' , units : 'imperial' )
128
+ temp_imperial = response [ 'list' ] . first [ 'main' ] [ 'temp' ]
129
+ farenheit_to_celsius = ( ( temp_imperial - 32 ) / 1.8000 )
130
+
131
+ expect ( farenheit_to_celsius ) . to be_within ( 0.01 ) . of ( temp_metric )
132
+ end
133
+ end
134
+ end
You can’t perform that action at this time.
0 commit comments