overrides_tracker 0.1.9 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,965 @@
1
+ require 'spec_helper'
2
+
3
+ describe OverridesTracker::Comparer do
4
+ let(:obj) { OverridesTracker::Comparer }
5
+ let(:file_one_hash) { {} }
6
+ let(:file_two_hash) { {} }
7
+
8
+ before do
9
+ allow(Dir).to receive(:entries).and_return(['.', '..', 'file_one.otf', 'file_two.otf'])
10
+ allow(OverridesTracker::MethodsCollector.instance).to receive(:load_from_file).with('file_one.otf').once.and_return(file_one_hash)
11
+ allow(OverridesTracker::MethodsCollector.instance).to receive(:load_from_file).with('file_two.otf').once.and_return(file_two_hash)
12
+ end
13
+
14
+ describe '#compare' do
15
+ context 'on instance_methods' do
16
+ context 'when nothing diverges' do
17
+ let(:file_one_hash) do
18
+ {
19
+ 'methods_collection': {
20
+ "ClassADifferentSources": {
21
+ "instance_methods": {
22
+ "method_one": {
23
+ "sha": 'aaa',
24
+ "overriding_sha": '376988d98a7069f2a2914a4544d4e2d1d519f345',
25
+ "location": [
26
+ '/gem/models/class_a.rb',
27
+ 7
28
+ ],
29
+ "body": "def method_one\n master_original_implementation\nend\n",
30
+ "overriding_location": [
31
+ '/app/models/class_a.rb',
32
+ 7
33
+ ],
34
+ "overriding_body": "def method_one\n master_override\nend\n"
35
+ }
36
+ }
37
+ }
38
+ },
39
+ 'working_directory': Dir.pwd,
40
+ 'bundle_path': Bundler.bundle_path.to_s
41
+ }
42
+ end
43
+
44
+ let(:file_two_hash) do
45
+ {
46
+ 'methods_collection': { "ClassADifferentSources": {
47
+ "instance_methods": {
48
+ "method_one": {
49
+ "sha": 'aaa',
50
+ "overriding_sha": '376988d98a7069f2a2914a4544d4e2d1d519f345',
51
+ "location": [
52
+ '/gem/models/class_a.rb',
53
+ 7
54
+ ],
55
+ "body": "def method_one\n master_original_implementation\nend\n",
56
+ "overriding_location": [
57
+ '/app/models/class_a.rb',
58
+ 7
59
+ ],
60
+ "overriding_body": "def method_one\n master_override\nend\n"
61
+ }
62
+ }
63
+ } },
64
+ 'working_directory': Dir.pwd,
65
+ 'bundle_path': Bundler.bundle_path.to_s
66
+ }
67
+ end
68
+
69
+ it 'should find 0 changes' do
70
+ result = obj.compare
71
+ expect(result[:numbers]).to eq({
72
+ overrides: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0,
73
+ method_not_override_count: 0, total: 0 }, added_methods: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 0 }, total: 0
74
+ })
75
+ end
76
+ end
77
+
78
+ context 'when original source diverge' do
79
+ let(:file_one_hash) do
80
+ {
81
+ 'working_directory': Dir.pwd,
82
+ 'bundle_path': Bundler.bundle_path.to_s,
83
+ 'methods_collection': { "ClassADifferentSources": {
84
+ "instance_methods": {
85
+ "method_one": {
86
+ "sha": 'aaa',
87
+ "overriding_sha": '376988d98a7069f2a2914a4544d4e2d1d519f345',
88
+ "location": [
89
+ '/gem/models/class_a.rb',
90
+ 7
91
+ ],
92
+ "body": "def method_one\n master_original_implementation\nend\n",
93
+ "overriding_location": [
94
+ '/app/models/class_a.rb',
95
+ 7
96
+ ],
97
+ "overriding_body": "def method_one\n master_override\nend\n"
98
+ }
99
+ }
100
+ } }
101
+ }
102
+ end
103
+
104
+ let(:file_two_hash) do
105
+ {
106
+ 'working_directory': Dir.pwd,
107
+ 'bundle_path': Bundler.bundle_path.to_s,
108
+ 'methods_collection': { "ClassADifferentSources": {
109
+ "instance_methods": {
110
+ "method_one": {
111
+ "sha": 'bbb',
112
+ "overriding_sha": '376988d98a7069f2a2914a4544d4e2d1d519f345',
113
+ "location": [
114
+ '/gem/models/class_a.rb',
115
+ 7
116
+ ],
117
+ "body": "def method_one\n other_original_implementation\nend\n",
118
+ "overriding_location": [
119
+ '/app/models/class_a.rb',
120
+ 7
121
+ ],
122
+ "overriding_body": "def method_one\n other_override\nend\n"
123
+ }
124
+ }
125
+ } }
126
+ }
127
+ end
128
+
129
+ it 'should find 2 source changes' do
130
+ result = obj.compare
131
+
132
+ expect(result[:numbers]).to eq({
133
+ overrides: { source_changed_count: 2, override_changed_count: 0, method_not_available_count: 0,
134
+ method_not_override_count: 0, total: 2 }, added_methods: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 0 }, total: 2
135
+ })
136
+ end
137
+ end
138
+
139
+ context 'when overrides diverge' do
140
+ let(:file_one_hash) do
141
+ {
142
+ 'working_directory': Dir.pwd,
143
+ 'bundle_path': Bundler.bundle_path.to_s,
144
+ 'methods_collection': { "ClassADifferentSources": {
145
+ "instance_methods": {
146
+ "method_one": {
147
+ "sha": 'aaa',
148
+ "overriding_sha": '111',
149
+ "location": [
150
+ '/gem/models/class_a.rb',
151
+ 7
152
+ ],
153
+ "body": "def method_one\n master_original_implementation\nend\n",
154
+ "overriding_location": [
155
+ '/app/models/class_a.rb',
156
+ 7
157
+ ],
158
+ "overriding_body": "def method_one\n master_override\nend\n"
159
+ }
160
+ }
161
+ } }
162
+ }
163
+ end
164
+
165
+ let(:file_two_hash) do
166
+ {
167
+ 'working_directory': Dir.pwd,
168
+ 'bundle_path': Bundler.bundle_path.to_s,
169
+ 'methods_collection': { "ClassADifferentSources": {
170
+ "instance_methods": {
171
+ "method_one": {
172
+ "sha": 'aaa',
173
+ "overriding_sha": '222',
174
+ "location": [
175
+ '/gem/models/class_a.rb',
176
+ 7
177
+ ],
178
+ "body": "def method_one\n other_original_implementation\nend\n",
179
+ "overriding_location": [
180
+ '/app/models/class_a.rb',
181
+ 7
182
+ ],
183
+ "overriding_body": "def method_one\n other_override\nend\n"
184
+ }
185
+ }
186
+ } }
187
+ }
188
+ end
189
+
190
+ it 'should find 2 override changes' do
191
+ result = obj.compare
192
+
193
+ expect(result[:numbers]).to eq({
194
+ overrides: { source_changed_count: 0, override_changed_count: 2, method_not_available_count: 0,
195
+ method_not_override_count: 0, total: 2 }, added_methods: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 0 }, total: 2
196
+ })
197
+ end
198
+ end
199
+
200
+ context 'when one becomes a added_method' do
201
+ let(:file_one_hash) do
202
+ {
203
+ 'working_directory': Dir.pwd,
204
+ 'bundle_path': Bundler.bundle_path.to_s,
205
+ 'methods_collection': { "ClassADifferentSources": {
206
+ "instance_methods": {
207
+ "method_one": {
208
+ "sha": 'aaa',
209
+ "overriding_sha": '376988d98a7069f2a2914a4544d4e2d1d519f345',
210
+ "location": [
211
+ '/gem/models/class_a.rb',
212
+ 7
213
+ ],
214
+ "body": "def method_one\n master_original_implementation\nend\n",
215
+ "overriding_location": [
216
+ '/app/models/class_a.rb',
217
+ 7
218
+ ],
219
+ "overriding_body": "def method_one\n master_override\nend\n"
220
+ }
221
+ }
222
+ } }
223
+ }
224
+ end
225
+
226
+ let(:file_two_hash) do
227
+ {
228
+ 'working_directory': Dir.pwd,
229
+ 'bundle_path': Bundler.bundle_path.to_s,
230
+ 'methods_collection': { "ClassADifferentSources": {
231
+ "added_instance_methods": {
232
+ "method_one": {
233
+ "sha": '376988d98a7069f2a2914a4544d4e2d1d519f345',
234
+ "location": [
235
+ '/app/models/class_a.rb',
236
+ 7
237
+ ],
238
+ "body": "def method_one\n master_override\nend\n"
239
+ }
240
+ }
241
+ } }
242
+ }
243
+ end
244
+
245
+ it 'should find 0 changes' do
246
+ result = obj.compare
247
+
248
+ expect(result[:numbers]).to eq({
249
+ overrides: { source_changed_count: 0, override_changed_count: 1, method_not_available_count: 0,
250
+ method_not_override_count: 1, total: 2 }, added_methods: { source_changed_count: 1, override_changed_count: 0, method_not_available_count: 1, method_not_override_count: 0, total: 2 }, total: 4
251
+ })
252
+ end
253
+ end
254
+
255
+ context 'when a whole override class is missing' do
256
+ let(:file_one_hash) do
257
+ {
258
+ 'working_directory': Dir.pwd,
259
+ 'bundle_path': Bundler.bundle_path.to_s,
260
+ 'methods_collection': { "ClassADifferentSources": {
261
+ "instance_methods": {
262
+ "method_one": {
263
+ "sha": 'aaa',
264
+ "overriding_sha": '111',
265
+ "location": [
266
+ '/gem/models/class_a.rb',
267
+ 7
268
+ ],
269
+ "body": "def method_one\n master_original_implementation\nend\n",
270
+ "overriding_location": [
271
+ '/app/models/class_a.rb',
272
+ 7
273
+ ],
274
+ "overriding_body": "def method_one\n master_override\nend\n"
275
+ }
276
+ }
277
+ } }
278
+ }
279
+ end
280
+
281
+ let(:file_two_hash) do
282
+ { 'working_directory': Dir.pwd,
283
+ 'bundle_path': Bundler.bundle_path.to_s,
284
+ 'methods_collection': {} }
285
+ end
286
+
287
+ it 'should find 1 override_change and 1 method_not_available' do
288
+ result = obj.compare
289
+ expect(result[:numbers]).to eq({
290
+ overrides: { source_changed_count: 0, override_changed_count: 1, method_not_available_count: 1,
291
+ method_not_override_count: 0, total: 2 }, added_methods: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 0 }, total: 2
292
+ })
293
+ end
294
+ end
295
+
296
+ context 'when a override method is missing' do
297
+ let(:file_one_hash) do
298
+ {
299
+ 'working_directory': Dir.pwd,
300
+ 'bundle_path': Bundler.bundle_path.to_s,
301
+ 'methods_collection': { "ClassADifferentSources": {
302
+ "instance_methods": {}
303
+ } }
304
+ }
305
+ end
306
+
307
+ let(:file_two_hash) do
308
+ {
309
+ 'working_directory': Dir.pwd,
310
+ 'bundle_path': Bundler.bundle_path.to_s,
311
+ 'methods_collection': { "ClassADifferentSources": {
312
+ "instance_methods": {
313
+ "method_one": {
314
+ "sha": 'aaa',
315
+ "overriding_sha": '222',
316
+ "location": [
317
+ '/gem/models/class_a.rb',
318
+ 7
319
+ ],
320
+ "body": "def method_one\n other_original_implementation\nend\n",
321
+ "overriding_location": [
322
+ '/app/models/class_a.rb',
323
+ 7
324
+ ],
325
+ "overriding_body": "def method_one\n other_override\nend\n"
326
+ }
327
+ }
328
+ } }
329
+ }
330
+ end
331
+
332
+ it 'should find 1 override_change and 1 method_not_available' do
333
+ result = obj.compare
334
+
335
+ expect(result[:numbers]).to eq({
336
+ overrides: { source_changed_count: 0, override_changed_count: 1, method_not_available_count: 1,
337
+ method_not_override_count: 0, total: 2 }, added_methods: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 0 }, total: 2
338
+ })
339
+ end
340
+ end
341
+ end
342
+
343
+ context 'on singleton_methods' do
344
+ context 'when nothing diverges' do
345
+ let(:file_one_hash) do
346
+ {
347
+ 'working_directory': Dir.pwd,
348
+ 'bundle_path': Bundler.bundle_path.to_s,
349
+ 'methods_collection': { "ClassADifferentSources": {
350
+ "singleton_methods": {
351
+ "method_one": {
352
+ "sha": 'aaa',
353
+ "overriding_sha": '376988d98a7069f2a2914a4544d4e2d1d519f345',
354
+ "location": [
355
+ '/gem/models/class_a.rb',
356
+ 7
357
+ ],
358
+ "body": "def method_one\n master_original_implementation\nend\n",
359
+ "overriding_location": [
360
+ '/app/models/class_a.rb',
361
+ 7
362
+ ],
363
+ "overriding_body": "def method_one\n master_override\nend\n"
364
+ }
365
+ }
366
+ } }
367
+ }
368
+ end
369
+
370
+ let(:file_two_hash) do
371
+ {
372
+ 'working_directory': Dir.pwd,
373
+ 'bundle_path': Bundler.bundle_path.to_s,
374
+ 'methods_collection': { "ClassADifferentSources": {
375
+ "singleton_methods": {
376
+ "method_one": {
377
+ "sha": 'aaa',
378
+ "overriding_sha": '376988d98a7069f2a2914a4544d4e2d1d519f345',
379
+ "location": [
380
+ '/gem/models/class_a.rb',
381
+ 7
382
+ ],
383
+ "body": "def method_one\n master_original_implementation\nend\n",
384
+ "overriding_location": [
385
+ '/app/models/class_a.rb',
386
+ 7
387
+ ],
388
+ "overriding_body": "def method_one\n master_override\nend\n"
389
+ }
390
+ }
391
+ } }
392
+ }
393
+ end
394
+
395
+ it 'should find 0 changes' do
396
+ result = obj.compare
397
+
398
+ expect(result[:numbers]).to eq({
399
+ overrides: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0,
400
+ method_not_override_count: 0, total: 0 }, added_methods: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 0 }, total: 0
401
+ })
402
+ end
403
+ end
404
+
405
+ context 'when original source diverge' do
406
+ let(:file_one_hash) do
407
+ {
408
+ 'working_directory': Dir.pwd,
409
+ 'bundle_path': Bundler.bundle_path.to_s,
410
+ 'methods_collection': { "ClassADifferentSources": {
411
+ "singleton_methods": {
412
+ "method_one": {
413
+ "sha": 'aaa',
414
+ "overriding_sha": '376988d98a7069f2a2914a4544d4e2d1d519f345',
415
+ "location": [
416
+ '/gem/models/class_a.rb',
417
+ 7
418
+ ],
419
+ "body": "def method_one\n master_original_implementation\nend\n",
420
+ "overriding_location": [
421
+ '/app/models/class_a.rb',
422
+ 7
423
+ ],
424
+ "overriding_body": "def method_one\n master_override\nend\n"
425
+ }
426
+ }
427
+ } }
428
+ }
429
+ end
430
+
431
+ let(:file_two_hash) do
432
+ {
433
+ 'working_directory': Dir.pwd,
434
+ 'bundle_path': Bundler.bundle_path.to_s,
435
+ 'methods_collection': { "ClassADifferentSources": {
436
+ "singleton_methods": {
437
+ "method_one": {
438
+ "sha": 'bbb',
439
+ "overriding_sha": '376988d98a7069f2a2914a4544d4e2d1d519f345',
440
+ "location": [
441
+ '/gem/models/class_a.rb',
442
+ 7
443
+ ],
444
+ "body": "def method_one\n other_original_implementation\nend\n",
445
+ "overriding_location": [
446
+ '/app/models/class_a.rb',
447
+ 7
448
+ ],
449
+ "overriding_body": "def method_one\n other_override\nend\n"
450
+ }
451
+ }
452
+ } }
453
+ }
454
+ end
455
+
456
+ it 'should find 2 source changes' do
457
+ result = obj.compare
458
+
459
+ expect(result[:numbers]).to eq({
460
+ overrides: { source_changed_count: 2, override_changed_count: 0, method_not_available_count: 0,
461
+ method_not_override_count: 0, total: 2 }, added_methods: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 0 }, total: 2
462
+ })
463
+ end
464
+ end
465
+
466
+ context 'when overrides diverge' do
467
+ let(:file_one_hash) do
468
+ {
469
+ 'working_directory': Dir.pwd,
470
+ 'bundle_path': Bundler.bundle_path.to_s,
471
+ 'methods_collection': { "ClassADifferentSources": {
472
+ "singleton_methods": {
473
+ "method_one": {
474
+ "sha": 'aaa',
475
+ "overriding_sha": '111',
476
+ "location": [
477
+ '/gem/models/class_a.rb',
478
+ 7
479
+ ],
480
+ "body": "def method_one\n master_original_implementation\nend\n",
481
+ "overriding_location": [
482
+ '/app/models/class_a.rb',
483
+ 7
484
+ ],
485
+ "overriding_body": "def method_one\n master_override\nend\n"
486
+ }
487
+ }
488
+ } }
489
+ }
490
+ end
491
+
492
+ let(:file_two_hash) do
493
+ {
494
+ 'working_directory': Dir.pwd,
495
+ 'bundle_path': Bundler.bundle_path.to_s,
496
+ 'methods_collection': { "ClassADifferentSources": {
497
+ "singleton_methods": {
498
+ "method_one": {
499
+ "sha": 'aaa',
500
+ "overriding_sha": '222',
501
+ "location": [
502
+ '/gem/models/class_a.rb',
503
+ 7
504
+ ],
505
+ "body": "def method_one\n other_original_implementation\nend\n",
506
+ "overriding_location": [
507
+ '/app/models/class_a.rb',
508
+ 7
509
+ ],
510
+ "overriding_body": "def method_one\n other_override\nend\n"
511
+ }
512
+ }
513
+ } }
514
+ }
515
+ end
516
+
517
+ it 'should find 2 override changes' do
518
+ result = obj.compare
519
+
520
+ expect(result[:numbers]).to eq({
521
+ overrides: { source_changed_count: 0, override_changed_count: 2, method_not_available_count: 0,
522
+ method_not_override_count: 0, total: 2 }, added_methods: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 0 }, total: 2
523
+ })
524
+ end
525
+ end
526
+
527
+ context 'when a whole override class is missing' do
528
+ let(:file_one_hash) do
529
+ {
530
+ 'working_directory': Dir.pwd,
531
+ 'bundle_path': Bundler.bundle_path.to_s,
532
+ 'methods_collection': { "ClassADifferentSources": {
533
+ "singleton_methods": {
534
+ "method_one": {
535
+ "sha": 'aaa',
536
+ "overriding_sha": '111',
537
+ "location": [
538
+ '/gem/models/class_a.rb',
539
+ 7
540
+ ],
541
+ "body": "def method_one\n master_original_implementation\nend\n",
542
+ "overriding_location": [
543
+ '/app/models/class_a.rb',
544
+ 7
545
+ ],
546
+ "overriding_body": "def method_one\n master_override\nend\n"
547
+ }
548
+ }
549
+ } }
550
+ }
551
+ end
552
+
553
+ let(:file_two_hash) do
554
+ { 'working_directory': Dir.pwd,
555
+ 'bundle_path': Bundler.bundle_path.to_s,
556
+ 'methods_collection': {} }
557
+ end
558
+
559
+ it 'should find 1 override_change and 1 method_not_available' do
560
+ result = obj.compare
561
+ expect(result[:numbers]).to eq({
562
+ overrides: { source_changed_count: 0, override_changed_count: 1, method_not_available_count: 1,
563
+ method_not_override_count: 0, total: 2 }, added_methods: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 0 }, total: 2
564
+ })
565
+ end
566
+ end
567
+
568
+ context 'when a override method is missing' do
569
+ let(:file_one_hash) do
570
+ {
571
+ 'working_directory': Dir.pwd,
572
+ 'bundle_path': Bundler.bundle_path.to_s,
573
+ 'methods_collection': { "ClassADifferentSources": {
574
+ "singleton_methods": {}
575
+ } }
576
+ }
577
+ end
578
+
579
+ let(:file_two_hash) do
580
+ {
581
+ 'working_directory': Dir.pwd,
582
+ 'bundle_path': Bundler.bundle_path.to_s,
583
+ 'methods_collection': { "ClassADifferentSources": {
584
+ "singleton_methods": {
585
+ "method_one": {
586
+ "sha": 'aaa',
587
+ "overriding_sha": '222',
588
+ "location": [
589
+ '/gem/models/class_a.rb',
590
+ 7
591
+ ],
592
+ "body": "def method_one\n other_original_implementation\nend\n",
593
+ "overriding_location": [
594
+ '/app/models/class_a.rb',
595
+ 7
596
+ ],
597
+ "overriding_body": "def method_one\n other_override\nend\n"
598
+ }
599
+ }
600
+ } }
601
+ }
602
+ end
603
+
604
+ it 'should find 1 override_change and 1 method_not_available' do
605
+ result = obj.compare
606
+
607
+ expect(result[:numbers]).to eq({
608
+ overrides: { source_changed_count: 0, override_changed_count: 1, method_not_available_count: 1,
609
+ method_not_override_count: 0, total: 2 }, added_methods: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 0 }, total: 2
610
+ })
611
+ end
612
+ end
613
+ end
614
+
615
+ context 'on added_instance_methods' do
616
+ context 'when nothing diverges' do
617
+ let(:file_one_hash) do
618
+ {
619
+ 'working_directory': Dir.pwd,
620
+ 'bundle_path': Bundler.bundle_path.to_s,
621
+ 'methods_collection': { "ClassADifferentSources": {
622
+ "added_instance_methods": {
623
+ "method_one": {
624
+ "sha": 'aaa',
625
+ "location": [
626
+ '/gem/models/class_a.rb',
627
+ 7
628
+ ],
629
+ "body": "def method_one\n master_original_implementation\nend\n"
630
+ }
631
+ }
632
+ } }
633
+ }
634
+ end
635
+
636
+ let(:file_two_hash) do
637
+ {
638
+ 'working_directory': Dir.pwd,
639
+ 'bundle_path': Bundler.bundle_path.to_s,
640
+ 'methods_collection': { "ClassADifferentSources": {
641
+ "added_instance_methods": {
642
+ "method_one": {
643
+ "sha": 'aaa',
644
+ "location": [
645
+ '/gem/models/class_a.rb',
646
+ 7
647
+ ],
648
+ "body": "def method_one\n master_original_implementation\nend\n"
649
+ }
650
+ }
651
+ } }
652
+ }
653
+ end
654
+
655
+ it 'should find 0 changes' do
656
+ result = obj.compare
657
+
658
+ expect(result[:numbers]).to eq({
659
+ overrides: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0,
660
+ method_not_override_count: 0, total: 0 }, added_methods: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 0 }, total: 0
661
+ })
662
+ end
663
+ end
664
+
665
+ context 'when original source diverge' do
666
+ let(:file_one_hash) do
667
+ {
668
+ 'working_directory': Dir.pwd,
669
+ 'bundle_path': Bundler.bundle_path.to_s,
670
+ 'methods_collection': { "ClassADifferentSources": {
671
+ "added_instance_methods": {
672
+ "method_one": {
673
+ "sha": 'aaa',
674
+ "location": [
675
+ '/gem/models/class_a.rb',
676
+ 7
677
+ ],
678
+ "body": "def method_one\n master_original_implementation\nend\n"
679
+ }
680
+ }
681
+ } }
682
+ }
683
+ end
684
+
685
+ let(:file_two_hash) do
686
+ {
687
+ 'working_directory': Dir.pwd,
688
+ 'bundle_path': Bundler.bundle_path.to_s,
689
+ 'methods_collection': { "ClassADifferentSources": {
690
+ "added_instance_methods": {
691
+ "method_one": {
692
+ "sha": 'bbb',
693
+ "location": [
694
+ '/gem/models/class_a.rb',
695
+ 7
696
+ ],
697
+ "body": "def method_one\n other_original_implementation\nend\n"
698
+ }
699
+ }
700
+ } }
701
+ }
702
+ end
703
+
704
+ it 'should find 2 source changes' do
705
+ result = obj.compare
706
+
707
+ expect(result[:numbers]).to eq({
708
+ overrides: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0,
709
+ method_not_override_count: 0, total: 0 }, added_methods: { source_changed_count: 2, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 2 }, total: 2
710
+ })
711
+ end
712
+ end
713
+
714
+ context 'when a whole added class is missing' do
715
+ let(:file_one_hash) do
716
+ {
717
+ 'working_directory': Dir.pwd,
718
+ 'bundle_path': Bundler.bundle_path.to_s,
719
+ 'methods_collection': { "ClassADifferentSources": {
720
+ "added_instance_methods": {
721
+ "method_one": {
722
+ "sha": 'aaa',
723
+ "location": [
724
+ '/gem/models/class_a.rb',
725
+ 7
726
+ ],
727
+ "body": "def method_one\n master_original_implementation\nend\n"
728
+ }
729
+ }
730
+ } }
731
+ }
732
+ end
733
+
734
+ let(:file_two_hash) do
735
+ { 'working_directory': Dir.pwd,
736
+ 'bundle_path': Bundler.bundle_path.to_s,
737
+ 'methods_collection': {} }
738
+ end
739
+
740
+ it 'should find 1 source_change and 1 method_not_available' do
741
+ result = obj.compare
742
+ expect(result[:numbers]).to eq({
743
+ overrides: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0,
744
+ method_not_override_count: 0, total: 0 }, added_methods: { source_changed_count: 1, override_changed_count: 0, method_not_available_count: 1, method_not_override_count: 0, total: 2 }, total: 2
745
+ })
746
+ end
747
+ end
748
+
749
+ context 'when a override method is missing' do
750
+ let(:file_one_hash) do
751
+ {
752
+ 'working_directory': Dir.pwd,
753
+ 'bundle_path': Bundler.bundle_path.to_s,
754
+ 'methods_collection': { "ClassADifferentSources": {
755
+ "added_instance_methods": {}
756
+ } }
757
+ }
758
+ end
759
+
760
+ let(:file_two_hash) do
761
+ {
762
+ 'working_directory': Dir.pwd,
763
+ 'bundle_path': Bundler.bundle_path.to_s,
764
+ 'methods_collection': { "ClassADifferentSources": {
765
+ "added_instance_methods": {
766
+ "method_one": {
767
+ "sha": 'aaa',
768
+ "location": [
769
+ '/gem/models/class_a.rb',
770
+ 7
771
+ ],
772
+ "body": "def method_one\n other_original_implementation\nend\n"
773
+ }
774
+ }
775
+ } }
776
+ }
777
+ end
778
+
779
+ it 'should find 1 souce_change and 1 method_not_available' do
780
+ result = obj.compare
781
+
782
+ expect(result[:numbers]).to eq({
783
+ overrides: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0,
784
+ method_not_override_count: 0, total: 0 }, added_methods: { source_changed_count: 1, override_changed_count: 0, method_not_available_count: 1, method_not_override_count: 0, total: 2 }, total: 2
785
+ })
786
+ end
787
+ end
788
+ end
789
+
790
+ context 'on added_singleton_methods' do
791
+ context 'when nothing diverges' do
792
+ let(:file_one_hash) do
793
+ {
794
+ 'working_directory': Dir.pwd,
795
+ 'bundle_path': Bundler.bundle_path.to_s,
796
+ 'methods_collection': { "ClassADifferentSources": {
797
+ "added_singleton_methods": {
798
+ "method_one": {
799
+ "sha": 'aaa',
800
+ "location": [
801
+ '/gem/models/class_a.rb',
802
+ 7
803
+ ],
804
+ "body": "def method_one\n master_original_implementation\nend\n"
805
+ }
806
+ }
807
+ } }
808
+ }
809
+ end
810
+
811
+ let(:file_two_hash) do
812
+ {
813
+ 'working_directory': Dir.pwd,
814
+ 'bundle_path': Bundler.bundle_path.to_s,
815
+ 'methods_collection': { "ClassADifferentSources": {
816
+ "added_singleton_methods": {
817
+ "method_one": {
818
+ "sha": 'aaa',
819
+ "location": [
820
+ '/gem/models/class_a.rb',
821
+ 7
822
+ ],
823
+ "body": "def method_one\n master_original_implementation\nend\n"
824
+ }
825
+ }
826
+ } }
827
+ }
828
+ end
829
+
830
+ it 'should find 0 changes' do
831
+ result = obj.compare
832
+
833
+ expect(result[:numbers]).to eq({
834
+ overrides: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0,
835
+ method_not_override_count: 0, total: 0 }, added_methods: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 0 }, total: 0
836
+ })
837
+ end
838
+ end
839
+
840
+ context 'when original source diverge' do
841
+ let(:file_one_hash) do
842
+ {
843
+ 'working_directory': Dir.pwd,
844
+ 'bundle_path': Bundler.bundle_path.to_s,
845
+ 'methods_collection': { "ClassADifferentSources": {
846
+ "added_singleton_methods": {
847
+ "method_one": {
848
+ "sha": 'aaa',
849
+ "location": [
850
+ '/gem/models/class_a.rb',
851
+ 7
852
+ ],
853
+ "body": "def method_one\n master_original_implementation\nend\n"
854
+ }
855
+ }
856
+ } }
857
+ }
858
+ end
859
+
860
+ let(:file_two_hash) do
861
+ {
862
+ 'working_directory': Dir.pwd,
863
+ 'bundle_path': Bundler.bundle_path.to_s,
864
+ 'methods_collection': { "ClassADifferentSources": {
865
+ "added_singleton_methods": {
866
+ "method_one": {
867
+ "sha": 'bbb',
868
+ "location": [
869
+ '/gem/models/class_a.rb',
870
+ 7
871
+ ],
872
+ "body": "def method_one\n other_original_implementation\nend\n"
873
+ }
874
+ }
875
+ } }
876
+ }
877
+ end
878
+
879
+ it 'should find 2 source changes' do
880
+ result = obj.compare
881
+
882
+ expect(result[:numbers]).to eq({
883
+ overrides: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0,
884
+ method_not_override_count: 0, total: 0 }, added_methods: { source_changed_count: 2, override_changed_count: 0, method_not_available_count: 0, method_not_override_count: 0, total: 2 }, total: 2
885
+ })
886
+ end
887
+ end
888
+
889
+ context 'when a whole added class is missing' do
890
+ let(:file_one_hash) do
891
+ {
892
+ 'working_directory': Dir.pwd,
893
+ 'bundle_path': Bundler.bundle_path.to_s,
894
+ 'methods_collection': { "ClassADifferentSources": {
895
+ "added_singleton_methods": {
896
+ "method_one": {
897
+ "sha": 'aaa',
898
+ "location": [
899
+ '/gem/models/class_a.rb',
900
+ 7
901
+ ],
902
+ "body": "def method_one\n master_original_implementation\nend\n"
903
+ }
904
+ }
905
+ } }
906
+ }
907
+ end
908
+
909
+ let(:file_two_hash) do
910
+ { 'working_directory': Dir.pwd,
911
+ 'bundle_path': Bundler.bundle_path.to_s,
912
+ 'methods_collection': {} }
913
+ end
914
+
915
+ it 'should find 1 source_change and 1 method_not_available' do
916
+ result = obj.compare
917
+ expect(result[:numbers]).to eq({
918
+ overrides: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0,
919
+ method_not_override_count: 0, total: 0 }, added_methods: { source_changed_count: 1, override_changed_count: 0, method_not_available_count: 1, method_not_override_count: 0, total: 2 }, total: 2
920
+ })
921
+ end
922
+ end
923
+
924
+ context 'when a override method is missing' do
925
+ let(:file_one_hash) do
926
+ {
927
+ 'working_directory': Dir.pwd,
928
+ 'bundle_path': Bundler.bundle_path.to_s,
929
+ 'methods_collection': { "ClassADifferentSources": {
930
+ "added_singleton_methods": {}
931
+ } }
932
+ }
933
+ end
934
+
935
+ let(:file_two_hash) do
936
+ {
937
+ 'working_directory': Dir.pwd,
938
+ 'bundle_path': Bundler.bundle_path.to_s,
939
+ 'methods_collection': { "ClassADifferentSources": {
940
+ "added_singleton_methods": {
941
+ "method_one": {
942
+ "sha": 'aaa',
943
+ "location": [
944
+ '/gem/models/class_a.rb',
945
+ 7
946
+ ],
947
+ "body": "def method_one\n other_original_implementation\nend\n"
948
+ }
949
+ }
950
+ } }
951
+ }
952
+ end
953
+
954
+ it 'should find 1 souce_change and 1 method_not_available' do
955
+ result = obj.compare
956
+
957
+ expect(result[:numbers]).to eq({
958
+ overrides: { source_changed_count: 0, override_changed_count: 0, method_not_available_count: 0,
959
+ method_not_override_count: 0, total: 0 }, added_methods: { source_changed_count: 1, override_changed_count: 0, method_not_available_count: 1, method_not_override_count: 0, total: 2 }, total: 2
960
+ })
961
+ end
962
+ end
963
+ end
964
+ end
965
+ end