overrides_tracker 0.1.12 → 0.1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +20 -0
- data/Gemfile.lock +109 -0
- data/README.md +83 -38
- data/lib/external/require_all.rb +252 -0
- data/lib/overrides_tracker/comparer.rb +9 -5
- data/lib/overrides_tracker/hash_decorator.rb +41 -0
- data/lib/overrides_tracker/version.rb +1 -1
- data/overrides_tracker/branch_name#last_commit_id.otf +1 -0
- data/overrides_tracker.gemspec +2 -2
- data/spec/overrides_tracker/api_spec.rb +227 -0
- data/spec/overrides_tracker/comparer_spec.rb +965 -0
- data/spec/overrides_tracker/file_observer_spec.rb +10 -0
- data/spec/overrides_tracker/hash_decorator_spec.rb +42 -0
- data/spec/overrides_tracker/methods_collector_spec.rb +336 -0
- data/spec/overrides_tracker/string_colorizer_spec.rb +73 -0
- data/spec/overrides_tracker/util_spec.rb +58 -0
- data/spec/overrides_tracker/version_spec.rb +9 -0
- data/spec/result_files/master.otf +134 -0
- data/spec/test_classes/custom_class.rb +31 -0
- metadata +21 -6
@@ -0,0 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require_relative '../test_classes/custom_class'
|
5
|
+
|
6
|
+
describe OverridesTracker::FileObserver do
|
7
|
+
it 'calls the method overrides_tracker_finished_file when the file is finished' do
|
8
|
+
expect(CustomClass.instance_variable_get(:@overrides_tracker_finished_file_called)).to eq(true)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require 'overrides_tracker/hash_decorator'
|
5
|
+
|
6
|
+
describe Hash do
|
7
|
+
describe '#deep_merge' do
|
8
|
+
let(:hash) { { a: 1, b: { c: 2 } } }
|
9
|
+
let(:other_hash) { { a: 3, b: { d: 4 } } }
|
10
|
+
|
11
|
+
it 'returns a new hash with the contents of both hashes merged' do
|
12
|
+
expect(hash.deep_merge(other_hash)).to eq(a: 3, b: { c: 2, d: 4 })
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'does not modify the original hash' do
|
16
|
+
expect { hash.deep_merge(other_hash) }.not_to change { hash }
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#deep_merge!' do
|
21
|
+
let(:hash) { { a: 1, b: { c: 2 } } }
|
22
|
+
let(:other_hash) { { a: 3, b: { d: 4 } } }
|
23
|
+
|
24
|
+
it 'modifies the original hash with the contents of the other hash merged' do
|
25
|
+
expect { hash.deep_merge!(other_hash) }.to change { hash }.to(a: 3, b: { c: 2, d: 4 })
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '#deep_stringify_keys!' do
|
30
|
+
it 'converts all keys in a hash to strings' do
|
31
|
+
hash = { a: 1, b: { c: 2, d: 3 } }
|
32
|
+
hash.deep_stringify_keys!
|
33
|
+
expect(hash).to eq({ 'a' => 1, 'b' => { 'c' => 2, 'd' => 3 } })
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'converts all keys in an array of hashes to strings' do
|
37
|
+
array = { a: [{ a: 1, b: 2 }, { c: 3, d: 4 }] }
|
38
|
+
array.deep_stringify_keys!
|
39
|
+
expect(array).to eq({ 'a' => [{ 'a' => 1, 'b' => 2 }, { 'c' => 3, 'd' => 4 }] })
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,336 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'spec_helper'
|
3
|
+
require_relative '../test_classes/custom_class'
|
4
|
+
|
5
|
+
|
6
|
+
WORKING_DIR = Dir.pwd
|
7
|
+
|
8
|
+
|
9
|
+
describe OverridesTracker::MethodsCollector do
|
10
|
+
let(:obj) { OverridesTracker::MethodsCollector.instance }
|
11
|
+
|
12
|
+
describe '#add_method_for_class' do
|
13
|
+
let(:method) { CustomClass.instance_method(:instance_test_method) }
|
14
|
+
|
15
|
+
it 'adds the method to the methods collection' do
|
16
|
+
expect(obj.instance_variable_get(:@methods_collection)).to eq(nil)
|
17
|
+
|
18
|
+
obj.add_method_for_class(:instance_methods, 'CustomClass', :instance_test_method, OverridesTracker::Util.method_hash(method))
|
19
|
+
|
20
|
+
expect(obj.instance_variable_get(:@methods_collection)).to eq({"CustomClass" => {:instance_methods=>{:instance_test_method=>{:body=>"def instance_test_method\n 'instance_test_method'\nend\n", :is_part_of_app=>true, :location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 10], :sha=>"3408e1f1736c6b83bc13f014e5338eec0c67393f"}}, :is_part_of_app=>true, :singleton_methods=>{}}})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#mark_method_as_override' do
|
25
|
+
let(:method) { CustomClass.instance_method(:instance_test_method) }
|
26
|
+
let(:overriding_method) { CustomClass.instance_method(:instance_override_test_method) }
|
27
|
+
|
28
|
+
before do
|
29
|
+
obj.instance_variable_set(:@methods_collection, nil)
|
30
|
+
end
|
31
|
+
|
32
|
+
context 'when overriding location is in working directory' do
|
33
|
+
it 'adds the method to the overridden methods collection' do
|
34
|
+
expect(obj.instance_variable_get(:@methods_collection)).to eq(nil)
|
35
|
+
|
36
|
+
obj.add_method_for_class(:instance_methods, 'CustomClass', :instance_test_method, OverridesTracker::Util.method_hash(method))
|
37
|
+
obj.mark_method_as_override(:instance_methods, 'CustomClass', :instance_test_method, overriding_method, OverridesTracker::Util.method_hash(overriding_method))
|
38
|
+
|
39
|
+
expect(obj.instance_variable_get(:@methods_collection)).to eq({"CustomClass" => {:instance_methods=>{:instance_test_method=>{:body=>"def instance_test_method\n 'instance_test_method'\nend\n", :is_part_of_app=>true, :location=>["#{Dir.pwd}/spec/test_classes/custom_class.rb", 10], :overriding_body=>"def instance_override_test_method\n 'instance_override_test_method'\nend\n", :overriding_is_part_of_app=>true, :overriding_location=>["#{Dir.pwd}/spec/test_classes/custom_class.rb", 14], :overriding_sha=>"75cf2b21c3033f33c155a329d8e9110ae3fb0290", :sha=>"3408e1f1736c6b83bc13f014e5338eec0c67393f"}}, :is_part_of_app=>true, :singleton_methods=>{}}})
|
40
|
+
expect(obj.instance_variable_get(:@overridden_methods_collection)).to eq({"CustomClass" => {:added_instance_methods=>{}, :added_singleton_methods=>{}, :instance_methods=>{:instance_test_method=>{:body=>"def instance_test_method\n 'instance_test_method'\nend\n", :is_part_of_app=>true, :location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 10], :overriding_body=>"def instance_override_test_method\n 'instance_override_test_method'\nend\n", :overriding_is_part_of_app=>true, :overriding_location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 14], :overriding_sha=>"75cf2b21c3033f33c155a329d8e9110ae3fb0290", :sha=>"3408e1f1736c6b83bc13f014e5338eec0c67393f"}}, :singleton_methods=>{}}})
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'when overriding location is not in working directory' do
|
45
|
+
let(:overriding_method) { CustomClass.instance_method(:instance_override_test_method) }
|
46
|
+
|
47
|
+
before do
|
48
|
+
@original_dir = Dir.pwd
|
49
|
+
allow(Dir).to receive(:pwd).and_return("another_directory")
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'adds the method to the overridden methods collection' do
|
53
|
+
expect(obj.instance_variable_get(:@methods_collection)).to eq(nil)
|
54
|
+
|
55
|
+
obj.add_method_for_class(:instance_methods, 'CustomClass', :instance_test_method, OverridesTracker::Util.method_hash(method))
|
56
|
+
obj.mark_method_as_override(:instance_methods, 'CustomClass', :instance_test_method, overriding_method, OverridesTracker::Util.method_hash(overriding_method))
|
57
|
+
|
58
|
+
expect(obj.instance_variable_get(:@methods_collection)).to eq({"CustomClass" => {:instance_methods=>{:instance_test_method=>{:body=>"def instance_test_method\n 'instance_test_method'\nend\n", :is_part_of_app=>false, :location=>["#{@original_dir}/spec/test_classes/custom_class.rb", 10], :overriding_body=>"def instance_override_test_method\n 'instance_override_test_method'\nend\n", :overriding_is_part_of_app=>false, :overriding_location=>["#{@original_dir}/spec/test_classes/custom_class.rb", 14], :overriding_sha=>"75cf2b21c3033f33c155a329d8e9110ae3fb0290", :sha=>"3408e1f1736c6b83bc13f014e5338eec0c67393f"}}, :is_part_of_app=>false, :singleton_methods=>{}}})
|
59
|
+
expect(obj.instance_variable_get(:@overridden_methods_collection)).to eq({"CustomClass" => {:added_instance_methods=>{}, :added_singleton_methods=>{}, :instance_methods=>{:instance_test_method=>{:body=>"def instance_test_method\n 'instance_test_method'\nend\n", :is_part_of_app=>false, :location=>["#{@original_dir}/spec/test_classes/custom_class.rb", 10], :overriding_body=>"def instance_override_test_method\n 'instance_override_test_method'\nend\n", :overriding_is_part_of_app=>false, :overriding_location=>["#{@original_dir}/spec/test_classes/custom_class.rb", 14], :overriding_sha=>"75cf2b21c3033f33c155a329d8e9110ae3fb0290", :sha=>"3408e1f1736c6b83bc13f014e5338eec0c67393f"}}, :singleton_methods=>{}}})
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#mark_method_as_added' do
|
65
|
+
let(:method) { CustomClass.instance_method(:instance_test_method) }
|
66
|
+
let(:overriding_method) { CustomClass.instance_method(:instance_override_test_method) }
|
67
|
+
|
68
|
+
before do
|
69
|
+
obj.instance_variable_set(:@methods_collection, nil)
|
70
|
+
obj.instance_variable_set(:@overridden_methods_collection, nil)
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when overriding location is in working directory' do
|
74
|
+
it 'adds the method to the overridden methods collection' do
|
75
|
+
expect(obj.instance_variable_get(:@methods_collection)).to eq(nil)
|
76
|
+
expect(obj.instance_variable_get(:@overridden_methods_collection)).to eq(nil)
|
77
|
+
|
78
|
+
obj.mark_method_as_added(:added_instance_methods, 'CustomClass', :instance_test_method, overriding_method, OverridesTracker::Util.method_hash(overriding_method))
|
79
|
+
|
80
|
+
expect(obj.instance_variable_get(:@overridden_methods_collection)).to eq({"CustomClass" => {:added_instance_methods=>{:instance_test_method=>{:body=>"def instance_override_test_method\n 'instance_override_test_method'\nend\n", :is_part_of_app=>true, :location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 14], :overriding_is_part_of_app=>true, :overriding_location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 14], :sha=>"75cf2b21c3033f33c155a329d8e9110ae3fb0290"}}, :added_singleton_methods=>{}, :instance_methods=>{}, :singleton_methods=>{}}})
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context 'when overriding location is not in working directory' do
|
85
|
+
let(:overriding_method) { CustomClass.instance_method(:instance_override_test_method) }
|
86
|
+
|
87
|
+
before do
|
88
|
+
allow(Dir).to receive(:pwd).and_return("another_directory")
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'adds the method to the overridden methods collection' do
|
92
|
+
expect(obj.instance_variable_get(:@methods_collection)).to eq(nil)
|
93
|
+
expect(obj.instance_variable_get(:@overridden_methods_collection)).to eq(nil)
|
94
|
+
|
95
|
+
obj.mark_method_as_added(:added_instance_methods, 'CustomClass', :instance_test_method, overriding_method, OverridesTracker::Util.method_hash(overriding_method))
|
96
|
+
|
97
|
+
expect(obj.instance_variable_get(:@overridden_methods_collection)).to eq({"CustomClass" => {:added_instance_methods=>{:instance_test_method=>{:body=>"def instance_override_test_method\n 'instance_override_test_method'\nend\n", :is_part_of_app=>false, :location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 14], :overriding_is_part_of_app=>false, :overriding_location=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 14], :sha=>"75cf2b21c3033f33c155a329d8e9110ae3fb0290"}}, :added_singleton_methods=>{}, :instance_methods=>{}, :singleton_methods=>{}}})
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'save and load_from_file' do
|
103
|
+
let(:method) { CustomClass.instance_method(:instance_test_method) }
|
104
|
+
let(:overriding_method) { CustomClass.instance_method(:instance_override_test_method) }
|
105
|
+
|
106
|
+
let(:file_name) { "branch_name#last_commit_id.otf"}
|
107
|
+
|
108
|
+
|
109
|
+
before do
|
110
|
+
allow(obj).to receive(:branch_name).and_return('branch_name')
|
111
|
+
allow(obj).to receive(:last_commit_id).and_return('last_commit_id')
|
112
|
+
allow(obj).to receive(:last_commit_name).and_return('last_commit_name')
|
113
|
+
allow(obj).to receive(:last_commit_name_to_report).and_return('last_commit_name_to_report')
|
114
|
+
allow(obj).to receive(:author_name).and_return('author_name')
|
115
|
+
allow(obj).to receive(:committer_name).and_return('committer_name')
|
116
|
+
|
117
|
+
obj.instance_variable_set(:@methods_collection, nil)
|
118
|
+
obj.add_method_for_class(:instance_methods, 'CustomClass', :instance_test_method, OverridesTracker::Util.method_hash(method))
|
119
|
+
obj.mark_method_as_override(:instance_methods, 'CustomClass', :instance_test_method, overriding_method, OverridesTracker::Util.method_hash(overriding_method))
|
120
|
+
obj.save_to_file
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'loads the methods collection from the file' do
|
124
|
+
obj.instance_variable_set(:@methods_collection, nil)
|
125
|
+
obj.instance_variable_set(:@overridden_methods_collection, nil)
|
126
|
+
|
127
|
+
data = obj.load_from_file(file_name)
|
128
|
+
expect(data).to eq(
|
129
|
+
{"branch_name" => "branch_name","branch_name_to_report" => "master","bundle_path" => Bundler.bundle_path.to_s, "author_name" => "author_name", "committer_name" => "committer_name","last_commit_id" => "last_commit_id","last_commit_name" => "last_commit_name","last_commit_name_to_report" => "last_commit_name_to_report","methods_collection" => {"CustomClass" => {"added_instance_methods"=>{"instance_test_method"=>{"body"=>"def instance_override_test_method\n 'instance_override_test_method'\nend\n", "is_part_of_app"=>false, "location"=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 14], "overriding_is_part_of_app"=>false, "overriding_location"=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 14], "sha"=>"75cf2b21c3033f33c155a329d8e9110ae3fb0290"}}, "added_singleton_methods"=>{}, "instance_methods"=>{"instance_test_method"=>{"body"=>"def instance_test_method\n 'instance_test_method'\nend\n", "is_part_of_app"=>true, "location"=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 10], "overriding_body"=>"def instance_override_test_method\n 'instance_override_test_method'\nend\n", "overriding_is_part_of_app"=>true, "overriding_location"=>["#{WORKING_DIR}/spec/test_classes/custom_class.rb", 14], "overriding_sha"=>"75cf2b21c3033f33c155a329d8e9110ae3fb0290", "sha"=>"3408e1f1736c6b83bc13f014e5338eec0c67393f"}}, "singleton_methods"=>{}}}, "version" => "#{OverridesTracker::VERSION}", "working_directory" => Dir.pwd,"number_of_classes" => 1, "number_of_classes_in_app_path" => 1, "number_of_methods" => 1, "number_of_methods_in_app_path" => 1})
|
130
|
+
end
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
describe '#build_overrides_hash' do
|
135
|
+
let(:method) { CustomClass.instance_method(:instance_test_method) }
|
136
|
+
|
137
|
+
before do
|
138
|
+
obj.instance_variable_set(:@methods_collection, nil)
|
139
|
+
obj.add_method_for_class(:instance_methods, 'CustomClass', :instance_test_method, OverridesTracker::Util.method_hash(method))
|
140
|
+
@methods_collection = obj.instance_variable_get(:@methods_collection)
|
141
|
+
|
142
|
+
allow(obj).to receive(:build_overrides_hash_for_method_type).with(CustomClass, @methods_collection["CustomClass"], :instance_methods, WORKING_DIR)
|
143
|
+
allow(obj).to receive(:build_overrides_hash_for_method_type).with(CustomClass, @methods_collection["CustomClass"], :singleton_methods, WORKING_DIR)
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'calls build_overrides_hash_for_method_type' do
|
147
|
+
obj.build_overrides_hash
|
148
|
+
|
149
|
+
expect(obj).to have_received(:build_overrides_hash_for_method_type).with(CustomClass, @methods_collection["CustomClass"], :instance_methods, WORKING_DIR)
|
150
|
+
expect(obj).to have_received(:build_overrides_hash_for_method_type).with(CustomClass, @methods_collection["CustomClass"], :singleton_methods, WORKING_DIR)
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
describe '#overridden_methods' do
|
155
|
+
let(:overridden_methods_collection) { {test: 'test '} }
|
156
|
+
|
157
|
+
before do
|
158
|
+
obj.instance_variable_set(:@overridden_methods_collection, overridden_methods_collection)
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'returns the overridden_methods_collection' do
|
162
|
+
expect(obj.overridden_methods).to eq(overridden_methods_collection)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe '#report' do
|
167
|
+
let(:api_token) { 'api_token' }
|
168
|
+
let(:branch_name_to_report) { 'branch_name_to_report' }
|
169
|
+
let(:last_commit_id) { 'last_commit_id' }
|
170
|
+
let(:last_commit_name_to_report) { 'last_commit_name_to_report' }
|
171
|
+
let(:path_to_report_file) { 'path_to_report_file' }
|
172
|
+
|
173
|
+
before do
|
174
|
+
allow(obj).to receive(:branch_name_to_report).and_return(branch_name_to_report)
|
175
|
+
allow(obj).to receive(:last_commit_id).and_return(last_commit_id)
|
176
|
+
allow(obj).to receive(:last_commit_name_to_report).and_return(last_commit_name_to_report)
|
177
|
+
allow(obj).to receive(:path_to_report_file).and_return(path_to_report_file)
|
178
|
+
allow(OverridesTracker::Api).to receive(:report_build).with(api_token, branch_name_to_report, last_commit_id, last_commit_name_to_report, path_to_report_file)
|
179
|
+
end
|
180
|
+
|
181
|
+
it 'call the API' do
|
182
|
+
obj.report(api_token)
|
183
|
+
|
184
|
+
expect(OverridesTracker::Api).to have_received(:report_build).with(api_token, branch_name_to_report, last_commit_id, last_commit_name_to_report, path_to_report_file)
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
describe '#branch_name' do
|
189
|
+
let(:branch_name) { `git rev-parse --abbrev-ref HEAD` }
|
190
|
+
|
191
|
+
it 'returns the branch name' do
|
192
|
+
expect(obj.send(:branch_name)).to eq(branch_name.downcase.gsub('/', '_').gsub(/\s+/, ''))
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
describe '#last_commit_id' do
|
197
|
+
let(:last_commit_id) { `git log --format="%H" -n 1` }
|
198
|
+
|
199
|
+
it 'returns the last_commit_id' do
|
200
|
+
expect(obj.send(:last_commit_id)).to eq(last_commit_id.gsub(/\s+/, ''))
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
describe '#last_commit_name_to_report' do
|
205
|
+
let(:last_commit_name_to_report) { `git log --format="%s" -n 1` }
|
206
|
+
|
207
|
+
it 'returns the last_commit_name_to_report' do
|
208
|
+
expect(obj.send(:last_commit_name_to_report)).to eq(last_commit_name_to_report.chomp)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
describe '#author_name' do
|
213
|
+
let(:author_name) { `git show -s --format='%an'`.chomp }
|
214
|
+
|
215
|
+
it 'returns the author_name' do
|
216
|
+
expect(obj.send(:author_name)).to eq(author_name)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe '#committer_name' do
|
221
|
+
let(:committer_name) { `git show -s --format='%cn'`.chomp }
|
222
|
+
|
223
|
+
it 'returns the committer_name' do
|
224
|
+
expect(obj.send(:committer_name)).to eq(committer_name)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
describe '#build_overrides_hash_for_method_type' do
|
229
|
+
|
230
|
+
context 'instance_methods' do
|
231
|
+
let(:method) { CustomClass.instance_method(:instance_test_method) }
|
232
|
+
|
233
|
+
before do
|
234
|
+
obj.instance_variable_set(:@methods_collection, nil)
|
235
|
+
obj.add_method_for_class(:instance_methods, 'CustomClass', :instance_test_method, OverridesTracker::Util.method_hash(method))
|
236
|
+
obj.add_method_for_class(:instance_methods, 'CustomClass', :instance_override_test_method, OverridesTracker::Util.method_hash(method))
|
237
|
+
@methods_collection = obj.instance_variable_get(:@methods_collection)
|
238
|
+
end
|
239
|
+
|
240
|
+
context 'when the method is not overridden' do
|
241
|
+
let(:method_to_check) { CustomClass.instance_method(:instance_added_test_method) }
|
242
|
+
|
243
|
+
before do
|
244
|
+
allow(obj).to receive(:mark_method_as_added).with(:added_instance_methods, 'CustomClass', :instance_added_test_method, method_to_check, OverridesTracker::Util.method_hash(method_to_check) )
|
245
|
+
end
|
246
|
+
|
247
|
+
context 'when the method is part of the app' do
|
248
|
+
it 'calls mark_method_as_added_instance_methods' do
|
249
|
+
obj.build_overrides_hash_for_method_type(CustomClass, @methods_collection["CustomClass"], :instance_methods, WORKING_DIR)
|
250
|
+
expect(obj).to have_received(:mark_method_as_added).with(:added_instance_methods, 'CustomClass', :instance_added_test_method, method_to_check, OverridesTracker::Util.method_hash(method_to_check) )
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
context 'when the method is not part of the app' do
|
255
|
+
it 'does not call mark_method_as_added_instance_methods' do
|
256
|
+
obj.build_overrides_hash_for_method_type(CustomClass, @methods_collection["CustomClass"], :instance_methods, '/not_working_dir')
|
257
|
+
expect(obj).to_not have_received(:mark_method_as_added).with(:added_instance_methods, 'CustomClass', :instance_added_test_method, method_to_check, OverridesTracker::Util.method_hash(method_to_check) )
|
258
|
+
end
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'when the method is override' do
|
263
|
+
let(:method_to_check) { CustomClass.instance_method(:instance_override_test_method) }
|
264
|
+
|
265
|
+
before do
|
266
|
+
CustomClass.class_eval do
|
267
|
+
def instance_override_test_method
|
268
|
+
"instance_override_test_method_override"
|
269
|
+
end
|
270
|
+
end
|
271
|
+
allow(obj).to receive(:mark_method_as_override).with(:instance_methods, 'CustomClass', :instance_override_test_method, method_to_check, OverridesTracker::Util.method_hash(method_to_check) )
|
272
|
+
end
|
273
|
+
|
274
|
+
it 'calls mark_method_as_added_instance_methods' do
|
275
|
+
obj.build_overrides_hash_for_method_type(CustomClass, @methods_collection["CustomClass"], :instance_methods, WORKING_DIR)
|
276
|
+
expect(obj).to have_received(:mark_method_as_override).with(:instance_methods, 'CustomClass', :instance_override_test_method, method_to_check, OverridesTracker::Util.method_hash(method_to_check) )
|
277
|
+
end
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
context 'singleton_methods' do
|
282
|
+
let(:method) { CustomClass.singleton_method(:singleton_test_method) }
|
283
|
+
|
284
|
+
before do
|
285
|
+
obj.instance_variable_set(:@methods_collection, nil)
|
286
|
+
obj.add_method_for_class(:singleton_methods, 'CustomClass', :singleton_test_method, OverridesTracker::Util.method_hash(method))
|
287
|
+
obj.add_method_for_class(:singleton_methods, 'CustomClass', :singleton_override_test_method, OverridesTracker::Util.method_hash(method))
|
288
|
+
@methods_collection = obj.instance_variable_get(:@methods_collection)
|
289
|
+
end
|
290
|
+
|
291
|
+
context 'when the method is not overridden' do
|
292
|
+
let(:method_to_check) { CustomClass.singleton_class.instance_method(:singleton_added_test_method) }
|
293
|
+
|
294
|
+
before do
|
295
|
+
allow(obj).to receive(:mark_method_as_added).with(:added_singleton_methods, 'CustomClass', :singleton_added_test_method, method_to_check, OverridesTracker::Util.method_hash(method_to_check) )
|
296
|
+
end
|
297
|
+
|
298
|
+
context 'when the method is part of the app' do
|
299
|
+
it 'calls mark_method_as_added_singleton_methods' do
|
300
|
+
obj.build_overrides_hash_for_method_type(CustomClass, @methods_collection["CustomClass"], :singleton_methods, WORKING_DIR)
|
301
|
+
|
302
|
+
expect(obj).to have_received(:mark_method_as_added).with(:added_singleton_methods, 'CustomClass', :singleton_added_test_method, method_to_check, OverridesTracker::Util.method_hash(method_to_check) )
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
context 'when the method is not part of the app' do
|
307
|
+
it 'does not call mark_method_as_added_singleton_methods' do
|
308
|
+
obj.build_overrides_hash_for_method_type(CustomClass, @methods_collection["CustomClass"], :singleton_methods, '/not_working_dir')
|
309
|
+
|
310
|
+
expect(obj).to_not have_received(:mark_method_as_added).with(:added_singleton_methods, 'CustomClass', :singleton_added_test_method, method_to_check, OverridesTracker::Util.method_hash(method_to_check) )
|
311
|
+
end
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
context 'when the method is override' do
|
316
|
+
let(:method_to_check) { CustomClass.singleton_class.instance_method(:singleton_override_test_method) }
|
317
|
+
|
318
|
+
before do
|
319
|
+
CustomClass.class_eval do
|
320
|
+
def self.singleton_override_test_method
|
321
|
+
"singleton_override_test_method_override"
|
322
|
+
end
|
323
|
+
end
|
324
|
+
allow(obj).to receive(:mark_method_as_override).with(:singleton_methods, 'CustomClass', :singleton_override_test_method, method_to_check, OverridesTracker::Util.method_hash(method_to_check) )
|
325
|
+
end
|
326
|
+
|
327
|
+
it 'calls mark_method_as_added_singleton_methods' do
|
328
|
+
obj.build_overrides_hash_for_method_type(CustomClass, @methods_collection["CustomClass"], :singleton_methods, WORKING_DIR)
|
329
|
+
|
330
|
+
expect(obj).to have_received(:mark_method_as_override).with(:singleton_methods, 'CustomClass', :singleton_override_test_method, method_to_check, OverridesTracker::Util.method_hash(method_to_check) )
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|
334
|
+
end
|
335
|
+
|
336
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe String do
|
6
|
+
let(:custom_string) { String.new('custom string') }
|
7
|
+
|
8
|
+
describe '#colorize' do
|
9
|
+
it 'returns a string with the color code' do
|
10
|
+
expect(custom_string.colorize(31)).to eq "\e[31m#{custom_string}\e[0m"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
describe '#red' do
|
15
|
+
it 'calls colorize with 31' do
|
16
|
+
expect(custom_string).to receive(:colorize).with(31)
|
17
|
+
|
18
|
+
custom_string.red
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#green' do
|
23
|
+
it 'calls colorize with 32' do
|
24
|
+
expect(custom_string).to receive(:colorize).with(32)
|
25
|
+
|
26
|
+
custom_string.green
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#yellow' do
|
31
|
+
it 'calls colorize with 33' do
|
32
|
+
expect(custom_string).to receive(:colorize).with(33)
|
33
|
+
|
34
|
+
custom_string.yellow
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#blue' do
|
39
|
+
it 'calls colorize with 34' do
|
40
|
+
expect(custom_string).to receive(:colorize).with(34)
|
41
|
+
|
42
|
+
custom_string.blue
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#pink' do
|
47
|
+
it 'calls colorize with 35' do
|
48
|
+
expect(custom_string).to receive(:colorize).with(35)
|
49
|
+
|
50
|
+
custom_string.pink
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#light_blue' do
|
55
|
+
it 'calls colorize with 36' do
|
56
|
+
expect(custom_string).to receive(:colorize).with(36)
|
57
|
+
|
58
|
+
custom_string.light_blue
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#bold' do
|
63
|
+
it 'returns a string with the bold code' do
|
64
|
+
expect(custom_string.bold).to eq "\e[1m#{custom_string}\e[22m"
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#italic' do
|
69
|
+
it 'returns a string with the italic code' do
|
70
|
+
expect(custom_string.italic).to eq "\e[3m#{custom_string}\e[23m"
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
require_relative '../test_classes/custom_class'
|
5
|
+
|
6
|
+
WORKING_DIR = Dir.pwd
|
7
|
+
|
8
|
+
describe OverridesTracker::Util do
|
9
|
+
let(:method) { CustomClass.instance_method(:instance_test_method) }
|
10
|
+
|
11
|
+
describe '.method_hash' do
|
12
|
+
context 'when the method is part of the app' do
|
13
|
+
it "returns a hash with the method's name, body and sha" do
|
14
|
+
expect(OverridesTracker::Util.method_hash(method)).to eq({ body: "def instance_test_method\n 'instance_test_method'\nend\n",
|
15
|
+
is_part_of_app: true,
|
16
|
+
location: [
|
17
|
+
"#{WORKING_DIR}/spec/test_classes/custom_class.rb", 10
|
18
|
+
],
|
19
|
+
sha: '3408e1f1736c6b83bc13f014e5338eec0c67393f' })
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context 'when the method is not part of the app' do
|
24
|
+
before do
|
25
|
+
allow(Dir).to receive(:pwd).and_return('another_directory')
|
26
|
+
end
|
27
|
+
|
28
|
+
it "returns a hash with the method's name, body and sha" do
|
29
|
+
expect(OverridesTracker::Util.method_hash(method)[:body]).to eq("def instance_test_method\n 'instance_test_method'\nend\n")
|
30
|
+
expect(OverridesTracker::Util.method_hash(method)[:is_part_of_app]).to eq(false)
|
31
|
+
expect(OverridesTracker::Util.method_hash(method)[:sha]).to eq('3408e1f1736c6b83bc13f014e5338eec0c67393f')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'when we we run into an error' do
|
36
|
+
before do
|
37
|
+
allow(method).to receive(:source_location).and_return('/')
|
38
|
+
end
|
39
|
+
|
40
|
+
it "returns a hash with the method's hash" do
|
41
|
+
expect(OverridesTracker::Util.method_hash(method)).to eq({ body: nil, is_part_of_app: false, location: nil,
|
42
|
+
sha: nil })
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.outdented_method_body' do
|
48
|
+
it 'returns the body of the method without the indentation' do
|
49
|
+
expect(OverridesTracker::Util.outdented_method_body(method)).to eq("def instance_test_method\n 'instance_test_method'\nend\n")
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '.method_sha' do
|
54
|
+
it 'returns the sha of the method' do
|
55
|
+
expect(OverridesTracker::Util.method_sha(method)).to eq('3408e1f1736c6b83bc13f014e5338eec0c67393f')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
{
|
2
|
+
"ClassADifferentSources":{
|
3
|
+
"instance_methods":{
|
4
|
+
"method_one":{
|
5
|
+
"sha":"376988d98a7069f2a2914a4544d4e2d1d519f62b",
|
6
|
+
"overriding_sha":"376988d98a7069f2a2914a4544d4e2d1d519f345",
|
7
|
+
"location":[
|
8
|
+
"/gem/models/class_a.rb",
|
9
|
+
7
|
10
|
+
],
|
11
|
+
"body":"def method_one\n master_original_implementation\nend\n",
|
12
|
+
"overriding_location":[
|
13
|
+
"/app/models/class_a.rb",
|
14
|
+
7
|
15
|
+
],
|
16
|
+
"overriding_body":"def method_one\n master_override\nend\n"
|
17
|
+
}
|
18
|
+
},
|
19
|
+
"singleton_methods":{
|
20
|
+
"self.method_two":{
|
21
|
+
"sha":"376988d98a7069f2a2914a4544d4e2d1d519f62b",
|
22
|
+
"overriding_sha":"376988d98a7069f2a2914a4544d4e2d1d519f345",
|
23
|
+
"location":[
|
24
|
+
"/gem/models/class_a.rb",
|
25
|
+
7
|
26
|
+
],
|
27
|
+
"body":"def self.method_two\n master_original_implementation\nend\n",
|
28
|
+
"overriding_location":[
|
29
|
+
"/app/models/class_a.rb",
|
30
|
+
7
|
31
|
+
],
|
32
|
+
"overriding_body":"def self.method_two\n master_override\nend\n"
|
33
|
+
}
|
34
|
+
},
|
35
|
+
"added_instance_methods":{
|
36
|
+
"method_three":{
|
37
|
+
"sha":"376988d98a7069f2a2914a4544d4e2d1d519f62b",
|
38
|
+
"overriding_sha":"376988d98a7069f2a2914a4544d4e2d1d519f345",
|
39
|
+
"location":[
|
40
|
+
"/gem/models/class_a.rb",
|
41
|
+
7
|
42
|
+
],
|
43
|
+
"body":"def method_three\n master_original_implementation\nend\n",
|
44
|
+
"overriding_location":[
|
45
|
+
"/app/models/class_a.rb",
|
46
|
+
7
|
47
|
+
],
|
48
|
+
"overriding_body":"def method_three\n master_override\nend\n"
|
49
|
+
}
|
50
|
+
},
|
51
|
+
"added_singleton_methods":{
|
52
|
+
"method_four":{
|
53
|
+
"sha":"376988d98a7069f2a2914a4544d4e2d1d519f62b",
|
54
|
+
"overriding_sha":"376988d98a7069f2a2914a4544d4e2d1d519f345",
|
55
|
+
"location":[
|
56
|
+
"/gem/models/class_a.rb",
|
57
|
+
7
|
58
|
+
],
|
59
|
+
"body":"def method_four\n master_original_implementation\nend\n",
|
60
|
+
"overriding_location":[
|
61
|
+
"/app/models/class_a.rb",
|
62
|
+
7
|
63
|
+
],
|
64
|
+
"overriding_body":"def method_four\n master_override\nend\n"
|
65
|
+
}
|
66
|
+
}
|
67
|
+
},
|
68
|
+
"ClassDifferentOverrides":{
|
69
|
+
"instance_methods":{
|
70
|
+
"method_one":{
|
71
|
+
"sha":"376988d98a7069f2a2914a4544d4e2d1d519f62b",
|
72
|
+
"overriding_sha":"376988d98a7069f2a2914a4544d4e2d1d519f345",
|
73
|
+
"location":[
|
74
|
+
"/gem/models/class_b.rb",
|
75
|
+
7
|
76
|
+
],
|
77
|
+
"body":"def method_one\n master_original_implementation\nend\n",
|
78
|
+
"overriding_location":[
|
79
|
+
"/app/models/class_b.rb",
|
80
|
+
7
|
81
|
+
],
|
82
|
+
"overriding_body":"def method_one\n master_override\nend\n"
|
83
|
+
}
|
84
|
+
},
|
85
|
+
"singleton_methods":{
|
86
|
+
"self.method_two":{
|
87
|
+
"sha":"376988d98a7069f2a2914a4544d4e2d1d519f62b",
|
88
|
+
"overriding_sha":"376988d98a7069f2a2914a4544d4e2d1d519f345",
|
89
|
+
"location":[
|
90
|
+
"/gem/models/class_b.rb",
|
91
|
+
7
|
92
|
+
],
|
93
|
+
"body":"def self.method_two\n master_original_implementation\nend\n",
|
94
|
+
"overriding_location":[
|
95
|
+
"/app/models/class_b.rb",
|
96
|
+
7
|
97
|
+
],
|
98
|
+
"overriding_body":"def self.method_two\n master_override\nend\n"
|
99
|
+
}
|
100
|
+
},
|
101
|
+
"added_instance_methods":{
|
102
|
+
"method_three":{
|
103
|
+
"sha":"376988d98a7069f2a2914a4544d4e2d1d519f62b",
|
104
|
+
"overriding_sha":"376988d98a7069f2a2914a4544d4e2d1d519f345",
|
105
|
+
"location":[
|
106
|
+
"/gem/models/class_b.rb",
|
107
|
+
7
|
108
|
+
],
|
109
|
+
"body":"def method_three\n master_original_implementation\nend\n",
|
110
|
+
"overriding_location":[
|
111
|
+
"/app/models/class_b.rb",
|
112
|
+
7
|
113
|
+
],
|
114
|
+
"overriding_body":"def method_three\n master_override\nend\n"
|
115
|
+
}
|
116
|
+
},
|
117
|
+
"added_singleton_methods":{
|
118
|
+
"method_four":{
|
119
|
+
"sha":"376988d98a7069f2a2914a4544d4e2d1d519f62b",
|
120
|
+
"overriding_sha":"376988d98a7069f2a2914a4544d4e2d1d519f345",
|
121
|
+
"location":[
|
122
|
+
"/gem/models/class_b.rb",
|
123
|
+
7
|
124
|
+
],
|
125
|
+
"body":"def method_four\n master_original_implementation\nend\n",
|
126
|
+
"overriding_location":[
|
127
|
+
"/app/models/class_a.rb",
|
128
|
+
7
|
129
|
+
],
|
130
|
+
"overriding_body":"def method_four\n master_override\nend\n"
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
}
|