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.
@@ -16,7 +16,7 @@ describe 'example files' do
16
16
  _, _, s = Open3.capture3(
17
17
  "bundle exec ruby #{File.join(DIR, e)}"
18
18
  )
19
- expect(s.success?).to be_true
19
+ expect(s.success?).to be_truthy
20
20
  end
21
21
  end
22
22
  end
@@ -0,0 +1,42 @@
1
+ # -*- coding: UTF-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe RMuh::RPT::Log::Formatters::Base do
5
+ let(:base) { RMuh::RPT::Log::Formatters::Base }
6
+
7
+ describe '.format' do
8
+ context 'when given more than one arg' do
9
+ it 'should raise ArgumentError' do
10
+ expect do
11
+ base.format(nil, nil)
12
+ end.to raise_error ArgumentError
13
+ end
14
+ end
15
+
16
+ context 'when given less than one arg' do
17
+ it 'should raise ArgumentError' do
18
+ expect do
19
+ base.format
20
+ end.to raise_error ArgumentError
21
+ end
22
+ end
23
+
24
+ context 'when provided a log event' do
25
+ let(:event) { { type: :log, message: 'ohai' } }
26
+
27
+ subject { base.format(event) }
28
+
29
+ it { should be_an_instance_of String }
30
+
31
+ it { should eql 'ohai' }
32
+ end
33
+
34
+ context 'when provided a non-log event' do
35
+ let(:event) { { type: :notlog, message: 'nohai' } }
36
+
37
+ subject { base.format(event) }
38
+
39
+ it { should be_nil }
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,198 @@
1
+ # -*- coding: UTF-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe RMuh::RPT::Log::Formatters::UnitedOperationsLog do
5
+ let(:uolog) { RMuh::RPT::Log::Formatters::UnitedOperationsLog }
6
+
7
+ describe '.format_chat' do
8
+ context 'when given more than one arg' do
9
+ it 'should raise ArgumentError' do
10
+ expect do
11
+ uolog.send(:format_chat, nil, nil)
12
+ end.to raise_error ArgumentError
13
+ end
14
+ end
15
+
16
+ context 'when given less than one arg' do
17
+ it 'should raise ArgumentError' do
18
+ expect do
19
+ uolog.send(:format_chat)
20
+ end.to raise_error ArgumentError
21
+ end
22
+ end
23
+
24
+ context 'when given a chat event' do
25
+ let(:event) do
26
+ {
27
+ iso8601: '1970-01-01T00:00:00Z', channel: 'group',
28
+ player: 'Heckman', message: 'Seriously?'
29
+ }
30
+ end
31
+
32
+ subject { uolog.send(:format_chat, event) }
33
+
34
+ it { should be_an_instance_of String }
35
+
36
+ it do
37
+ should eql "1970-01-01T00:00:00Z Chat: (group) Heckman: Seriously?\n"
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '.format_beguid' do
43
+ context 'when given more than one arg' do
44
+ it 'should raise ArgumentError' do
45
+ expect do
46
+ uolog.send(:format_beguid, nil, nil)
47
+ end.to raise_error ArgumentError
48
+ end
49
+ end
50
+
51
+ context 'when given less than one arg' do
52
+ it 'should raise ArgumentError' do
53
+ expect do
54
+ uolog.send(:format_beguid)
55
+ end.to raise_error ArgumentError
56
+ end
57
+ end
58
+
59
+ context 'when given a beguid event' do
60
+ let(:event) do
61
+ {
62
+ iso8601: 'z', player_beguid: 'x', player: 'y', player_num: 0
63
+ }
64
+ end
65
+
66
+ subject { uolog.send(:format_beguid, event) }
67
+
68
+ it { should be_an_instance_of String }
69
+
70
+ it { should eql "z Server: Verified GUID (x) of player #0 y\n" }
71
+ end
72
+ end
73
+
74
+ describe '.format_disconnect' do
75
+ context 'when given more than one arg' do
76
+ it 'should raise ArgumentError' do
77
+ expect do
78
+ uolog.send(:format_disconnect, nil, nil)
79
+ end.to raise_error ArgumentError
80
+ end
81
+ end
82
+
83
+ context 'when given less than one arg' do
84
+ it 'should raise ArgumentError' do
85
+ expect do
86
+ uolog.send(:format_disconnect)
87
+ end.to raise_error ArgumentError
88
+ end
89
+ end
90
+
91
+ context 'when given a beguid event' do
92
+ let(:event) do
93
+ {
94
+ iso8601: 'z', player: 'x'
95
+ }
96
+ end
97
+
98
+ subject { uolog.send(:format_disconnect, event) }
99
+
100
+ it { should be_an_instance_of String }
101
+
102
+ it { should eql "z Server: Player x disconnected\n" }
103
+ end
104
+ end
105
+
106
+ describe '.format_connect' do
107
+ context 'when given more than one arg' do
108
+ it 'should raise ArgumentError' do
109
+ expect do
110
+ uolog.send(:format_connect, nil, nil)
111
+ end.to raise_error ArgumentError
112
+ end
113
+ end
114
+
115
+ context 'when given less than one arg' do
116
+ it 'should raise ArgumentError' do
117
+ expect do
118
+ uolog.send(:format_connect)
119
+ end.to raise_error ArgumentError
120
+ end
121
+ end
122
+
123
+ context 'when given a beguid event' do
124
+ let(:event) do
125
+ {
126
+ iso8601: 'z', player: 'x', player_num: 0, ipaddr: '127.0.0.1'
127
+ }
128
+ end
129
+
130
+ subject { uolog.send(:format_connect, event) }
131
+
132
+ it { should be_an_instance_of String }
133
+
134
+ it { should eql "z Server: Player #0 x (127.0.0.1) connected\n" }
135
+ end
136
+ end
137
+
138
+ describe '.format' do
139
+ context 'when given more than one arg' do
140
+ it 'should raise ArgumentError' do
141
+ expect do
142
+ uolog.format(nil, nil)
143
+ end.to raise_error ArgumentError
144
+ end
145
+ end
146
+
147
+ context 'when given less than one arg' do
148
+ it 'should raise ArgumentError' do
149
+ expect do
150
+ uolog.format
151
+ end.to raise_error ArgumentError
152
+ end
153
+ end
154
+
155
+ context 'when given a :connect event' do
156
+ let(:event) { { type: :connect } }
157
+ it 'should call .format_connect' do
158
+ expect(uolog).to receive(:format_connect).with(event)
159
+ .and_return('ohai')
160
+ expect(uolog.format(event)).to eql 'ohai'
161
+ end
162
+ end
163
+
164
+ context 'when given a :disconnect event' do
165
+ let(:event) { { type: :disconnect } }
166
+ it 'should call .format_disconnect' do
167
+ expect(uolog).to receive(:format_disconnect).with(event)
168
+ .and_return('ohai2')
169
+ expect(uolog.format(event)).to eql 'ohai2'
170
+ end
171
+ end
172
+
173
+ context 'when given a :beguid event' do
174
+ let(:event) { { type: :beguid } }
175
+ it 'should call .format_connect' do
176
+ expect(uolog).to receive(:format_beguid).with(event)
177
+ .and_return('ohai3')
178
+ expect(uolog.format(event)).to eql 'ohai3'
179
+ end
180
+ end
181
+
182
+ context 'when given a :chat event' do
183
+ let(:event) { { type: :chat } }
184
+ it 'should call .format_beguid' do
185
+ expect(uolog).to receive(:format_chat).with(event)
186
+ .and_return('ohai4')
187
+ expect(uolog.format(event)).to eql 'ohai4'
188
+ end
189
+ end
190
+
191
+ context 'when given an unknown event' do
192
+ let(:event) { { type: :x } }
193
+ it 'should call .format_connect' do
194
+ expect(uolog.format(event)).to be_nil
195
+ end
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,757 @@
1
+ # -*- coding: UTF-8 -*-
2
+ require 'spec_helper'
3
+
4
+ describe RMuh::RPT::Log::Formatters::UnitedOperationsRPT do
5
+ let(:uorpt) { RMuh::RPT::Log::Formatters::UnitedOperationsRPT }
6
+
7
+ before do
8
+ allow(uorpt).to receive(:time).and_return('z')
9
+ allow(uorpt).to receive(:server_time).and_return('zt')
10
+ end
11
+
12
+ describe '::LEVELS' do
13
+ subject { RMuh::RPT::Log::Formatters::UnitedOperationsRPT::LEVELS }
14
+
15
+ it { should be_an_instance_of Array }
16
+
17
+ it 'should only contain symbols' do
18
+ subject.each do |l|
19
+ expect(l).to be_an_instance_of Symbol
20
+ end
21
+ end
22
+ end
23
+
24
+ describe '.validate_and_set_level' do
25
+ before(:each) { uorpt.instance_variable_set(:@level, nil) }
26
+
27
+ context 'when given more than one arg' do
28
+ it 'should raise ArgumentError' do
29
+ expect do
30
+ uorpt.send(:validate_and_set_level, nil, nil)
31
+ end.to raise_error ArgumentError
32
+ end
33
+ end
34
+
35
+ context 'when given less than one arg' do
36
+ it 'should raise ArgumentError' do
37
+ expect do
38
+ uorpt.send(:validate_and_set_level)
39
+ end.to raise_error ArgumentError
40
+ end
41
+ end
42
+
43
+ context 'should always' do
44
+ it 'accept the values within ::LEVELS' do
45
+ RMuh::RPT::Log::Formatters::UnitedOperationsRPT::LEVELS.each do |l|
46
+ expect do
47
+ uorpt.send(:validate_and_set_level, l)
48
+ end.not_to raise_error
49
+ expect(uorpt.instance_variable_get(:@level)).to eql l
50
+ end
51
+ end
52
+ end
53
+
54
+ context 'when given a valid log verbosity level' do
55
+ let(:level) { :full }
56
+
57
+ it 'should not raise ArgumentError' do
58
+ expect do
59
+ uorpt.send(:validate_and_set_level, level)
60
+ end.not_to raise_error
61
+ end
62
+
63
+ it 'should set the @level instance variable to your level' do
64
+ uorpt.send(:validate_and_set_level, level)
65
+ expect(uorpt.instance_variable_get(:@level)).to eql :full
66
+ end
67
+ end
68
+
69
+ context 'when given a bullshit level, and yeah I said bullshit...' do
70
+ it 'should raise ArgumentError :)' do
71
+ expect do
72
+ uorpt.send(:validate_and_set_level, :bullshit)
73
+ end.to raise_error ArgumentError
74
+ end
75
+ end
76
+ end
77
+
78
+ describe '.time' do
79
+ before do
80
+ allow(uorpt).to receive(:time).and_call_original
81
+ end
82
+
83
+ context 'when given more than one arg' do
84
+ it 'should raise ArgumentError' do
85
+ expect do
86
+ uorpt.send(:time, nil, nil)
87
+ end.to raise_error ArgumentError
88
+ end
89
+ end
90
+
91
+ context 'when given less than one arg' do
92
+ it 'should raise ArgumentError' do
93
+ expect do
94
+ uorpt.send(:time, nil, nil)
95
+ end.to raise_error ArgumentError
96
+ end
97
+ end
98
+
99
+ context 'when given an event with an :iso8601 key' do
100
+ let(:event) { { iso8601: '1970-01-01T00:00:00Z' } }
101
+
102
+ subject { uorpt.send(:time, event) }
103
+
104
+ it { should be_an_instance_of String }
105
+
106
+ it { should eql '1970-01-01T00:00:00Z' }
107
+ end
108
+ end
109
+
110
+ describe '.server_time' do
111
+ before do
112
+ allow(uorpt).to receive(:server_time).and_call_original
113
+ end
114
+
115
+ context 'when given more than one arg' do
116
+ it 'should raise ArgumentError' do
117
+ expect do
118
+ uorpt.send(:server_time, nil, nil)
119
+ end.to raise_error ArgumentError
120
+ end
121
+ end
122
+
123
+ context 'when given less than one arg' do
124
+ it 'should raise ArgumentError' do
125
+ expect do
126
+ uorpt.send(:server_time, nil, nil)
127
+ end.to raise_error ArgumentError
128
+ end
129
+ end
130
+
131
+ context 'when given an event with a :server_time key' do
132
+ let(:event) { { server_time: 3.14 } }
133
+
134
+ subject { uorpt.send(:server_time, event) }
135
+
136
+ it { should be_an_instance_of String }
137
+
138
+ it { should eql 'z "3.14 seconds:' }
139
+ end
140
+ end
141
+
142
+ describe '.nearby_players' do
143
+ context 'when given more than one arg' do
144
+ it 'should raise ArgumentError' do
145
+ expect do
146
+ uorpt.send(:nearby_players, nil, nil)
147
+ end.to raise_error ArgumentError
148
+ end
149
+ end
150
+
151
+ context 'when given less than one arg' do
152
+ it 'should raise ArgumentError' do
153
+ expect do
154
+ uorpt.send(:nearby_players)
155
+ end.to raise_error ArgumentError
156
+ end
157
+ end
158
+
159
+ context 'when provided an empty list of nearby players' do
160
+ let(:event) { { nearby_players: [] } }
161
+
162
+ subject { uorpt.send(:nearby_players, event) }
163
+
164
+ it { should be_an_instance_of String }
165
+
166
+ it { should eql '. Nearby players (100m): None' }
167
+ end
168
+
169
+ context 'when provided a ist of nearby players' do
170
+ let(:event) { { nearby_players: %w(Player1 Player2) } }
171
+
172
+ subject { uorpt.send(:nearby_players, event) }
173
+
174
+ it { should be_an_instance_of String }
175
+
176
+ it { should eql ". Nearby players (100m): ['Player1','Player2']" }
177
+ end
178
+ end
179
+
180
+ describe '.beguid' do
181
+ context 'when given more than one arg' do
182
+ it 'should raise ArgumentError' do
183
+ expect do
184
+ uorpt.send(:beguid, nil, nil)
185
+ end.to raise_error ArgumentError
186
+ end
187
+ end
188
+
189
+ context 'when given less than one arg' do
190
+ it 'should raise ArgumentError' do
191
+ expect do
192
+ uorpt.send(:beguid)
193
+ end.to raise_error ArgumentError
194
+ end
195
+ end
196
+
197
+ context 'when given a non-nil value' do
198
+ subject { uorpt.send(:beguid, 'ohai') }
199
+
200
+ it { should be_an_instance_of String }
201
+
202
+ it { should eql ' (ohai)' }
203
+ end
204
+
205
+ context 'when given nil' do
206
+ subject { uorpt.send(:beguid, nil) }
207
+
208
+ it { should be_nil }
209
+ end
210
+ end
211
+
212
+ describe '.format_died_ext' do
213
+ context 'when given more than one arg' do
214
+ it 'should raise ArgumentError' do
215
+ expect do
216
+ uorpt.send(:format_died_ext, nil, nil)
217
+ end.to raise_error ArgumentError
218
+ end
219
+ end
220
+
221
+ context 'when given less than one arg' do
222
+ it 'should raise ArgumentError' do
223
+ expect do
224
+ uorpt.send(:format_died_ext)
225
+ end.to raise_error ArgumentError
226
+ end
227
+ end
228
+
229
+ context 'when given a death event' do
230
+ let(:event) { { victim_position: 'x', victim_grid: '0x0' } }
231
+
232
+ subject { uorpt.send(:format_died_ext, event) }
233
+
234
+ it { should be_an_instance_of String }
235
+
236
+ it { should eql ' at [x] (GRID 0x0)' }
237
+ end
238
+ end
239
+
240
+ describe '.format_wounded_ext' do
241
+ context 'when given more than one arg' do
242
+ it 'should raise ArgumentError' do
243
+ expect do
244
+ uorpt.send(:format_wounded_ext, nil, nil)
245
+ end.to raise_error ArgumentError
246
+ end
247
+ end
248
+
249
+ context 'when given less than one arg' do
250
+ it 'should raise ArgumentError' do
251
+ expect do
252
+ uorpt.send(:format_wounded_ext)
253
+ end.to raise_error ArgumentError
254
+ end
255
+ end
256
+
257
+ context 'when given a wounded event' do
258
+ let(:event) { { damage: 9001 } }
259
+
260
+ subject { uorpt.send(:format_wounded_ext, event) }
261
+
262
+ it { should be_an_instance_of String }
263
+
264
+ it { should eql ' for 9001 damage' }
265
+ end
266
+ end
267
+
268
+ describe '.format_killed_ext' do
269
+ context 'when given more than one arg' do
270
+ it 'should raise ArgumentError' do
271
+ expect do
272
+ uorpt.send(:format_killed_ext, nil, nil)
273
+ end.to raise_error ArgumentError
274
+ end
275
+ end
276
+
277
+ context 'when given less than one arg' do
278
+ it 'should raise ArgumentError' do
279
+ expect do
280
+ uorpt.send(:format_killed_ext)
281
+ end.to raise_error ArgumentError
282
+ end
283
+ end
284
+
285
+ context 'when given a killed event' do
286
+ let(:event) do
287
+ {
288
+ victim: 'x', victim_position: '0', victim_grid: '00', offender: 'y',
289
+ offender_position: '1', offender_grid: '11', distance: '42'
290
+ }
291
+ end
292
+
293
+ subject { uorpt.send(:format_killed_ext, event) }
294
+
295
+ it { should be_an_instance_of String }
296
+
297
+ it do
298
+ should eql(
299
+ '. x pos: [0] (GRID 00). y pos: [1] (GRID 11). Distance between: 42m'
300
+ )
301
+ end
302
+ end
303
+ end
304
+
305
+ describe '.format_announcement' do
306
+ context 'when given more than one arg' do
307
+ it 'should raise ArgumentError' do
308
+ expect do
309
+ uorpt.send(:format_announcement, nil, nil)
310
+ end.to raise_error ArgumentError
311
+ end
312
+ end
313
+
314
+ context 'when given less than one arg' do
315
+ it 'should raise ArgumentError' do
316
+ expect do
317
+ uorpt.send(:format_announcement)
318
+ end.to raise_error ArgumentError
319
+ end
320
+ end
321
+
322
+ context 'when given an announcement event' do
323
+ let(:event) { { head: '#', tail: '##', message: 'ohai' } }
324
+
325
+ subject { uorpt.send(:format_announcement, event) }
326
+
327
+ it { should be_an_instance_of String }
328
+
329
+ it { should eql "z \"# ohai ##\"\n" }
330
+ end
331
+ end
332
+
333
+ describe '.format_died' do
334
+ let(:event) { { victim: 'x' } }
335
+
336
+ context 'when given more than one arg' do
337
+ it 'should raise ArgumentError' do
338
+ expect do
339
+ uorpt.send(:format_died, nil, nil)
340
+ end.to raise_error ArgumentError
341
+ end
342
+ end
343
+
344
+ context 'when given less than one arg' do
345
+ it 'should raise ArgumentError' do
346
+ expect do
347
+ uorpt.send(:format_died)
348
+ end.to raise_error ArgumentError
349
+ end
350
+ end
351
+
352
+ context 'when the event has a beguid for victim' do
353
+ before do
354
+ uorpt.instance_variable_set(:@level, :simple)
355
+ end
356
+ let(:event) { { victim: 'x', victim_beguid: 'abc' } }
357
+
358
+ subject { uorpt.send(:format_died, event) }
359
+
360
+ it { should be_an_instance_of String }
361
+
362
+ it { should eql "zt x (abc) has bled out or died of pain\"\n" }
363
+ end
364
+
365
+ context 'when @level is :simple' do
366
+ before { uorpt.instance_variable_set(:@level, :simple) }
367
+
368
+ subject { uorpt.send(:format_died, event) }
369
+
370
+ it { should be_an_instance_of String }
371
+
372
+ it { should eql "zt x has bled out or died of pain\"\n" }
373
+ end
374
+
375
+ context 'when @level is :ext' do
376
+ before do
377
+ uorpt.instance_variable_set(:@level, :ext)
378
+ allow(uorpt).to receive(:format_died_ext).and_return(' z')
379
+ end
380
+
381
+ subject { uorpt.send(:format_died, event) }
382
+
383
+ it { should be_an_instance_of String }
384
+
385
+ it { should eql "zt x has bled out or died of pain z\"\n" }
386
+
387
+ it 'should call the .format_died_ext' do
388
+ expect(uorpt).to receive(:format_died_ext).with(event)
389
+ .and_return(' z')
390
+
391
+ expect(uorpt.send(:format_died, event)).to be_an_instance_of String
392
+ end
393
+ end
394
+
395
+ context 'when @level is :full' do
396
+ before do
397
+ uorpt.instance_variable_set(:@level, :full)
398
+ allow(uorpt).to receive(:format_died_ext).and_return(' z')
399
+ allow(uorpt).to receive(:nearby_players).and_return(' y')
400
+ end
401
+
402
+ subject { uorpt.send(:format_died, event) }
403
+
404
+ it { should be_an_instance_of String }
405
+
406
+ it { should eql "zt x has bled out or died of pain z y\"\n" }
407
+
408
+ it 'should call the .format_died_ext' do
409
+ expect(uorpt).to receive(:format_died_ext).with(event)
410
+ .and_return(' z')
411
+
412
+ expect(uorpt.send(:format_died, event)).to be_an_instance_of String
413
+ end
414
+
415
+ it 'should call the .nearby_players' do
416
+ expect(uorpt).to receive(:nearby_players).with(event)
417
+ .and_return(' y')
418
+
419
+ expect(uorpt.send(:format_died, event)).to be_an_instance_of String
420
+ end
421
+ end
422
+ end
423
+
424
+ describe '.format_killed' do
425
+ let(:event) do
426
+ { victim: 'x', victim_team: 'b', offender: 'y', offender_team: 'o' }
427
+ end
428
+
429
+ context 'when given more than one arg' do
430
+ it 'should raise ArgumentError' do
431
+ expect do
432
+ uorpt.send(:format_killed, nil, nil)
433
+ end.to raise_error ArgumentError
434
+ end
435
+ end
436
+
437
+ context 'when given less than one arg' do
438
+ it 'should raise ArgumentError' do
439
+ expect do
440
+ uorpt.send(:format_killed)
441
+ end.to raise_error ArgumentError
442
+ end
443
+ end
444
+
445
+ context 'when the event has a beguid for both players' do
446
+ before do
447
+ uorpt.instance_variable_set(:@level, :simple)
448
+ end
449
+ let(:event) do
450
+ {
451
+ victim: 'x', victim_team: 'b', offender: 'y', offender_team: 'o',
452
+ victim_beguid: 'abc', offender_beguid: '123'
453
+ }
454
+ end
455
+
456
+ subject { uorpt.send(:format_killed, event) }
457
+
458
+ it { should be_an_instance_of String }
459
+
460
+ it { should eql "zt x (abc) (b) has been killed by y (123) (o)\"\n" }
461
+ end
462
+
463
+ context 'when the event has a beguid for the victim' do
464
+ before do
465
+ uorpt.instance_variable_set(:@level, :simple)
466
+ end
467
+ let(:event) do
468
+ {
469
+ victim: 'x', victim_team: 'b', offender: 'y', offender_team: 'o',
470
+ victim_beguid: 'abc'
471
+ }
472
+ end
473
+
474
+ subject { uorpt.send(:format_killed, event) }
475
+
476
+ it { should be_an_instance_of String }
477
+
478
+ it { should eql "zt x (abc) (b) has been killed by y (o)\"\n" }
479
+ end
480
+
481
+ context 'when the event has a beguid for the offender' do
482
+ before do
483
+ uorpt.instance_variable_set(:@level, :simple)
484
+ end
485
+ let(:event) do
486
+ {
487
+ victim: 'x', victim_team: 'b', offender: 'y', offender_team: 'o',
488
+ offender_beguid: '123'
489
+ }
490
+ end
491
+
492
+ subject { uorpt.send(:format_killed, event) }
493
+
494
+ it { should be_an_instance_of String }
495
+
496
+ it { should eql "zt x (b) has been killed by y (123) (o)\"\n" }
497
+ end
498
+
499
+ context 'when @level is :simple' do
500
+ before { uorpt.instance_variable_set(:@level, :simple) }
501
+
502
+ subject { uorpt.send(:format_killed, event) }
503
+
504
+ it { should be_an_instance_of String }
505
+
506
+ it { should eql "zt x (b) has been killed by y (o)\"\n" }
507
+ end
508
+
509
+ context 'when @level is :ext' do
510
+ before do
511
+ uorpt.instance_variable_set(:@level, :ext)
512
+ allow(uorpt).to receive(:format_killed_ext).and_return(' k')
513
+ end
514
+
515
+ subject { uorpt.send(:format_killed, event) }
516
+
517
+ it { should be_an_instance_of String }
518
+
519
+ it { should eql "zt x (b) has been killed by y (o) k\"\n" }
520
+
521
+ it 'should call .format_killed_ext' do
522
+ expect(uorpt).to receive(:format_killed_ext).with(event)
523
+ .and_return(' k')
524
+
525
+ expect(uorpt.send(:format_killed, event)).to be_an_instance_of String
526
+ end
527
+ end
528
+
529
+ context 'when @level is :full' do
530
+ before do
531
+ uorpt.instance_variable_set(:@level, :full)
532
+ allow(uorpt).to receive(:format_killed_ext).and_return(' k')
533
+ allow(uorpt).to receive(:nearby_players).and_return(' p')
534
+ end
535
+
536
+ subject { uorpt.send(:format_killed, event) }
537
+
538
+ it { should be_an_instance_of String }
539
+
540
+ it { should eql "zt x (b) has been killed by y (o) k p\"\n" }
541
+
542
+ it 'should call .format_killed_ext' do
543
+ expect(uorpt).to receive(:format_killed_ext).with(event)
544
+ .and_return(' k')
545
+
546
+ expect(uorpt.send(:format_killed, event)).to be_an_instance_of String
547
+ end
548
+
549
+ it 'should call .nearby_players' do
550
+ expect(uorpt).to receive(:nearby_players).with(event)
551
+ .and_return(' p')
552
+
553
+ expect(uorpt.send(:format_killed, event)).to be_an_instance_of String
554
+ end
555
+ end
556
+ end
557
+
558
+ describe '.format_wounded' do
559
+ let(:event) do
560
+ { victim: 'x', victim_team: 'b', offender: 'y', offender_team: 'o' }
561
+ end
562
+
563
+ context 'when given more than one arg' do
564
+ it 'should raise ArgumentError' do
565
+ expect do
566
+ uorpt.send(:format_wounded, nil, nil)
567
+ end.to raise_error ArgumentError
568
+ end
569
+ end
570
+
571
+ context 'when given less than one arg' do
572
+ it 'should raise ArgumentError' do
573
+ expect do
574
+ uorpt.send(:format_wounded)
575
+ end.to raise_error ArgumentError
576
+ end
577
+ end
578
+
579
+ context 'when the event has a beguid for both players' do
580
+ before do
581
+ uorpt.instance_variable_set(:@level, :simple)
582
+ end
583
+ let(:event) do
584
+ {
585
+ victim: 'x', victim_team: 'b', offender: 'y', offender_team: 'o',
586
+ victim_beguid: 'abc', offender_beguid: '123'
587
+ }
588
+ end
589
+
590
+ subject { uorpt.send(:format_wounded, event) }
591
+
592
+ it { should be_an_instance_of String }
593
+
594
+ it { should eql "zt x (abc) (b) has been wounded by y (123) (o)\"\n" }
595
+ end
596
+
597
+ context 'when the event has a beguid for only victim' do
598
+ before do
599
+ uorpt.instance_variable_set(:@level, :simple)
600
+ end
601
+ let(:event) do
602
+ {
603
+ victim: 'x', victim_team: 'b', offender: 'y', offender_team: 'o',
604
+ victim_beguid: 'abc'
605
+ }
606
+ end
607
+
608
+ subject { uorpt.send(:format_wounded, event) }
609
+
610
+ it { should be_an_instance_of String }
611
+
612
+ it { should eql "zt x (abc) (b) has been wounded by y (o)\"\n" }
613
+ end
614
+
615
+ context 'when the event has a beguid for only offender' do
616
+ before do
617
+ uorpt.instance_variable_set(:@level, :simple)
618
+ end
619
+ let(:event) do
620
+ {
621
+ victim: 'x', victim_team: 'b', offender: 'y', offender_team: 'o',
622
+ offender_beguid: '123'
623
+ }
624
+ end
625
+
626
+ subject { uorpt.send(:format_wounded, event) }
627
+
628
+ it { should be_an_instance_of String }
629
+
630
+ it { should eql "zt x (b) has been wounded by y (123) (o)\"\n" }
631
+ end
632
+
633
+ context 'when @level is :simple' do
634
+ before { uorpt.instance_variable_set(:@level, :simple) }
635
+
636
+ subject { uorpt.send(:format_wounded, event) }
637
+
638
+ it { should be_an_instance_of String }
639
+
640
+ it { should eql "zt x (b) has been wounded by y (o)\"\n" }
641
+ end
642
+
643
+ context 'when @level is :ext' do
644
+ before do
645
+ uorpt.instance_variable_set(:@level, :ext)
646
+ allow(uorpt).to receive(:format_wounded_ext).and_return(' k')
647
+ end
648
+
649
+ subject { uorpt.send(:format_wounded, event) }
650
+
651
+ it { should be_an_instance_of String }
652
+
653
+ it { should eql "zt x (b) has been wounded by y (o) k\"\n" }
654
+
655
+ it 'should call .format_wounded_ext' do
656
+ expect(uorpt).to receive(:format_wounded_ext).with(event)
657
+ .and_return(' k')
658
+
659
+ expect(uorpt.send(:format_wounded, event)).to be_an_instance_of String
660
+ end
661
+ end
662
+
663
+ context 'when @level is :full' do
664
+ before do
665
+ uorpt.instance_variable_set(:@level, :full)
666
+ allow(uorpt).to receive(:format_wounded_ext).and_return(' k')
667
+ end
668
+
669
+ subject { uorpt.send(:format_wounded, event) }
670
+
671
+ it { should be_an_instance_of String }
672
+
673
+ it { should eql "zt x (b) has been wounded by y (o) k\"\n" }
674
+
675
+ it 'should call .format_wounded_ext' do
676
+ expect(uorpt).to receive(:format_wounded_ext).with(event)
677
+ .and_return(' k')
678
+
679
+ expect(uorpt.send(:format_wounded, event)).to be_an_instance_of String
680
+ end
681
+ end
682
+ end
683
+
684
+ describe '.format' do
685
+ context 'when given more than two args' do
686
+ it 'should raise ArgumentError' do
687
+ expect do
688
+ uorpt.format(nil, nil, nil)
689
+ end.to raise_error ArgumentError
690
+ end
691
+ end
692
+
693
+ context 'when given less than one arg' do
694
+ it 'should raise ArgumentError' do
695
+ expect do
696
+ uorpt.format
697
+ end.to raise_error ArgumentError
698
+ end
699
+ end
700
+
701
+ context 'always' do
702
+ it 'should call .validate_and_set_level' do
703
+ expect(uorpt).to receive(:validate_and_set_level).with(:ohai)
704
+ .and_return(nil)
705
+ uorpt.format({ type: :x }, :ohai)
706
+ end
707
+ end
708
+
709
+ context 'when a :wounded event' do
710
+ let(:event) { { type: :wounded } }
711
+
712
+ it 'should call format_wounded with the event' do
713
+ expect(uorpt).to receive(:format_wounded).with(event)
714
+ .and_return(:hello)
715
+ expect(uorpt.format(event)).to eql :hello
716
+ end
717
+ end
718
+
719
+ context 'when a :killed event' do
720
+ let(:event) { { type: :killed } }
721
+
722
+ it 'should call format_killed with the event' do
723
+ expect(uorpt).to receive(:format_killed).with(event)
724
+ .and_return(:hullo)
725
+ expect(uorpt.format(event)).to eql :hullo
726
+ end
727
+ end
728
+
729
+ context 'when a :died event' do
730
+ let(:event) { { type: :died } }
731
+
732
+ it 'should call format_died with the event' do
733
+ expect(uorpt).to receive(:format_died).with(event)
734
+ .and_return(:hallo)
735
+ expect(uorpt.format(event)).to eql :hallo
736
+ end
737
+ end
738
+
739
+ context 'when an :announcement event' do
740
+ let(:event) { { type: :announcement } }
741
+
742
+ it 'should call format_announcement with the event' do
743
+ expect(uorpt).to receive(:format_announcement).with(event)
744
+ .and_return(:ugh)
745
+ expect(uorpt.format(event)).to eql :ugh
746
+ end
747
+ end
748
+
749
+ context 'when an :unknown event' do
750
+ let(:event) { { type: :something } }
751
+
752
+ subject { uorpt.format(event) }
753
+
754
+ it { should be_nil }
755
+ end
756
+ end
757
+ end