rmuh 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +33 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +19 -0
- data/Rakefile +15 -0
- data/lib/rmuh.rb +22 -0
- data/lib/rmuh/rpt/log/fetch.rb +56 -0
- data/lib/rmuh/rpt/log/parsers/base.rb +29 -0
- data/lib/rmuh/rpt/log/parsers/unitedoperationslog.rb +94 -0
- data/lib/rmuh/rpt/log/parsers/unitedoperationsrpt.rb +65 -0
- data/lib/rmuh/rpt/log/util/unitedoperations.rb +127 -0
- data/lib/rmuh/rpt/log/util/unitedoperationslog.rb +26 -0
- data/lib/rmuh/rpt/log/util/unitedoperationsrpt.rb +37 -0
- data/lib/rmuh/serverstats/base.rb +55 -0
- data/lib/rmuh/version.rb +10 -0
- data/rmuh.gemspec +33 -0
- data/spec/files/content-length.txt +1 -0
- data/spec/helpers/spec_helper.rb +13 -0
- data/spec/helpers/unitedoperations.rb +106 -0
- data/spec/rmuh_rpt_log_fetch_spec.rb +112 -0
- data/spec/rmuh_rpt_log_parsers_base_spec.rb +57 -0
- data/spec/rmuh_rpt_log_parsers_unitedoperationslog_spec.rb +390 -0
- data/spec/rmuh_rpt_log_parsers_unitedoperationsrpt_spec.rb +252 -0
- data/spec/rmuh_rpt_log_util_unitedoperations_spec.rb +473 -0
- data/spec/rmuh_rpt_log_util_unitedoperationslog_spec.rb +66 -0
- data/spec/rmuh_rpt_log_util_unitedoperationsrpt_spec.rb +122 -0
- data/spec/rmuh_rpt_spec.rb +45 -0
- data/spec/rmuh_serverstats_base_spec.rb +190 -0
- metadata +225 -0
@@ -0,0 +1,390 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
require 'stringio'
|
3
|
+
require 'rspec'
|
4
|
+
require 'tzinfo'
|
5
|
+
require 'helpers/spec_helper'
|
6
|
+
require File.join(repo_root, 'lib/rmuh/rpt/log/util/unitedoperations')
|
7
|
+
require File.join(repo_root, 'lib/rmuh/rpt/log/util/unitedoperationslog')
|
8
|
+
require File.join(repo_root, 'lib/rmuh/rpt/log/parsers/unitedoperationslog')
|
9
|
+
|
10
|
+
describe RMuh::RPT::Log::Parsers::UnitedOperationsLog do
|
11
|
+
let(:uolog) { RMuh::RPT::Log::Parsers::UnitedOperationsLog.new }
|
12
|
+
|
13
|
+
context '::validate_opts' do
|
14
|
+
it 'should take no more than one arg' do
|
15
|
+
expect do
|
16
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsLog.validate_opts(nil, nil)
|
17
|
+
end.to raise_error ArgumentError
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should take no less than one arg' do
|
21
|
+
expect do
|
22
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsLog.validate_opts
|
23
|
+
end.to raise_error ArgumentError
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should return nil if arg 1 is a Hash' do
|
27
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsLog.validate_opts({})
|
28
|
+
.should be_nil
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'should fail if to_zulu is not boolean' do
|
32
|
+
expect do
|
33
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsLog.validate_opts(to_zulu: {})
|
34
|
+
end.to raise_error ArgumentError
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should fail if timezone is not TZInfo::DataTimezone' do
|
38
|
+
expect do
|
39
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsLog
|
40
|
+
.validate_opts(timezone: {})
|
41
|
+
end.to raise_error ArgumentError
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should fail if chat is not boolean' do
|
45
|
+
expect do
|
46
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsLog.validate_opts(chat: {})
|
47
|
+
end.to raise_error ArgumentError
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context '::new' do
|
52
|
+
it 'should not take more than one arg' do
|
53
|
+
expect do
|
54
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsLog.new(nil, nil)
|
55
|
+
end.to raise_error ArgumentError
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should fail if arg 1 is not a Hash' do
|
59
|
+
expect do
|
60
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsLog.new(nil)
|
61
|
+
end.to raise_error ArgumentError
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should return an instance of UnitedOperationsLog' do
|
65
|
+
u = RMuh::RPT::Log::Parsers::UnitedOperationsLog.new
|
66
|
+
u.should be_an_instance_of RMuh::RPT::Log::Parsers::UnitedOperationsLog
|
67
|
+
end
|
68
|
+
|
69
|
+
it 'should not include chat by default' do
|
70
|
+
u = uolog.instance_variable_get(:@include_chat)
|
71
|
+
u.should be_false
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should convert to zulu by default' do
|
75
|
+
u = uolog.instance_variable_get(:@to_zulu)
|
76
|
+
u.should be_true
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should use the UO timezone by default' do
|
80
|
+
t = RMuh::RPT::Log::Util::UnitedOperations::UO_TZ
|
81
|
+
u = uolog.instance_variable_get(:@timezone)
|
82
|
+
u.should eql t
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should not include chat if passed as false' do
|
86
|
+
u = RMuh::RPT::Log::Parsers::UnitedOperationsLog.new(chat: false)
|
87
|
+
u.instance_variable_get(:@include_chat).should eql false
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should include chat if passed as true' do
|
91
|
+
u = RMuh::RPT::Log::Parsers::UnitedOperationsLog.new(chat: true)
|
92
|
+
u.instance_variable_get(:@include_chat).should eql true
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should not convert to zulu if passed as false' do
|
96
|
+
u = RMuh::RPT::Log::Parsers::UnitedOperationsLog.new(to_zulu: false)
|
97
|
+
u.instance_variable_get(:@to_zulu).should eql false
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'should convert to zulu if passed as true' do
|
101
|
+
u = RMuh::RPT::Log::Parsers::UnitedOperationsLog.new(to_zulu: true)
|
102
|
+
u.instance_variable_get(:@to_zulu).should eql true
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should specify a custom timezone if passed in' do
|
106
|
+
t = TZInfo::Timezone.get('Etc/UTC')
|
107
|
+
u = RMuh::RPT::Log::Parsers::UnitedOperationsLog.new(timezone: t)
|
108
|
+
u.instance_variable_get(:@timezone).should eql t
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context '#date_of_line_based_on_now' do
|
113
|
+
it 'should take no more than one arg' do
|
114
|
+
expect do
|
115
|
+
uolog.send(:date_of_line_based_on_now, nil, nil)
|
116
|
+
end.to raise_error ArgumentError
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'should return today if it is between 0400 and 2359' do
|
120
|
+
tz = RMuh::RPT::Log::Util::UnitedOperations::UO_TZ
|
121
|
+
t = Time.new(2014, 1, 1, 4, 0, 0)
|
122
|
+
uolog.send(:date_of_line_based_on_now, t).to_s.should eql tz.now.to_s
|
123
|
+
t = Time.new(2014, 1, 1, 23, 59, 59)
|
124
|
+
uolog.send(:date_of_line_based_on_now, t).to_s.should eql tz.now.to_s
|
125
|
+
t = Time.new(2014, 1, 1, 0, 0, 0)
|
126
|
+
uolog.send(:date_of_line_based_on_now, t).to_s.should_not eql tz.now.to_s
|
127
|
+
end
|
128
|
+
|
129
|
+
it 'should return yesterday if it is between 0000 and 0359' do
|
130
|
+
tz = RMuh::RPT::Log::Util::UnitedOperations::UO_TZ
|
131
|
+
d = RMuh::RPT::Log::Util::UnitedOperationsLog::ONE_DAY
|
132
|
+
t = Time.new(2014, 1, 1, 0, 0, 0)
|
133
|
+
uolog.send(:date_of_line_based_on_now, t)
|
134
|
+
.to_s.should(eql((tz.now - d).to_s))
|
135
|
+
t = Time.new(2014, 1, 1, 3, 59, 59)
|
136
|
+
uolog.send(:date_of_line_based_on_now, t)
|
137
|
+
.to_s.should(eql((tz.now - d).to_s))
|
138
|
+
t = Time.new(2014, 1, 1, 4, 0, 0)
|
139
|
+
uolog.send(:date_of_line_based_on_now, t)
|
140
|
+
.to_s.should_not(eql((tz.now - d).to_s))
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context '#set_line_date!' do
|
145
|
+
it 'should not take more than two args' do
|
146
|
+
expect do
|
147
|
+
uolog.send(:set_line_date!, nil, nil, nil)
|
148
|
+
end.to raise_error ArgumentError
|
149
|
+
end
|
150
|
+
|
151
|
+
it 'should not take less than one arg' do
|
152
|
+
expect do
|
153
|
+
uolog.send(:set_line_date!)
|
154
|
+
end.to raise_error ArgumentError
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should set the line's year to this year" do
|
158
|
+
tz = uolog.instance_variable_get(:@timezone)
|
159
|
+
l = {}
|
160
|
+
uolog.send(:set_line_date!, l)
|
161
|
+
l[:year].should eql tz.now.year
|
162
|
+
end
|
163
|
+
|
164
|
+
it "should set the line's month to this month" do
|
165
|
+
tz = uolog.instance_variable_get(:@timezone)
|
166
|
+
l = {}
|
167
|
+
uolog.send(:set_line_date!, l)
|
168
|
+
l[:month].should eql tz.now.month
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should set the line's date to this day" do
|
172
|
+
tz = uolog.instance_variable_get(:@timezone)
|
173
|
+
l = {}
|
174
|
+
uolog.send(:set_line_date!, l)
|
175
|
+
l[:day].should eql tz.now.day
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
context '#when_am_i!' do
|
180
|
+
let(:yday_line) { { hour: 4, min: 0, sec: 0 } }
|
181
|
+
let(:today_line) { { hour: 0, min: 0, sec: 0 } }
|
182
|
+
|
183
|
+
it 'should take no more than one arg' do
|
184
|
+
expect do
|
185
|
+
uolog.send(:when_am_i!, nil, nil)
|
186
|
+
end.to raise_error ArgumentError
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'should take no less than one arg' do
|
190
|
+
expect do
|
191
|
+
uolog.send(:when_am_i!)
|
192
|
+
end.to raise_error ArgumentError
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'should set date as today if line (0400-2359) and now same range ' do
|
196
|
+
tz = uolog.instance_variable_get(:@timezone)
|
197
|
+
l = yday_line.dup
|
198
|
+
uolog.stub(:date_of_line_based_on_now) { tz.now }
|
199
|
+
uolog.send(:when_am_i!, l)
|
200
|
+
l[:year].should eql tz.now.year
|
201
|
+
l[:month].should eql tz.now.month
|
202
|
+
l[:day].should eql tz.now.day
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should set the date as yday if line (0400-2359) now not same range' do
|
206
|
+
d = RMuh::RPT::Log::Util::UnitedOperationsLog::ONE_DAY
|
207
|
+
tz = uolog.instance_variable_get(:@timezone)
|
208
|
+
l = yday_line.dup
|
209
|
+
uolog.stub(:date_of_line_based_on_now) { tz.now - d }
|
210
|
+
uolog.send(:when_am_i!, l)
|
211
|
+
l[:year].should(eql((tz.now - d).year))
|
212
|
+
l[:month].should(eql((tz.now - d).month))
|
213
|
+
l[:day].should(eql((tz.now - d).day))
|
214
|
+
end
|
215
|
+
|
216
|
+
it 'should set the date as today if time between 0000 and 0359' do
|
217
|
+
tz = uolog.instance_variable_get(:@timezone)
|
218
|
+
l = today_line.dup
|
219
|
+
uolog.send(:when_am_i!, l)
|
220
|
+
l[:year].should eql tz.now.year
|
221
|
+
l[:month].should eql tz.now.month
|
222
|
+
l[:day].should eql tz.now.day
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
context '#line_modifiers' do
|
227
|
+
it 'should take no more than one arg' do
|
228
|
+
expect do
|
229
|
+
uolog.send(:line_modifiers, nil, nil)
|
230
|
+
end.to raise_error ArgumentError
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'should take no less than one arg' do
|
234
|
+
expect do
|
235
|
+
uolog.send(:line_modifiers)
|
236
|
+
end.to raise_error ArgumentError
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'should call where_am_i! and set the year/month/day' do
|
240
|
+
l = { hour: 4, min: 0, sec: 0 }
|
241
|
+
x = uolog.send(:line_modifiers, l)
|
242
|
+
x.key?(:year).should be_true
|
243
|
+
x.key?(:month).should be_true
|
244
|
+
x.key?(:day).should be_true
|
245
|
+
end
|
246
|
+
|
247
|
+
it 'sould call zulu! and set the time to zulu' do
|
248
|
+
l = { hour: 4, min: 0, sec: 0 }
|
249
|
+
x = uolog.send(:line_modifiers, l)
|
250
|
+
x.key?(:iso8601).should be_true
|
251
|
+
x.key?(:dtg).should be_true
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'should call add_guid! and add the event_guid' do
|
255
|
+
l = { hour: 4, min: 0, sec: 0 }
|
256
|
+
x = uolog.send(:line_modifiers, l)
|
257
|
+
x.key?(:event_guid).should be_true
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
context '#regex_matches' do
|
262
|
+
let(:uolog) do
|
263
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsLog.new(chat: true)
|
264
|
+
end
|
265
|
+
let(:guid_line) do
|
266
|
+
' 4:01:51 BattlEye Server: Verified GUID (a0fbee2a02992c8cafabe67e0675' \
|
267
|
+
'cea7) of player #0 stebbi92 '
|
268
|
+
end
|
269
|
+
let(:chat_line) do
|
270
|
+
"6:58:25 BattlEye Server: (Side) Major Lee Payne: I'm up, " \
|
271
|
+
"radio doesn't work"
|
272
|
+
end
|
273
|
+
let(:loglines) { StringIO.new("#{guid_line}\n#{chat_line}\n") }
|
274
|
+
|
275
|
+
it 'should take no more than one arg' do
|
276
|
+
expect do
|
277
|
+
uolog.send(:regex_matches, nil, nil)
|
278
|
+
end.to raise_error ArgumentError
|
279
|
+
end
|
280
|
+
|
281
|
+
it 'should take no less than one arg' do
|
282
|
+
expect do
|
283
|
+
uolog.send(:regex_matches)
|
284
|
+
end.to raise_error ArgumentError
|
285
|
+
end
|
286
|
+
|
287
|
+
it 'should return an Array' do
|
288
|
+
uolog.send(:regex_matches, StringIO.new).should be_an_instance_of Array
|
289
|
+
end
|
290
|
+
|
291
|
+
it 'should iterate over multiple log lines' do
|
292
|
+
x = uolog.send(:regex_matches, loglines)
|
293
|
+
x.should be_an_instance_of Array
|
294
|
+
x.length.should eql 2
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'should properly match a guid line' do
|
298
|
+
x = uolog.send(:regex_matches, StringIO.new(guid_line))
|
299
|
+
x[0][:type].should eql :beguid
|
300
|
+
end
|
301
|
+
|
302
|
+
it 'should properly match a chat line' do
|
303
|
+
x = uolog.send(:regex_matches, StringIO.new(chat_line))
|
304
|
+
x[0][:type].should eql :chat
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'should not match a chat line if chat matching is disabled' do
|
308
|
+
u = RMuh::RPT::Log::Parsers::UnitedOperationsLog.new
|
309
|
+
u.send(:regex_matches, StringIO.new(chat_line)).empty?.should be_true
|
310
|
+
end
|
311
|
+
|
312
|
+
it 'should compact the Array' do
|
313
|
+
l = StringIO.new("Something1\nSomething2\n")
|
314
|
+
x = uolog.send(:regex_matches, l)
|
315
|
+
x.include?(nil).should be_false
|
316
|
+
end
|
317
|
+
|
318
|
+
it 'should call #line_modifiers' do
|
319
|
+
x = uolog.send(:regex_matches, StringIO.new(guid_line))
|
320
|
+
x[0].key?(:year).should be_true
|
321
|
+
x[0].key?(:month).should be_true
|
322
|
+
x[0].key?(:day).should be_true
|
323
|
+
x[0].key?(:iso8601).should be_true
|
324
|
+
x[0].key?(:dtg).should be_true
|
325
|
+
x[0].key?(:event_guid).should be_true
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
context '#parse' do
|
330
|
+
let(:guid_line) do
|
331
|
+
' 4:01:51 BattlEye Server: Verified GUID (a0fbee2a02992c8cafabe67e0675' \
|
332
|
+
'cea7) of player #0 stebbi92 '
|
333
|
+
end
|
334
|
+
|
335
|
+
it 'should take no more than one arg' do
|
336
|
+
expect { uolog.parse(nil, nil) }.to raise_error ArgumentError
|
337
|
+
end
|
338
|
+
|
339
|
+
it 'should take no less than one arg' do
|
340
|
+
expect { uolog.parse }.to raise_error ArgumentError
|
341
|
+
end
|
342
|
+
|
343
|
+
it 'should not fail if arg1 is a StringIO object' do
|
344
|
+
expect { uolog.parse(StringIO.new) }.not_to raise_error
|
345
|
+
end
|
346
|
+
|
347
|
+
it 'should fail if arg1 is a String' do
|
348
|
+
expect { uolog.parse('') }.to raise_error ArgumentError
|
349
|
+
end
|
350
|
+
|
351
|
+
it 'should fail if arg1 is a Symbol' do
|
352
|
+
expect { uolog.parse(:x) }.to raise_error ArgumentError
|
353
|
+
end
|
354
|
+
|
355
|
+
it 'should fail if arg1 is a Fixnum' do
|
356
|
+
expect { uolog.parse(0) }.to raise_error ArgumentError
|
357
|
+
end
|
358
|
+
|
359
|
+
it 'should fail if arg1 is a Float' do
|
360
|
+
expect { uolog.parse(0.0) }.to raise_error ArgumentError
|
361
|
+
end
|
362
|
+
|
363
|
+
it 'should fail if arg1 is a Array' do
|
364
|
+
expect { uolog.parse([]) }.to raise_error ArgumentError
|
365
|
+
end
|
366
|
+
|
367
|
+
it 'should fail if arg1 is a Hash' do
|
368
|
+
expect { uolog.parse({}) }.to raise_error ArgumentError
|
369
|
+
end
|
370
|
+
|
371
|
+
it 'should fail if arg1 is nil' do
|
372
|
+
expect { uolog.parse(nil) }.to raise_error ArgumentError
|
373
|
+
end
|
374
|
+
|
375
|
+
it 'should return an Array' do
|
376
|
+
uolog.parse(StringIO.new).should be_an_instance_of Array
|
377
|
+
end
|
378
|
+
|
379
|
+
it 'should call #regex_matches' do
|
380
|
+
x = uolog.parse(StringIO.new(guid_line))
|
381
|
+
x[0].key?(:type).should be_true
|
382
|
+
x[0].key?(:year).should be_true
|
383
|
+
x[0].key?(:month).should be_true
|
384
|
+
x[0].key?(:day).should be_true
|
385
|
+
x[0].key?(:iso8601).should be_true
|
386
|
+
x[0].key?(:dtg).should be_true
|
387
|
+
x[0].key?(:event_guid).should be_true
|
388
|
+
end
|
389
|
+
end
|
390
|
+
end
|
@@ -0,0 +1,252 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
require 'stringio'
|
3
|
+
require 'rspec'
|
4
|
+
require 'helpers/spec_helper'
|
5
|
+
require File.join(repo_root, 'lib/rmuh/rpt/log/parsers/unitedoperationsrpt')
|
6
|
+
|
7
|
+
describe RMuh::RPT::Log::Parsers::UnitedOperationsRPT do
|
8
|
+
let(:uorpt) { RMuh::RPT::Log::Parsers::UnitedOperationsRPT.new }
|
9
|
+
|
10
|
+
context '::validate_opts' do
|
11
|
+
it 'should not take more than one arg' do
|
12
|
+
expect do
|
13
|
+
uorpt.send(:regex_match, nil, nil)
|
14
|
+
end.to raise_error ArgumentError
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'should not take less than one arg' do
|
18
|
+
expect do
|
19
|
+
uorpt.send(:regex_match)
|
20
|
+
end.to raise_error ArgumentError
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should not fail if arg 1 is a Hash' do
|
24
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT
|
25
|
+
.validate_opts({}).should be_nil
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should fail if arg 1 is an Array' do
|
29
|
+
expect do
|
30
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.validate_opts([])
|
31
|
+
end.to raise_error ArgumentError
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should fail if arg 1 is a String' do
|
35
|
+
expect do
|
36
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.validate_opts('')
|
37
|
+
end.to raise_error ArgumentError
|
38
|
+
end
|
39
|
+
|
40
|
+
it 'should fail if arg 1 is a Regexp' do
|
41
|
+
expect do
|
42
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.validate_opts(//)
|
43
|
+
end.to raise_error ArgumentError
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should fail if arg 1 is a Fixnum' do
|
47
|
+
expect do
|
48
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.validate_opts(0)
|
49
|
+
end.to raise_error ArgumentError
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should fail if arg 1 is a Float' do
|
53
|
+
expect do
|
54
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.validate_opts(0.0)
|
55
|
+
end.to raise_error ArgumentError
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'should fail if arg 1 is false' do
|
59
|
+
expect do
|
60
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.validate_opts(false)
|
61
|
+
end.to raise_error ArgumentError
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should fail if arg 1 is true' do
|
65
|
+
expect do
|
66
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.validate_opts(true)
|
67
|
+
end.to raise_error ArgumentError
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'should fail if arg 1 is nil' do
|
71
|
+
expect do
|
72
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.validate_opts(nil)
|
73
|
+
end.to raise_error ArgumentError
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context '::new' do
|
78
|
+
it 'should not take more than one argument' do
|
79
|
+
expect do
|
80
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.new(nil, nil)
|
81
|
+
end.to raise_error ArgumentError
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'should not fail if arg 1 is a hash' do
|
85
|
+
expect do
|
86
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.new
|
87
|
+
end.not_to raise_error
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should fail if arg 1 is an Array' do
|
91
|
+
expect do
|
92
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.new([])
|
93
|
+
end.to raise_error ArgumentError
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'should fail if arg 1 is a String' do
|
97
|
+
expect do
|
98
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.new('')
|
99
|
+
end.to raise_error ArgumentError
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should fail if arg 1 is a Regexp' do
|
103
|
+
expect do
|
104
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.new(//)
|
105
|
+
end.to raise_error ArgumentError
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should fail if arg 1 is a Fixnum' do
|
109
|
+
expect do
|
110
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.new(0)
|
111
|
+
end.to raise_error ArgumentError
|
112
|
+
end
|
113
|
+
|
114
|
+
it 'should fail if arg 1 is a Float' do
|
115
|
+
expect do
|
116
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.new(0.0)
|
117
|
+
end.to raise_error ArgumentError
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should fail if arg 1 is false' do
|
121
|
+
expect do
|
122
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.new(false)
|
123
|
+
end.to raise_error ArgumentError
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should fail if arg 1 is true' do
|
127
|
+
expect do
|
128
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.new(true)
|
129
|
+
end.to raise_error ArgumentError
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should fail if arg 1 is nil' do
|
133
|
+
expect do
|
134
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT.new(nil)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should return an instance of itself' do
|
139
|
+
uorpt.should be_an_instance_of(
|
140
|
+
RMuh::RPT::Log::Parsers::UnitedOperationsRPT
|
141
|
+
)
|
142
|
+
end
|
143
|
+
|
144
|
+
it 'should set @to_zulu to true if nothing provided' do
|
145
|
+
uorpt.instance_variable_get(:@to_zulu).should be_true
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should set @timezone to America/Los_Angeles if nothing provided' do
|
149
|
+
tz = TZInfo::Timezone.get('America/Los_Angeles')
|
150
|
+
uorpt.instance_variable_get(:@timezone).should eql tz
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context '#regex_match' do
|
155
|
+
it 'should take no more than one arg' do
|
156
|
+
expect do
|
157
|
+
uorpt.send(:regex_match, nil, nil)
|
158
|
+
end.to raise_error ArgumentError
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should take no less than one arg' do
|
162
|
+
expect do
|
163
|
+
uorpt.send(:regex_match)
|
164
|
+
end.to raise_error ArgumentError
|
165
|
+
end
|
166
|
+
|
167
|
+
it 'should return nil if line matches nothing' do
|
168
|
+
uorpt.send(:regex_match, '').should be_nil
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'should return a Hash if the line matches ANNOUNCEMENT' do
|
172
|
+
l = '2014/02/16, 4:13:10 "############################# Start ' \
|
173
|
+
'CO08_Escape_Chernarus_V1 #############################"'
|
174
|
+
x = uorpt.send(:regex_match, l)
|
175
|
+
x.should be_an_instance_of Hash
|
176
|
+
x[:type].should eql :announcement
|
177
|
+
end
|
178
|
+
|
179
|
+
it 'should return a Hash if the line matches WOUNDED' do
|
180
|
+
l = '2014/02/16, 5:22:55 "4152.41 seconds: Sherminator (CIV) has ' \
|
181
|
+
'been team wounded by Xcenocide (WEST) for 1.50828 damage."'
|
182
|
+
x = uorpt.send(:regex_match, l)
|
183
|
+
x.should be_an_instance_of Hash
|
184
|
+
x[:type].should eql :wounded
|
185
|
+
end
|
186
|
+
|
187
|
+
it 'should return a Hash if the line matches KILLED' do
|
188
|
+
l = '2014/02/16, 4:11:42 "69.85 seconds: Olli (CIV) has been killed ' \
|
189
|
+
'by Yevgeniy Nikolayev (EAST). Olli position: [6553.55,6961.92,' \
|
190
|
+
'0.0015564] (GRID 0655306961). Yevgeniy Nikolayev position: ' \
|
191
|
+
'[6498.62,6916.71,0.0204163] (GRID 0649806916). Distance between: ' \
|
192
|
+
'71.1653 meters. Near players (100m): None."'
|
193
|
+
x = uorpt.send(:regex_match, l)
|
194
|
+
x.should be_an_instance_of Hash
|
195
|
+
x[:type].should eql :killed
|
196
|
+
end
|
197
|
+
|
198
|
+
it 'should return a Hash if the line matches DIED' do
|
199
|
+
l = '2014/02/16, 5:15:06 "3683.58 seconds: Appe96 has died at ' \
|
200
|
+
'[4602.18,7490.26,2.2435] (GRID 0460207490). Near players (100m): ' \
|
201
|
+
'["Olli","nametag47","Villanyi"]"'
|
202
|
+
x = uorpt.send(:regex_match, l)
|
203
|
+
x.should be_an_instance_of Hash
|
204
|
+
x[:type].should eql :died
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
context '#parse' do
|
209
|
+
let(:loglines) do
|
210
|
+
l1 = '2014/02/16, 5:15:06 "3683.58 seconds: Appe96 has died at ' \
|
211
|
+
'[4602.18,7490.26,2.2435] (GRID 0460207490). Near players (100m):' \
|
212
|
+
' ["Olli","nametag47","Villanyi"]"'
|
213
|
+
l2 = '2014/02/16, 4:11:42 "69.85 seconds: Olli (CIV) has been killed ' \
|
214
|
+
'by Yevgeniy Nikolayev (EAST). Olli position: [6553.55,6961.92,' \
|
215
|
+
'0.0015564] (GRID 0655306961). Yevgeniy Nikolayev position: ' \
|
216
|
+
'[6498.62,6916.71,0.0204163] (GRID 0649806916). Distance between:' \
|
217
|
+
' 71.1653 meters. Near players (100m): None."'
|
218
|
+
StringIO.new("#{l1}\n#{l2}")
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'should not take more than one arg' do
|
222
|
+
expect do
|
223
|
+
uorpt.parse(nil, nil)
|
224
|
+
end.to raise_error ArgumentError
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'should not take less than one arg' do
|
228
|
+
expect do
|
229
|
+
uorpt.parse
|
230
|
+
end.to raise_error ArgumentError
|
231
|
+
end
|
232
|
+
|
233
|
+
it 'should fail if arg 1 is not an instance of StringIO' do
|
234
|
+
expect do
|
235
|
+
uorpt.parse(nil)
|
236
|
+
end.to raise_error ArgumentError
|
237
|
+
end
|
238
|
+
|
239
|
+
it 'should return an Array' do
|
240
|
+
ll = StringIO.new
|
241
|
+
x = uorpt.parse(ll)
|
242
|
+
x.should be_an_instance_of Array
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'should return an Array of hashes if a line matches' do
|
246
|
+
x = uorpt.parse(loglines)
|
247
|
+
x.should be_an_instance_of Array
|
248
|
+
x.empty?.should be_false
|
249
|
+
x.each { |y| y.should be_an_instance_of Hash }
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|