rmuh 0.2.5 → 0.2.6

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.
@@ -65,12 +65,12 @@ describe RMuh::RPT::Log::Parsers::UnitedOperationsLog do
65
65
 
66
66
  it 'should not include chat by default' do
67
67
  u = uolog.instance_variable_get(:@include_chat)
68
- expect(u).to be_false
68
+ expect(u).to be_falsey
69
69
  end
70
70
 
71
71
  it 'should convert to zulu by default' do
72
72
  u = uolog.instance_variable_get(:@to_zulu)
73
- expect(u).to be_true
73
+ expect(u).to be_truthy
74
74
  end
75
75
 
76
76
  it 'should use the UO timezone by default' do
@@ -193,7 +193,7 @@ describe RMuh::RPT::Log::Parsers::UnitedOperationsLog do
193
193
  it 'should set date as today if line (0400-2359) and now same range ' do
194
194
  tz = uolog.instance_variable_get(:@timezone)
195
195
  l = yday_line.dup
196
- uolog.stub(:date_of_line_based_on_now) { tz.now }
196
+ allow(uolog).to receive(:date_of_line_based_on_now).and_return(tz.now)
197
197
  uolog.send(:when_am_i!, l)
198
198
  expect(l[:year]).to eql tz.now.year
199
199
  expect(l[:month]).to eql tz.now.month
@@ -204,7 +204,8 @@ describe RMuh::RPT::Log::Parsers::UnitedOperationsLog do
204
204
  d = RMuh::RPT::Log::Util::UnitedOperationsLog::ONE_DAY
205
205
  tz = uolog.instance_variable_get(:@timezone)
206
206
  l = yday_line.dup
207
- uolog.stub(:date_of_line_based_on_now) { tz.now - d }
207
+ allow(uolog).to receive(:date_of_line_based_on_now)
208
+ .and_return(tz.now - d)
208
209
  uolog.send(:when_am_i!, l)
209
210
  expect(l[:year]).to eql((tz.now - d).year)
210
211
  expect(l[:month]).to eql((tz.now - d).month)
@@ -237,22 +238,39 @@ describe RMuh::RPT::Log::Parsers::UnitedOperationsLog do
237
238
  it 'should call where_am_i! and set the year/month/day' do
238
239
  l = { hour: 4, min: 0, sec: 0 }
239
240
  x = uolog.send(:line_modifiers, l)
240
- expect(x.key?(:year)).to be_true
241
- expect(x.key?(:month)).to be_true
242
- expect(x.key?(:day)).to be_true
241
+ expect(x.key?(:year)).to be_truthy
242
+ expect(x.key?(:month)).to be_truthy
243
+ expect(x.key?(:day)).to be_truthy
243
244
  end
244
245
 
245
246
  it 'sould call zulu! and set the time to zulu' do
246
247
  l = { hour: 4, min: 0, sec: 0 }
247
248
  x = uolog.send(:line_modifiers, l)
248
- expect(x.key?(:iso8601)).to be_true
249
- expect(x.key?(:dtg)).to be_true
249
+ expect(x.key?(:iso8601)).to be_truthy
250
+ expect(x.key?(:dtg)).to be_truthy
250
251
  end
251
252
 
252
253
  it 'should call add_guid! and add the event_guid' do
253
254
  l = { hour: 4, min: 0, sec: 0 }
254
255
  x = uolog.send(:line_modifiers, l)
255
- expect(x.key?(:event_guid)).to be_true
256
+ expect(x.key?(:event_guid)).to be_truthy
257
+ end
258
+
259
+ context 'when a user join event' do
260
+ it 'should call strip_port!' do
261
+ l = { hour: 4, min: 0, sec: 0, type: :connect, net: '127.0.0.1:443' }
262
+ x = uolog.send(:line_modifiers, l)
263
+ expect(x.key?(:ipaddr)).to be_truthy
264
+ expect(x.key?(:net)).to be_falsey
265
+ end
266
+ end
267
+
268
+ context 'when not a user joint event' do
269
+ it 'should not call strip_port!' do
270
+ l = { hour: 4, min: 0, sec: 0, type: :x, net: '127.0.0.1:443' }
271
+ x = uolog.send(:line_modifiers, l)
272
+ expect(x.key?(:net)).to be_truthy
273
+ end
256
274
  end
257
275
  end
258
276
 
@@ -307,23 +325,23 @@ describe RMuh::RPT::Log::Parsers::UnitedOperationsLog do
307
325
  u = RMuh::RPT::Log::Parsers::UnitedOperationsLog.new
308
326
  expect(
309
327
  u.send(:regex_matches, StringIO.new(chat_line)).empty?
310
- ).to be_true
328
+ ).to be_truthy
311
329
  end
312
330
 
313
331
  it 'should compact the Array' do
314
332
  l = StringIO.new("Something1\nSomething2\n")
315
333
  x = uolog.send(:regex_matches, l)
316
- expect(x.include?(nil)).to be_false
334
+ expect(x.include?(nil)).to be_falsey
317
335
  end
318
336
 
319
337
  it 'should call #line_modifiers' do
320
338
  x = uolog.send(:regex_matches, StringIO.new(guid_line))
321
- expect(x[0].key?(:year)).to be_true
322
- expect(x[0].key?(:month)).to be_true
323
- expect(x[0].key?(:day)).to be_true
324
- expect(x[0].key?(:iso8601)).to be_true
325
- expect(x[0].key?(:dtg)).to be_true
326
- expect(x[0].key?(:event_guid)).to be_true
339
+ expect(x[0].key?(:year)).to be_truthy
340
+ expect(x[0].key?(:month)).to be_truthy
341
+ expect(x[0].key?(:day)).to be_truthy
342
+ expect(x[0].key?(:iso8601)).to be_truthy
343
+ expect(x[0].key?(:dtg)).to be_truthy
344
+ expect(x[0].key?(:event_guid)).to be_truthy
327
345
  end
328
346
  end
329
347
 
@@ -379,13 +397,13 @@ describe RMuh::RPT::Log::Parsers::UnitedOperationsLog do
379
397
 
380
398
  it 'should call #regex_matches' do
381
399
  x = uolog.parse(StringIO.new(guid_line))
382
- expect(x[0].key?(:type)).to be_true
383
- expect(x[0].key?(:year)).to be_true
384
- expect(x[0].key?(:month)).to be_true
385
- expect(x[0].key?(:day)).to be_true
386
- expect(x[0].key?(:iso8601)).to be_true
387
- expect(x[0].key?(:dtg)).to be_true
388
- expect(x[0].key?(:event_guid)).to be_true
400
+ expect(x[0].key?(:type)).to be_truthy
401
+ expect(x[0].key?(:year)).to be_truthy
402
+ expect(x[0].key?(:month)).to be_truthy
403
+ expect(x[0].key?(:day)).to be_truthy
404
+ expect(x[0].key?(:iso8601)).to be_truthy
405
+ expect(x[0].key?(:dtg)).to be_truthy
406
+ expect(x[0].key?(:event_guid)).to be_truthy
389
407
  end
390
408
  end
391
409
  end
@@ -140,7 +140,7 @@ describe RMuh::RPT::Log::Parsers::UnitedOperationsRPT do
140
140
  end
141
141
 
142
142
  it 'should set @to_zulu to true if nothing provided' do
143
- expect(uorpt.instance_variable_get(:@to_zulu)).to be_true
143
+ expect(uorpt.instance_variable_get(:@to_zulu)).to be_truthy
144
144
  end
145
145
 
146
146
  it 'should set @timezone to America/Los_Angeles if nothing provided' do
@@ -243,7 +243,7 @@ describe RMuh::RPT::Log::Parsers::UnitedOperationsRPT do
243
243
  it 'should return an Array of hashes if a line matches' do
244
244
  x = uorpt.parse(loglines)
245
245
  expect(x).to be_an_instance_of Array
246
- expect(x.empty?).to be_false
246
+ expect(x.empty?).to be_falsey
247
247
  x.each { |y| expect(y).to be_an_instance_of Hash }
248
248
  end
249
249
  end
@@ -9,7 +9,7 @@ describe RMuh::RPT::Log::Util::UnitedOperations do
9
9
  @uo_util.extend(RMuh::RPT::Log::Util::UnitedOperations)
10
10
  @mi = Regexp.new(
11
11
  '(?<year>\d+)/(?<month>\d+)/(?<day>\d+)'\
12
- '\s(?<hour>\d+):(?<min>\d+):(?<sec>\d+)'
12
+ '\s(?<hour>\d+):(?<min>\d+):(?<sec>\d+)\s(?<player_num>\d+)'
13
13
  )
14
14
  @mf = Regexp.new(
15
15
  '(?<server_time>[0-9.]+)\s(?<damage>[0-9.]+)\s(?<distance>[0-9.]+)'
@@ -44,7 +44,7 @@ describe RMuh::RPT::Log::Util::UnitedOperations do
44
44
  t.strftime('%Y-%m-%dT%H:%M:%SZ')
45
45
  end
46
46
  let(:zulued) do
47
- ml = @uo_util.m_to_h(@mi.match('2013/12/31 16:00:00'))
47
+ ml = @uo_util.m_to_h(@mi.match('2013/12/31 16:00:00 0'))
48
48
  @uo_util.zulu!(ml, uo_tz)
49
49
  end
50
50
 
@@ -57,7 +57,7 @@ describe RMuh::RPT::Log::Util::UnitedOperations do
57
57
  end
58
58
 
59
59
  it 'should return a Hash' do
60
- ml = @uo_util.m_to_h(@mi.match('2013/12/31 16:00:00'))
60
+ ml = @uo_util.m_to_h(@mi.match('2013/12/31 16:00:00 0'))
61
61
  mr = @uo_util.zulu!(ml, uo_tz)
62
62
  expect(mr).to be_an_instance_of Hash
63
63
  end
@@ -165,42 +165,42 @@ describe RMuh::RPT::Log::Util::UnitedOperations do
165
165
  it 'should properly set the :event_guid for killed' do
166
166
  x = @uo_util.add_guid!(spec_killed_line)
167
167
  y = spec_guid_reference_implementation(spec_killed_line)
168
- expect(x.key?(:event_guid)).to be_true
168
+ expect(x.key?(:event_guid)).to be_truthy
169
169
  expect(x[:event_guid]).to eql y[:event_guid]
170
170
  end
171
171
 
172
172
  it 'should properly set the :event_guid for died' do
173
173
  x = @uo_util.add_guid!(spec_died_line)
174
174
  y = spec_guid_reference_implementation(spec_died_line)
175
- expect(x.key?(:event_guid)).to be_true
175
+ expect(x.key?(:event_guid)).to be_truthy
176
176
  expect(y[:event_guid]).to eql y[:event_guid]
177
177
  end
178
178
 
179
179
  it 'should properly set the :event_guid for wounded' do
180
180
  x = @uo_util.add_guid!(spec_wounded_line)
181
181
  y = spec_guid_reference_implementation(spec_wounded_line)
182
- expect(x.key?(:event_guid)).to be_true
182
+ expect(x.key?(:event_guid)).to be_truthy
183
183
  expect(x[:event_guid]).to eql y[:event_guid]
184
184
  end
185
185
 
186
186
  it 'should properly set the :event_guid for announcements' do
187
187
  x = @uo_util.add_guid!(spec_announcement_line)
188
188
  y = spec_guid_reference_implementation(spec_announcement_line)
189
- expect(x.key?(:event_guid)).to be_true
189
+ expect(x.key?(:event_guid)).to be_truthy
190
190
  expect(x[:event_guid]).to eql y[:event_guid]
191
191
  end
192
192
 
193
193
  it 'should properly set the :event_guid for beguid' do
194
194
  x = @uo_util.add_guid!(spec_beguid_line)
195
195
  y = spec_guid_reference_implementation(spec_beguid_line)
196
- expect(x.key?(:event_guid)).to be_true
196
+ expect(x.key?(:event_guid)).to be_truthy
197
197
  expect(x[:event_guid]).to eql y[:event_guid]
198
198
  end
199
199
 
200
200
  it 'should properly set the :event_guid for chat' do
201
201
  x = @uo_util.add_guid!(spec_chat_line)
202
202
  y = spec_guid_reference_implementation(spec_chat_line)
203
- expect(x.key?(:event_guid)).to be_true
203
+ expect(x.key?(:event_guid)).to be_truthy
204
204
  expect(x[:event_guid]).to eql y[:event_guid]
205
205
  end
206
206
  end
@@ -270,8 +270,8 @@ describe RMuh::RPT::Log::Util::UnitedOperations do
270
270
  end
271
271
 
272
272
  it 'should convert the correct values to Fixnum' do
273
- md = @mi.match('2014/02/09 14:44:44')
274
- %w( year month day hour min sec ).each do |m|
273
+ md = @mi.match('2014/02/09 14:44:44 0')
274
+ %w( year month day hour min sec player_num ).each do |m|
275
275
  x = @uo_util.__line_modifiers(md, m)
276
276
  expect(x).to be_an_instance_of Fixnum
277
277
  expect(x).to eql md[m].to_i
@@ -315,7 +315,7 @@ describe RMuh::RPT::Log::Util::UnitedOperations do
315
315
  end
316
316
 
317
317
  it 'should properly convert the correct values to int' do
318
- md = @mi.match('2014/02/09 14:44:44')
318
+ md = @mi.match('2014/02/09 14:44:44 0')
319
319
  h = @uo_util.m_to_h(md)
320
320
  [:year, :month, :day, :hour, :min, :sec].each do |m|
321
321
  expect(h[m]).to be_an_instance_of Fixnum
@@ -346,7 +346,7 @@ describe RMuh::RPT::Log::Util::UnitedOperations do
346
346
  md = @ma.match('None."')
347
347
  h = @uo_util.m_to_h(md)
348
348
  expect(h[:nearby_players]).to be_an_instance_of Array
349
- expect(h[:nearby_players].empty?).to be_true
349
+ expect(h[:nearby_players].empty?).to be_truthy
350
350
  end
351
351
  end
352
352
 
@@ -6,56 +6,53 @@ describe RMuh::RPT::Log::Util::UnitedOperationsLog do
6
6
  @uo_util.extend(RMuh::RPT::Log::Util::UnitedOperationsLog)
7
7
  end
8
8
 
9
- context '::ONE_DAY' do
10
- it 'should be an instance of Fixnum' do
11
- expect(
12
- RMuh::RPT::Log::Util::UnitedOperationsLog::ONE_DAY
13
- ).to be_an_instance_of Fixnum
14
- end
9
+ describe '::ONE_DAY' do
10
+ subject { RMuh::RPT::Log::Util::UnitedOperationsLog::ONE_DAY }
15
11
 
16
- it 'should be 24 hours in seconds' do
17
- expect(RMuh::RPT::Log::Util::UnitedOperationsLog::ONE_DAY).to eql 86_400
18
- end
12
+ it { should be_an_instance_of Fixnum }
13
+
14
+ it { should eql 86_400 }
19
15
  end
20
16
 
21
- context '::TIME' do
22
- it 'should be an instance of String' do
23
- expect(
24
- RMuh::RPT::Log::Util::UnitedOperationsLog::TIME
25
- ).to be_an_instance_of String
26
- end
17
+ describe '::TIME_SHORT' do
18
+ subject { RMuh::RPT::Log::Util::UnitedOperationsLog::TIME_SHORT }
19
+
20
+ it { should be_an_instance_of String }
27
21
  end
28
22
 
29
- context '::GUID' do
30
- it 'should be an instance of Regexp' do
31
- expect(
32
- RMuh::RPT::Log::Util::UnitedOperationsLog::GUID
33
- ).to be_an_instance_of Regexp
34
- end
23
+ describe '::TIME' do
24
+ subject { RMuh::RPT::Log::Util::UnitedOperationsLog::TIME }
25
+
26
+ it { should be_an_instance_of String }
27
+ end
28
+
29
+ describe '::GUID' do
30
+ subject { RMuh::RPT::Log::Util::UnitedOperationsLog::GUID }
31
+
32
+ it { should be_an_instance_of Regexp }
35
33
 
36
34
  it 'should match an example line' do
37
35
  l = ' 4:01:02 BattlEye Server: Verified GUID ' \
38
36
  '(04de012b0f882b9ff2e43564c8c09361) of player #0 nametag47'
39
- m = RMuh::RPT::Log::Util::UnitedOperationsLog::GUID.match(l)
37
+ m = subject.match(l)
40
38
  expect(m).to_not be_nil
41
39
  expect(m['hour']).to eql '4'
42
40
  expect(m['min']).to eql '01'
43
41
  expect(m['sec']).to eql '02'
44
42
  expect(m['player_beguid']).to eql '04de012b0f882b9ff2e43564c8c09361'
45
43
  expect(m['player']).to eql 'nametag47'
44
+ expect(m['player_num']).to eql '0'
46
45
  end
47
46
  end
48
47
 
49
- context '::CHAT' do
50
- it 'should be an instance of Regexp' do
51
- expect(
52
- RMuh::RPT::Log::Util::UnitedOperationsLog::CHAT
53
- ).to be_an_instance_of Regexp
54
- end
48
+ describe '::CHAT' do
49
+ subject { RMuh::RPT::Log::Util::UnitedOperationsLog::CHAT }
50
+
51
+ it { should be_an_instance_of Regexp }
55
52
 
56
53
  it 'should match an example line' do
57
54
  l = ' 5:48:01 BattlEye Server: (Side) Xcenocide: Admin back'
58
- m = RMuh::RPT::Log::Util::UnitedOperationsLog::CHAT.match(l)
55
+ m = subject.match(l)
59
56
  expect(m['hour']).to eql '5'
60
57
  expect(m['min']).to eql '48'
61
58
  expect(m['sec']).to eql '01'
@@ -64,4 +61,37 @@ describe RMuh::RPT::Log::Util::UnitedOperationsLog do
64
61
  expect(m['message']).to eql 'Admin back'
65
62
  end
66
63
  end
64
+
65
+ describe '::JOINED' do
66
+ subject { RMuh::RPT::Log::Util::UnitedOperationsLog::JOINED }
67
+
68
+ it { should be_an_instance_of Regexp }
69
+
70
+ it 'should match an example line' do
71
+ l = ' 4:01:09 BattlEye Server: Player #0 Delta38 ' \
72
+ '(127.0.0.1:65007) connected'
73
+ m = subject.match(l)
74
+ expect(m['hour']).to eql '4'
75
+ expect(m['min']).to eql '01'
76
+ expect(m['sec']).to eql '09'
77
+ expect(m['player']).to eql 'Delta38'
78
+ expect(m['player_num']).to eql '0'
79
+ expect(m['net']).to eql '127.0.0.1:65007'
80
+ end
81
+ end
82
+
83
+ describe '::LEFT' do
84
+ subject { RMuh::RPT::Log::Util::UnitedOperationsLog::LEFT }
85
+
86
+ it { should be_an_instance_of Regexp }
87
+
88
+ it 'should match an example line' do
89
+ l = ' 5:05:53 Player MPWR disconnected.'
90
+ m = subject.match(l)
91
+ expect(m['hour']).to eql '5'
92
+ expect(m['min']).to eql '05'
93
+ expect(m['sec']).to eql '53'
94
+ expect(m['player']).to eq 'MPWR'
95
+ end
96
+ end
67
97
  end
@@ -3,31 +3,31 @@
3
3
  describe RMuh do
4
4
  context '::VERSION_MAJ' do
5
5
  it 'should have a major version that is an integer' do
6
- expect(RMuh::VERSION_MAJ.is_a?(Integer)).to be_true
6
+ expect(RMuh::VERSION_MAJ.is_a?(Integer)).to be_truthy
7
7
  end
8
8
 
9
9
  it 'should have a major version that is a positive number' do
10
- expect(RMuh::VERSION_MAJ > -1).to be_true
10
+ expect(RMuh::VERSION_MAJ > -1).to be_truthy
11
11
  end
12
12
  end
13
13
 
14
14
  context '::VERSION_MIN' do
15
15
  it 'should have a minor version that is an integer' do
16
- expect(RMuh::VERSION_MIN.is_a?(Integer)).to be_true
16
+ expect(RMuh::VERSION_MIN.is_a?(Integer)).to be_truthy
17
17
  end
18
18
 
19
19
  it 'should have a minor version that is a positive integer' do
20
- expect(RMuh::VERSION_MIN > -1).to be_true
20
+ expect(RMuh::VERSION_MIN > -1).to be_truthy
21
21
  end
22
22
  end
23
23
 
24
24
  context '::VERSION_REV' do
25
25
  it 'should have a revision number that is an integer' do
26
- expect(RMuh::VERSION_REV.is_a?(Integer)).to be_true
26
+ expect(RMuh::VERSION_REV.is_a?(Integer)).to be_truthy
27
27
  end
28
28
 
29
29
  it 'should have a revision number that is a positive integer' do
30
- expect(RMuh::VERSION_REV > -1).to be_true
30
+ expect(RMuh::VERSION_REV > -1).to be_truthy
31
31
  end
32
32
  end
33
33
 
@@ -37,15 +37,15 @@ shared_examples 'RMuh::ServerStats::Base' do
37
37
  it 'should set the default port if not provided' do
38
38
  h = srv_hash.dup
39
39
  RMuh::ServerStats::Base.validate_opts(h)
40
- expect(h.key?(:port)).to be_true
40
+ expect(h.key?(:port)).to be_truthy
41
41
  expect(h[:port]).to eql RMuh::ServerStats::Base::DEFAULT_PORT
42
42
  end
43
43
 
44
44
  it 'should set the auto_cache key to true if not provided' do
45
45
  h = srv_hash.dup
46
46
  RMuh::ServerStats::Base.validate_opts(h)
47
- expect(h.key?(:auto_cache)).to be_true
48
- expect(h[:auto_cache]).to be_true
47
+ expect(h.key?(:auto_cache)).to be_truthy
48
+ expect(h[:auto_cache]).to be_truthy
49
49
  end
50
50
 
51
51
  it 'should return nil' do
@@ -122,7 +122,8 @@ shared_examples 'RMuh::ServerStats::Base' do
122
122
 
123
123
  context '#sync' do
124
124
  before do
125
- GamespyQuery::Socket.any_instance.stub(:sync).and_return(one: 1)
125
+ allow_any_instance_of(GamespyQuery::Socket).to receive(:sync)
126
+ .and_return(one: 1)
126
127
  end
127
128
  let(:b) { RMuh::ServerStats::Base.new(host: '127.0.0.1') }
128
129
 
@@ -149,7 +150,7 @@ shared_examples 'RMuh::ServerStats::Base' do
149
150
 
150
151
  it 'should return the return value from the #sync method if cache true' do
151
152
  n = RMuh::ServerStats::Base.new(host: '127.0.0.1', cache: false)
152
- n.stub(:sync).and_return(one: 'two')
153
+ allow(n).to receive(:sync).and_return(one: 'two')
153
154
  expect(n.send(:remote_stats)).to eql(one: 'two')
154
155
  end
155
156
  end
@@ -158,8 +159,8 @@ shared_examples 'RMuh::ServerStats::Base' do
158
159
  before(:each) do
159
160
  @b = RMuh::ServerStats::Base.new(host: '127.0.0.1')
160
161
  @bf = RMuh::ServerStats::Base.new(host: '127.0.0.1', cache: false)
161
- @b.stub(:sync).and_return(one: 'two')
162
- @bf.stub(:sync).and_return(one: 'two')
162
+ allow(@b).to receive(:sync).and_return(one: 'two')
163
+ allow(@bf).to receive(:sync).and_return(one: 'two')
163
164
  end
164
165
 
165
166
  it 'should take no args' do
@@ -181,8 +182,8 @@ shared_examples 'RMuh::ServerStats::Base' do
181
182
  before(:each) do
182
183
  @b = RMuh::ServerStats::Base.new(host: '127.0.0.1')
183
184
  @bf = RMuh::ServerStats::Base.new(host: '127.0.0.1', cache: false)
184
- @b.stub(:sync).and_return(one: 'two')
185
- @bf.stub(:sync).and_return(one: 'two')
185
+ allow(@b).to receive(:sync).and_return(one: 'two')
186
+ allow(@bf).to receive(:sync).and_return(one: 'two')
186
187
  @b.update_cache
187
188
  end
188
189