metar-parser 1.1.8 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +39 -24
- data/Rakefile +0 -11
- data/bin/parse_raw.rb +0 -1
- data/lib/metar/raw.rb +57 -18
- data/lib/metar/version.rb +2 -2
- data/spec/spec_helper.rb +0 -1
- data/spec/unit/distance_spec.rb +36 -46
- data/spec/unit/parser_spec.rb +32 -11
- data/spec/unit/pressure_spec.rb +6 -17
- data/spec/unit/raw_spec.rb +117 -38
- data/spec/unit/remark_spec.rb +34 -39
- data/spec/unit/report_spec.rb +92 -102
- data/spec/unit/runway_visible_range_spec.rb +3 -4
- data/spec/unit/sky_condition_spec.rb +2 -2
- data/spec/unit/speed_spec.rb +11 -17
- data/spec/unit/station_spec.rb +92 -101
- data/spec/unit/temperature_spec.rb +8 -19
- data/spec/unit/variable_wind_spec.rb +9 -17
- data/spec/unit/vertical_visibility_spec.rb +8 -14
- data/spec/unit/visibility_spec.rb +16 -19
- data/spec/unit/weather_phenomenon_spec.rb +3 -4
- data/spec/unit/wind_spec.rb +13 -14
- metadata +147 -163
data/spec/unit/pressure_spec.rb
CHANGED
@@ -1,33 +1,22 @@
|
|
1
|
-
|
2
|
-
load File.expand_path( '../spec_helper.rb', File.dirname(__FILE__) )
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe Metar::Pressure do
|
5
|
-
|
6
4
|
context '.parse' do
|
7
|
-
|
8
5
|
it 'interprets the Q prefix as hectopascals' do
|
9
|
-
Metar::Pressure.parse( 'Q1300' ).value.
|
10
|
-
should be_within( 0.01 ).of( 1.3 )
|
6
|
+
expect(Metar::Pressure.parse( 'Q1300' ).value).to be_within( 0.01 ).of( 1.3 )
|
11
7
|
end
|
12
8
|
|
13
9
|
it 'interprets the A prefix as inches of mercury' do
|
14
|
-
Metar::Pressure.parse( 'A1234' ).value.
|
15
|
-
should be_within( 0.01 ).of( 0.42 )
|
10
|
+
expect(Metar::Pressure.parse( 'A1234' ).value).to be_within( 0.01 ).of( 0.42 )
|
16
11
|
end
|
17
12
|
|
18
13
|
it 'require 4 digits' do
|
19
|
-
Metar::Pressure.parse( 'Q12345' ).
|
20
|
-
|
21
|
-
Metar::Pressure.parse( 'A123' ).
|
22
|
-
should be_nil
|
14
|
+
expect(Metar::Pressure.parse( 'Q12345' )).to be_nil
|
15
|
+
expect(Metar::Pressure.parse( 'A123' )).to be_nil
|
23
16
|
end
|
24
17
|
|
25
18
|
it 'returns nil for nil' do
|
26
|
-
Metar::Pressure.parse( nil ).
|
27
|
-
should be_nil
|
19
|
+
expect(Metar::Pressure.parse( nil )).to be_nil
|
28
20
|
end
|
29
|
-
|
30
21
|
end
|
31
|
-
|
32
22
|
end
|
33
|
-
|
data/spec/unit/raw_spec.rb
CHANGED
@@ -3,6 +3,7 @@ require 'spec_helper'
|
|
3
3
|
|
4
4
|
require 'net/ftp'
|
5
5
|
require 'time'
|
6
|
+
require 'timecop'
|
6
7
|
|
7
8
|
module MetarRawTestHelper
|
8
9
|
def raw_metar
|
@@ -14,17 +15,88 @@ describe Metar::Raw::Data do
|
|
14
15
|
include MetarRawTestHelper
|
15
16
|
|
16
17
|
context 'initialization' do
|
17
|
-
let(:
|
18
|
+
let(:time) { Time.parse('2012-07-29 16:35') }
|
18
19
|
|
19
|
-
|
20
|
-
now = call_time
|
21
|
-
Time.stub(:now) { now }
|
20
|
+
subject { described_class.new(raw_metar, time) }
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
it "accepts a METAR string" do
|
23
|
+
expect(subject.metar).to eq(raw_metar)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "accepts a reading time" do
|
27
|
+
expect(subject.time).to eq(time)
|
28
|
+
end
|
29
|
+
|
30
|
+
context "when called without a time parameter" do
|
31
|
+
it "warns that the usage is deprecated" do
|
32
|
+
expect { described_class.new(raw_metar) }.to output(/deprecated/).to_stderr
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe Metar::Raw::Metar do
|
39
|
+
context "time" do
|
40
|
+
let(:call_time) { Time.parse("2016-04-01 16:35") }
|
41
|
+
let(:raw_metar) { "OPPS 312359Z 23006KT 4000 HZ SCT040 SCT100 17/12 Q1011" }
|
42
|
+
|
43
|
+
subject { described_class.new(raw_metar) }
|
44
|
+
|
45
|
+
before { Timecop.freeze(call_time) }
|
46
|
+
after { Timecop.return }
|
47
|
+
|
48
|
+
it "is the last day with the day of month from the METAR datetime" do
|
49
|
+
expect(subject.time.year).to eq(2016)
|
50
|
+
expect(subject.time.month).to eq(3)
|
51
|
+
expect(subject.time.day).to eq(31)
|
52
|
+
end
|
53
|
+
|
54
|
+
context "when the current day of month is greater than the METAR's day of month" do
|
55
|
+
let(:call_time) { Time.parse("2016-04-11 16:35") }
|
56
|
+
let(:raw_metar) { "OPPS 092359Z 23006KT 4000 HZ SCT040 SCT100 17/12 Q1011" }
|
57
|
+
|
58
|
+
it "uses the date from the current month" do
|
59
|
+
expect(subject.time.year).to eq(2016)
|
60
|
+
expect(subject.time.month).to eq(4)
|
61
|
+
expect(subject.time.day).to eq(9)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when the previous month did not have the day of the month" do
|
66
|
+
let(:call_time) { Time.parse("2016-05-01 16:35") }
|
67
|
+
|
68
|
+
it "skips back to a previous month" do
|
69
|
+
expect(subject.time.year).to eq(2016)
|
70
|
+
expect(subject.time.month).to eq(3)
|
71
|
+
expect(subject.time.day).to eq(31)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when the datetime doesn't have 6 numerals" do
|
76
|
+
let(:raw_metar) { "OPPS 3123Z 23006KT 4000 HZ SCT040 SCT100 17/12 Q1011" }
|
77
|
+
|
78
|
+
it "throws an error" do
|
79
|
+
expect { subject.time }.
|
80
|
+
to raise_error(RuntimeError, /6 digit/)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when the day of month in the datetime is > 31" do
|
85
|
+
let(:raw_metar) { "OPPS 332359Z 23006KT 4000 HZ SCT040 SCT100 17/12 Q1011" }
|
86
|
+
|
87
|
+
it "throws an error" do
|
88
|
+
expect { subject.time }.
|
89
|
+
to raise_error(RuntimeError, /at most 31/)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context "when the day of month in the datetime is 0" do
|
94
|
+
let(:raw_metar) { "OPPS 002359Z 23006KT 4000 HZ SCT040 SCT100 17/12 Q1011" }
|
95
|
+
|
96
|
+
it "throws an error" do
|
97
|
+
expect { subject.time }.
|
98
|
+
to raise_error(RuntimeError, /greater than 0/)
|
99
|
+
end
|
28
100
|
end
|
29
101
|
end
|
30
102
|
end
|
@@ -32,13 +104,16 @@ end
|
|
32
104
|
describe Metar::Raw::Noaa do
|
33
105
|
include MetarRawTestHelper
|
34
106
|
|
35
|
-
let(:
|
107
|
+
let(:cccc) { "ESSB" }
|
108
|
+
let(:ftp) do
|
109
|
+
double(Net::FTP, login: nil, chdir: nil, :passive= => nil, retrbinary: nil)
|
110
|
+
end
|
36
111
|
|
37
112
|
before do
|
38
|
-
Net::FTP.
|
113
|
+
allow(Net::FTP).to receive(:new) { ftp }
|
39
114
|
end
|
40
115
|
|
41
|
-
after
|
116
|
+
after do
|
42
117
|
Metar::Raw::Noaa.send(:class_variable_set, '@@connection', nil)
|
43
118
|
end
|
44
119
|
|
@@ -75,7 +150,7 @@ describe Metar::Raw::Noaa do
|
|
75
150
|
Metar::Raw::Noaa.connect
|
76
151
|
|
77
152
|
expect(Net::FTP).to have_received(:new)
|
78
|
-
expect(ftp).to have_received(:login).with()
|
153
|
+
expect(ftp).to have_received(:login).with(no_args)
|
79
154
|
expect(ftp).to have_received(:chdir).with('data/observations/metar/stations')
|
80
155
|
expect(ftp).to have_received(:passive=).with(true)
|
81
156
|
end
|
@@ -143,37 +218,20 @@ describe Metar::Raw::Noaa do
|
|
143
218
|
end
|
144
219
|
end
|
145
220
|
|
146
|
-
context
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
expect(raw.cccc).to eq('XXXX')
|
151
|
-
end
|
152
|
-
|
153
|
-
it 'should accept Stations' do
|
154
|
-
station = double('Metar::Station', :cccc => 'YYYY')
|
155
|
-
raw = Metar::Raw::Noaa.new(station)
|
156
|
-
|
157
|
-
expect(raw.cccc).to eq('YYYY')
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context 'lazy loading' do
|
162
|
-
let(:noaa_metar) do
|
163
|
-
raw_time = "2010/02/15 10:20"
|
164
|
-
"#{raw_time}\n#{raw_metar}"
|
165
|
-
end
|
221
|
+
context "fetching" do
|
222
|
+
let(:noaa_metar) { "#{raw_time}\n#{raw_metar}" }
|
223
|
+
let(:raw_time) { "2010/02/15 10:20" }
|
166
224
|
|
167
225
|
before do
|
168
|
-
|
226
|
+
allow(ftp).to receive(:retrbinary).and_yield(noaa_metar)
|
169
227
|
end
|
170
228
|
|
171
|
-
subject { Metar::Raw::Noaa.new(
|
229
|
+
subject { Metar::Raw::Noaa.new(cccc) }
|
172
230
|
|
173
|
-
it
|
231
|
+
it "queries for the station's data" do
|
174
232
|
subject.metar
|
175
233
|
|
176
|
-
expect(
|
234
|
+
expect(ftp).to have_received(:retrbinary).with("RETR #{cccc}.TXT", 1024)
|
177
235
|
end
|
178
236
|
|
179
237
|
it 'sets data to the returned value' do
|
@@ -181,6 +239,27 @@ describe Metar::Raw::Noaa do
|
|
181
239
|
|
182
240
|
expect(subject.data).to eq(noaa_metar)
|
183
241
|
end
|
242
|
+
|
243
|
+
context "times" do
|
244
|
+
let(:cccc) { "OPPS" }
|
245
|
+
let(:raw_time) { "2016/03/31 23:59" }
|
246
|
+
let(:raw_metar) { "OPPS 312359Z 23006KT 4000 HZ SCT040 SCT100 17/12 Q1011" }
|
247
|
+
|
248
|
+
specify "are parsed as UTC" do
|
249
|
+
expect(subject.time.zone).to eq("UTC")
|
250
|
+
end
|
251
|
+
|
252
|
+
context "across month rollover" do
|
253
|
+
let(:after_midnight) { Time.parse("2016/04/01 00:02:11 UTC") }
|
254
|
+
|
255
|
+
specify "have correct date" do
|
256
|
+
Timecop.freeze(after_midnight) do
|
257
|
+
expect(subject.time.day).to eq(31)
|
258
|
+
expect(subject.time.month).to eq(3)
|
259
|
+
expect(subject.time.year).to eq(2016)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
end
|
184
264
|
end
|
185
265
|
end
|
186
|
-
|
data/spec/unit/remark_spec.rb
CHANGED
@@ -1,20 +1,16 @@
|
|
1
|
-
|
2
|
-
load File.expand_path( '../spec_helper.rb', File.dirname(__FILE__) )
|
1
|
+
require "spec_helper"
|
3
2
|
|
4
3
|
describe Metar::Remark do
|
5
|
-
|
6
4
|
context '.parse' do
|
7
|
-
|
8
|
-
|
9
|
-
Metar::Remark.parse('21012'). should be_a(Metar::TemperatureExtreme)
|
5
|
+
it 'delegate to subclasses' do
|
6
|
+
expect(Metar::Remark.parse('21012')).to be_a(Metar::TemperatureExtreme)
|
10
7
|
end
|
11
8
|
|
12
|
-
it '
|
13
|
-
Metar::Remark.parse('FOO').
|
9
|
+
it 'returns nil for unrecognised' do
|
10
|
+
expect(Metar::Remark.parse('FOO')).to be_nil
|
14
11
|
end
|
15
12
|
|
16
13
|
context '6-hour maximum or minimum' do
|
17
|
-
|
18
14
|
[
|
19
15
|
['positive maximum', '10046', [:maximum, 4.6]],
|
20
16
|
['negative maximum', '11012', [:maximum, -1.2]],
|
@@ -22,8 +18,7 @@ describe Metar::Remark do
|
|
22
18
|
['negative minimum', '21012', [:minimum, -1.2]],
|
23
19
|
].each do |docstring, raw, expected|
|
24
20
|
example docstring do
|
25
|
-
Metar::Remark.parse(raw).
|
26
|
-
should be_temperature_extreme(*expected)
|
21
|
+
expect(Metar::Remark.parse(raw)).to be_temperature_extreme(*expected)
|
27
22
|
end
|
28
23
|
end
|
29
24
|
|
@@ -34,8 +29,8 @@ describe Metar::Remark do
|
|
34
29
|
it 'returns minimum and maximum' do
|
35
30
|
max, min = Metar::Remark.parse('400461006')
|
36
31
|
|
37
|
-
max.
|
38
|
-
min.
|
32
|
+
expect(max).to be_temperature_extreme(:maximum, 4.6)
|
33
|
+
expect(min).to be_temperature_extreme(:minimum, -0.6)
|
39
34
|
end
|
40
35
|
|
41
36
|
end
|
@@ -45,9 +40,9 @@ describe Metar::Remark do
|
|
45
40
|
it 'steady_then_decreasing' do
|
46
41
|
pt = Metar::Remark.parse('58033')
|
47
42
|
|
48
|
-
pt.
|
49
|
-
pt.character.
|
50
|
-
pt.value.
|
43
|
+
expect(pt).to be_a(Metar::PressureTendency)
|
44
|
+
expect(pt.character).to eq(:steady_then_decreasing)
|
45
|
+
expect(pt.value).to eq(3.3)
|
51
46
|
end
|
52
47
|
|
53
48
|
end
|
@@ -57,9 +52,9 @@ describe Metar::Remark do
|
|
57
52
|
it '60009' do
|
58
53
|
pr = Metar::Remark.parse('60009')
|
59
54
|
|
60
|
-
pr.
|
61
|
-
pr.period.
|
62
|
-
pr.amount.value.
|
55
|
+
expect(pr).to be_a(Metar::Precipitation)
|
56
|
+
expect(pr.period).to eq(3)
|
57
|
+
expect(pr.amount.value).to eq(0.002286)
|
63
58
|
end
|
64
59
|
|
65
60
|
end
|
@@ -69,9 +64,9 @@ describe Metar::Remark do
|
|
69
64
|
it '70015' do
|
70
65
|
pr = Metar::Remark.parse('70015')
|
71
66
|
|
72
|
-
pr.
|
73
|
-
pr.period.
|
74
|
-
pr.amount.value.
|
67
|
+
expect(pr).to be_a(Metar::Precipitation)
|
68
|
+
expect(pr.period).to eq(24)
|
69
|
+
expect(pr.amount.value).to eq(0.003810)
|
75
70
|
end
|
76
71
|
|
77
72
|
end
|
@@ -85,8 +80,8 @@ describe Metar::Remark do
|
|
85
80
|
example docstring do
|
86
81
|
aut = Metar::Remark.parse(raw)
|
87
82
|
|
88
|
-
aut.
|
89
|
-
aut.type.
|
83
|
+
expect(aut).to be_a(expected[0])
|
84
|
+
expect(aut.type).to eq(expected[1])
|
90
85
|
end
|
91
86
|
end
|
92
87
|
|
@@ -97,8 +92,8 @@ describe Metar::Remark do
|
|
97
92
|
it 'SLP125' do
|
98
93
|
slp = Metar::Remark.parse('SLP125')
|
99
94
|
|
100
|
-
slp.
|
101
|
-
slp.pressure.value.
|
95
|
+
expect(slp).to be_a(Metar::SeaLevelPressure)
|
96
|
+
expect(slp.pressure.value).to eq(0.0125)
|
102
97
|
end
|
103
98
|
|
104
99
|
end
|
@@ -108,9 +103,9 @@ describe Metar::Remark do
|
|
108
103
|
it 'T00640036' do
|
109
104
|
htm = Metar::Remark.parse('T00641036')
|
110
105
|
|
111
|
-
htm.
|
112
|
-
htm.temperature.value.
|
113
|
-
htm.dew_point.value.
|
106
|
+
expect(htm).to be_a(Metar::HourlyTemperaturAndDewPoint)
|
107
|
+
expect(htm.temperature.value).to eq(6.4)
|
108
|
+
expect(htm.dew_point.value).to eq(-3.6)
|
114
109
|
end
|
115
110
|
|
116
111
|
end
|
@@ -134,37 +129,37 @@ describe Metar::Lightning do
|
|
134
129
|
chunks = section.split(' ')
|
135
130
|
r = Metar::Lightning.parse_chunks(chunks)
|
136
131
|
|
137
|
-
r.
|
138
|
-
r.type.
|
132
|
+
expect(r).to be_a(Metar::Lightning)
|
133
|
+
expect(r.type).to eq(expected[0])
|
139
134
|
if expected[1]
|
140
|
-
r.distance.value.
|
135
|
+
expect(r.distance.value).to eq(expected[1])
|
141
136
|
else
|
142
|
-
r.distance.
|
137
|
+
expect(r.distance).to be_nil
|
143
138
|
end
|
144
|
-
r.directions.
|
139
|
+
expect(r.directions).to eq(expected[2])
|
145
140
|
end
|
146
141
|
end
|
147
142
|
|
148
|
-
it '
|
143
|
+
it 'removes parsed chunks' do
|
149
144
|
chunks = ['LTG', 'DSNT', 'SE', 'FOO']
|
150
145
|
|
151
146
|
r = Metar::Lightning.parse_chunks(chunks)
|
152
147
|
|
153
|
-
chunks.
|
148
|
+
expect(chunks).to eq(['FOO'])
|
154
149
|
end
|
155
150
|
|
156
|
-
it '
|
151
|
+
it 'fails if the first chunk is not LTGnnn' do
|
157
152
|
expect do
|
158
153
|
Metar::Lightning.parse_chunks(['FOO'])
|
159
154
|
end. to raise_error(RuntimeError, /not lightning/)
|
160
155
|
end
|
161
156
|
|
162
|
-
it '
|
157
|
+
it "doesn't not fail if all chunks are parsed" do
|
163
158
|
chunks = ['LTG', 'DSNT', 'SE']
|
164
159
|
|
165
160
|
r = Metar::Lightning.parse_chunks(chunks)
|
166
161
|
|
167
|
-
chunks.
|
162
|
+
expect(chunks).to eq([])
|
168
163
|
end
|
169
164
|
|
170
165
|
end
|
data/spec/unit/report_spec.rb
CHANGED
@@ -1,44 +1,32 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
-
|
2
|
+
require "spec_helper"
|
3
3
|
|
4
4
|
describe Metar::Report do
|
5
|
-
|
6
|
-
context 'initialization' do
|
7
|
-
|
8
|
-
it 'loads the Station' do
|
9
|
-
station = stub( 'station' )
|
10
|
-
parser = stub( 'parser', :station_code => 'SSSS' )
|
11
|
-
|
12
|
-
Metar::Station. should_receive( :find_by_cccc ).
|
13
|
-
with( 'SSSS' ).
|
14
|
-
and_return( station )
|
15
|
-
|
16
|
-
Metar::Report.new( parser )
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
5
|
context 'attributes' do
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
6
|
+
let(:parser) do
|
7
|
+
double(
|
8
|
+
Metar::Parser,
|
9
|
+
:station_code => station_code,
|
10
|
+
:date => Date.parse(metar_date),
|
11
|
+
:time => Time.parse(metar_datetime),
|
12
|
+
:observer => :real
|
13
|
+
)
|
14
|
+
end
|
15
|
+
let(:station_code) { "SSSS" }
|
16
|
+
let(:locale) { I18n.locale }
|
17
|
+
let(:metar_date) { "2008/05/06" }
|
18
|
+
let(:metar_time) { "10:56" }
|
19
|
+
let(:metar_datetime) { "#{metar_date} #{metar_time}" }
|
20
|
+
let(:station) { double(Metar::Station, :name => 'Airport 1', :country => 'Wwwwww') }
|
21
|
+
|
22
|
+
before do
|
23
|
+
allow(Metar::Station).to receive(:find_by_cccc).with(station_code) { station }
|
36
24
|
end
|
37
25
|
|
38
|
-
subject {
|
26
|
+
subject { described_class.new(parser) }
|
39
27
|
|
40
28
|
after :each do
|
41
|
-
I18n.locale =
|
29
|
+
I18n.locale = locale
|
42
30
|
end
|
43
31
|
|
44
32
|
context '#date' do
|
@@ -48,30 +36,42 @@ describe Metar::Report do
|
|
48
36
|
end
|
49
37
|
|
50
38
|
context '#time' do
|
51
|
-
|
39
|
+
it "is equal to the METAR time" do
|
40
|
+
expect(subject.time).to eq(metar_time)
|
41
|
+
end
|
52
42
|
|
53
43
|
it 'zero-pads single figure minutes' do
|
54
|
-
|
44
|
+
allow(parser).to receive(:time) { Time.parse('10:02') }
|
55
45
|
|
56
46
|
expect(subject.time).to eq('10:02')
|
57
47
|
end
|
58
48
|
end
|
59
49
|
|
60
50
|
context '#observer' do
|
61
|
-
|
51
|
+
it "returns the observer" do
|
52
|
+
expect(subject.observer).to eq('real')
|
53
|
+
end
|
62
54
|
end
|
63
55
|
|
64
|
-
|
65
|
-
|
56
|
+
context "#station_name" do
|
57
|
+
it "returns the name" do
|
58
|
+
expect(subject.station_name).to eq('Airport 1')
|
59
|
+
end
|
60
|
+
end
|
66
61
|
|
67
|
-
|
68
|
-
|
62
|
+
context "#station_country" do
|
63
|
+
it "returns the country" do
|
64
|
+
expect(subject.station_country).to eq('Wwwwww')
|
65
|
+
end
|
66
|
+
end
|
69
67
|
|
70
|
-
|
71
|
-
|
68
|
+
context "#station_code" do
|
69
|
+
it "returns the station code" do
|
70
|
+
expect(subject.station_code).to eq(station_code)
|
71
|
+
end
|
72
|
+
end
|
72
73
|
|
73
74
|
context 'proxied from parser' do
|
74
|
-
|
75
75
|
context 'singly' do
|
76
76
|
[
|
77
77
|
:wind,
|
@@ -84,94 +84,86 @@ describe Metar::Report do
|
|
84
84
|
:sea_level_pressure,
|
85
85
|
].each do | attribute |
|
86
86
|
example attribute do
|
87
|
-
|
88
|
-
@parser.stub!( attribute => @attr )
|
87
|
+
allow(parser).to receive(attribute) { attribute.to_s }
|
89
88
|
|
90
|
-
|
91
|
-
|
92
|
-
subject.send( attribute )
|
89
|
+
expect(subject.send(attribute)).to eq(attribute.to_s)
|
93
90
|
end
|
94
91
|
end
|
95
92
|
|
96
|
-
context
|
97
|
-
|
98
|
-
it 'returns the summary' do
|
99
|
-
@skies1 = stub('sky_conditions')
|
100
|
-
@parser.stub!( :sky_conditions => [@skies1] )
|
93
|
+
context "#sky_summary" do
|
94
|
+
let(:conditions1) { double(:to_summary => "skies1") }
|
101
95
|
|
102
|
-
|
103
|
-
|
96
|
+
it "returns the summary" do
|
97
|
+
allow(parser).to receive(:sky_conditions) { [conditions1] }
|
104
98
|
|
105
|
-
subject.sky_summary.
|
99
|
+
expect(subject.sky_summary).to eq("skies1")
|
106
100
|
end
|
107
101
|
|
108
|
-
it
|
109
|
-
|
102
|
+
it "clear skies when missing" do
|
103
|
+
allow(parser).to receive(:sky_conditions) { [] }
|
110
104
|
|
111
|
-
subject.sky_summary.
|
105
|
+
expect(subject.sky_summary).to eq("clear skies")
|
112
106
|
end
|
113
107
|
|
114
|
-
it
|
115
|
-
@skies1 =
|
116
|
-
@skies2 =
|
117
|
-
|
108
|
+
it "uses the last, if there is more than 1" do
|
109
|
+
@skies1 = double("sky_conditions1")
|
110
|
+
@skies2 = double("sky_conditions2", :to_summary => "skies2")
|
111
|
+
allow(parser).to receive(:sky_conditions) { [@skies1, @skies2] }
|
118
112
|
|
119
|
-
|
120
|
-
and_return( 'skies2' )
|
121
|
-
|
122
|
-
subject.sky_summary. should == 'skies2'
|
113
|
+
expect(subject.sky_summary).to eq("skies2")
|
123
114
|
end
|
124
115
|
end
|
125
116
|
end
|
126
117
|
|
127
|
-
context
|
128
|
-
|
129
|
-
|
130
|
-
@
|
131
|
-
|
132
|
-
@parser.stub!( :runway_visible_range => [ @rvr1, @rvr2 ] )
|
118
|
+
context "joined" do
|
119
|
+
it "#runway_visible_range" do
|
120
|
+
@rvr1 = double("rvr1", :to_s => "rvr1")
|
121
|
+
@rvr2 = double("rvr2", :to_s => "rvr2")
|
122
|
+
allow(parser).to receive(:runway_visible_range) { [@rvr1, @rvr2] }
|
133
123
|
|
134
|
-
subject.runway_visible_range.
|
135
|
-
should == 'rvr1, rvr2'
|
124
|
+
expect(subject.runway_visible_range).to eq("rvr1, rvr2")
|
136
125
|
end
|
137
126
|
|
138
|
-
it
|
139
|
-
|
127
|
+
it "#present_weather" do
|
128
|
+
allow(parser).to receive(:present_weather) { ["pw1", "pw2"] }
|
140
129
|
|
141
|
-
subject.present_weather.
|
130
|
+
expect(subject.present_weather).to eq("pw1, pw2")
|
142
131
|
end
|
143
132
|
|
144
|
-
it
|
145
|
-
|
133
|
+
it "#remarks" do
|
134
|
+
allow(parser).to receive(:remarks) { ["rem1", "rem2"] }
|
146
135
|
|
147
|
-
subject.remarks.
|
136
|
+
expect(subject.remarks).to eq("rem1, rem2")
|
148
137
|
end
|
149
138
|
|
150
139
|
it '#sky_conditions' do
|
151
|
-
sky1 =
|
152
|
-
sky2 =
|
153
|
-
|
140
|
+
sky1 = double('sky1', :to_s => 'sky1')
|
141
|
+
sky2 = double('sky2', :to_s => 'sky2')
|
142
|
+
allow(parser).to receive(:sky_conditions) { [sky1, sky2] }
|
154
143
|
|
155
|
-
subject.sky_conditions.
|
144
|
+
expect(subject.sky_conditions).to eq("sky1, sky2")
|
156
145
|
end
|
157
|
-
|
158
146
|
end
|
159
|
-
|
160
147
|
end
|
161
148
|
|
162
|
-
|
163
|
-
sky1
|
164
|
-
sky2
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
149
|
+
context '#to_s' do
|
150
|
+
let(:sky1) { double('sky1', :to_summary => 'sky1') }
|
151
|
+
let(:sky2) { double('sky2', :to_summary => 'sky2') }
|
152
|
+
|
153
|
+
before do
|
154
|
+
allow(parser).to receive(:wind) { "wind" }
|
155
|
+
allow(parser).to receive(:visibility) { "visibility" }
|
156
|
+
allow(parser).to receive(:minimum_visibility) { "min visibility" }
|
157
|
+
allow(parser).to receive(:present_weather) { ["pw"] }
|
158
|
+
allow(parser).to receive(:sky_conditions) { [sky1, sky2] }
|
159
|
+
allow(parser).to receive(:temperature) { "temp" }
|
160
|
+
end
|
161
|
+
|
162
|
+
it "returns the full report" do
|
163
|
+
expected = <<EOT
|
172
164
|
name: Airport 1
|
173
165
|
country: Wwwwww
|
174
|
-
time: #{
|
166
|
+
time: #{metar_time}
|
175
167
|
wind: wind
|
176
168
|
visibility: visibility
|
177
169
|
minimum visibility: min visibility
|
@@ -179,10 +171,8 @@ weather: pw
|
|
179
171
|
sky: sky2
|
180
172
|
temperature: temp
|
181
173
|
EOT
|
182
|
-
|
174
|
+
expect(subject.to_s).to eq(expected)
|
175
|
+
end
|
183
176
|
end
|
184
|
-
|
185
177
|
end
|
186
|
-
|
187
178
|
end
|
188
|
-
|