overrides_tracker 0.1.12 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -140,6 +140,58 @@ overriding_method.source_location
140
140
  data
141
141
  end
142
142
 
143
+ def summarize_overrides
144
+ puts ""
145
+ puts "==========================================================================================="
146
+ puts ""
147
+ puts ""
148
+ puts "SUMMARY"
149
+ puts ""
150
+ @overridden_methods_collection.each do |class_name, class_methods|
151
+ class_methods[:instance_methods].each do |method_name, method_hash|
152
+ show_override(class_name, method_name, method_hash, '#', 'overridden')
153
+ end
154
+ class_methods[:singleton_methods].each do |method_name, method_hash|
155
+ show_override(class_name, method_name, method_hash, '.', 'overridden')
156
+ end
157
+ class_methods[:added_instance_methods].each do |method_name, method_hash|
158
+ show_override(class_name, method_name, method_hash, '#', 'added')
159
+ end
160
+ class_methods[:added_singleton_methods].each do |method_name, method_hash|
161
+ show_override(class_name, method_name, method_hash, '.', 'added')
162
+ end
163
+ end
164
+ end
165
+
166
+ def show_override(class_name, method_name, method_hash, separator = '#', word_choice = 'overridden')
167
+
168
+ puts ""
169
+ puts "==========================================================================================="
170
+ puts ""
171
+
172
+ puts "#{class_name}#{separator}#{method_name} was #{word_choice}."
173
+ unless method_hash[:body].nil?
174
+ puts "-------------------------------------------------------------------------------------------".pink
175
+ puts ''
176
+ puts 'Original:'.italic
177
+ puts ''
178
+ puts "#{method_hash[:body]}".pink
179
+ puts ''
180
+ puts "in #{method_hash[:location][0]}:#{method_hash[:location][1]}".italic
181
+ end
182
+ puts ''
183
+ puts ''
184
+ unless method_hash[:overriding_body].nil?
185
+ puts "-------------------------------------------------------------------------------------------".blue
186
+ puts ''
187
+ puts 'Override:'.italic
188
+ puts ''
189
+ puts "#{method_hash[:overriding_body]}".blue
190
+ puts ''
191
+ puts "in: #{method_hash[:overriding_location][0]}:#{method_hash[:overriding_location][1]}".italic
192
+ end
193
+ end
194
+
143
195
  def save_to_file
144
196
  file_data = {}
145
197
  file_data[:version] = OverridesTracker::VERSION
@@ -1,3 +1,3 @@
1
1
  module OverridesTracker
2
- VERSION = '0.1.12'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -0,0 +1 @@
1
+ {"version":"0.1.13","branch_name":"branch_name","author_name":"author_name","committer_name":"committer_name","branch_name_to_report":"master","last_commit_id":"last_commit_id","last_commit_name":"last_commit_name","last_commit_name_to_report":"last_commit_name_to_report","working_directory":"/Users/simonmeyborg/Documents/syborgstudios/projects/overrides_tracker","bundle_path":"/Library/Ruby/Gems/2.6.0","methods_collection":{"CustomClass":{"instance_methods":{"instance_test_method":{"sha":"3408e1f1736c6b83bc13f014e5338eec0c67393f","location":["/Users/simonmeyborg/Documents/syborgstudios/projects/overrides_tracker/spec/test_classes/custom_class.rb",10],"body":"def instance_test_method\n 'instance_test_method'\nend\n","is_part_of_app":true,"overriding_location":["/Users/simonmeyborg/Documents/syborgstudios/projects/overrides_tracker/spec/test_classes/custom_class.rb",14],"overriding_body":"def instance_override_test_method\n 'instance_override_test_method'\nend\n","overriding_sha":"75cf2b21c3033f33c155a329d8e9110ae3fb0290","overriding_is_part_of_app":true}},"singleton_methods":{},"added_instance_methods":{},"added_singleton_methods":{}}},"number_of_methods":1,"number_of_methods_in_app_path":1,"number_of_classes":1,"number_of_classes_in_app_path":1}
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['Simon Meyborg']
9
9
  spec.email = ['meyborg@syborgstudios.com']
10
10
 
11
- spec.summary = 'Overrides Tracker monitors methods you override for changes and allows for comparison across branches.'
12
- spec.description = 'Overrides Tracker monitors methods you override for changes and allows for comparison across branches.'
11
+ spec.summary = 'Overrides Tracker keeps track of all overriding methods and their sources and allows for comparison across branches.'
12
+ spec.description = 'Overrides Tracker keeps track of all overriding methods and their sources and allows for comparison across branches.'
13
13
  spec.homepage = 'https://github.com/SyborgStudios/overrides_tracker'
14
14
  spec.license = 'MIT'
15
15
 
@@ -0,0 +1,227 @@
1
+ require 'spec_helper'
2
+ require 'webmock'
3
+ require 'vcr'
4
+
5
+ describe OverridesTracker::Api do
6
+ describe '.report_build' do
7
+ let(:api_token) { 'abc123' }
8
+ let(:branch_name) { 'master' }
9
+ let(:last_commit_id) { '123456' }
10
+ let(:last_commit_name) { 'Commit message' }
11
+ let(:file_path) { "#{Dir.pwd}/spec/result_files/master.otf" }
12
+
13
+ let(:uri) { URI(OverridesTracker::Api::API_DOMAIN) }
14
+ let(:client) { double('client') }
15
+ let(:request) { double('request') }
16
+ let(:file) { double('file') }
17
+ let(:response) { double('response') }
18
+ let(:file_hash) { double('file_hash') }
19
+
20
+ let(:form_data) do
21
+ [['api_token', api_token],
22
+ ['branch_name', branch_name],
23
+ ['build_provider_id', last_commit_id],
24
+ ['build_name', last_commit_name],
25
+ ['result_file', file],
26
+ ['file_hash', file_hash]
27
+ ]
28
+ end
29
+
30
+ before do
31
+ allow(OverridesTracker::Api).to receive(:build_client).and_return(client)
32
+ allow(Net::HTTP::Post).to receive(:new).and_return(request)
33
+ allow(request).to receive(:set_form).with(form_data, 'multipart/form-data')
34
+ allow(client).to receive(:request).and_return(response)
35
+ allow(response).to receive(:body).and_return('{"success": true}')
36
+ allow(File).to receive(:open).and_return(file)
37
+ allow(Digest::SHA256).to receive(:hexdigest).and_return(file_hash)
38
+ allow(described_class).to receive(:disable_net_blockers!)
39
+ end
40
+
41
+ context 'when reference build is not found' do
42
+ before do
43
+ allow(OverridesTracker::Api).to receive(:find_or_report_build).with(api_token, branch_name, last_commit_id, last_commit_name, file_hash).and_return(false)
44
+ end
45
+
46
+ it 'sends a POST request to the API with the correct form data' do
47
+ expect(request).to receive(:set_form).with(form_data, 'multipart/form-data')
48
+ expect(client).to receive(:request).with(request)
49
+
50
+ expect(OverridesTracker::Api.report_build(api_token, branch_name, last_commit_id, last_commit_name,
51
+ file_path)).to be true
52
+ end
53
+
54
+ context 'when the API request fails' do
55
+ before do
56
+ allow(client).to receive(:request).and_raise(SocketError)
57
+ end
58
+
59
+ it 'raises an error' do
60
+ expect(OverridesTracker::Api.report_build(api_token, branch_name, last_commit_id, last_commit_name,
61
+ file_path)).to be false
62
+ end
63
+ end
64
+ end
65
+
66
+ context 'when reference build is found' do
67
+ before do
68
+ allow(OverridesTracker::Api).to receive(:find_or_report_build).with(api_token, branch_name, last_commit_id, last_commit_name, file_hash).and_return(true)
69
+ end
70
+
71
+ it 'does not send a POST request to the API with the correct form data' do
72
+ expect(request).to_not receive(:set_form).with(form_data, 'multipart/form-data')
73
+ expect(client).to_not receive(:request).with(request)
74
+
75
+ expect(OverridesTracker::Api.report_build(api_token, branch_name, last_commit_id, last_commit_name,
76
+ file_path)).to be true
77
+ end
78
+ end
79
+ end
80
+
81
+ describe '.find_or_report_build' do
82
+ let(:api_token) { 'abc123' }
83
+ let(:branch_name) { 'master' }
84
+ let(:last_commit_id) { '123456' }
85
+ let(:last_commit_name) { 'Commit message' }
86
+ let(:file_path) { "#{Dir.pwd}/spec/result_files/master.otf" }
87
+
88
+ let(:uri) { URI(OverridesTracker::Api::API_DOMAIN) }
89
+ let(:client) { double('client') }
90
+ let(:request) { double('request') }
91
+ let(:file) { double('file') }
92
+ let(:response) { double('response') }
93
+ let(:file_hash) { double('file_hash') }
94
+
95
+ let(:form_data) do
96
+ [['api_token', api_token],
97
+ ['branch_name', branch_name],
98
+ ['build_provider_id', last_commit_id],
99
+ ['build_name', last_commit_name],
100
+ ['file_hash', file_hash]
101
+ ]
102
+ end
103
+
104
+ before do
105
+ allow(OverridesTracker::Api).to receive(:build_client).and_return(client)
106
+ allow(Net::HTTP::Post).to receive(:new).and_return(request)
107
+ allow(request).to receive(:set_form).with(form_data)
108
+ allow(client).to receive(:request).and_return(response)
109
+ allow(response).to receive(:body).and_return('{"success": true}')
110
+ allow(File).to receive(:open).and_return(file)
111
+ allow(Digest::SHA256).to receive(:hexdigest).and_return(file_hash)
112
+ allow(described_class).to receive(:disable_net_blockers!)
113
+ end
114
+
115
+ context 'when reference build is not found' do
116
+ before do
117
+ allow(response).to receive(:code).and_return('404')
118
+ end
119
+
120
+ it 'sends a POST request to the API with the correct form data and returns false' do
121
+ expect(request).to receive(:set_form).with(form_data)
122
+ expect(client).to receive(:request).with(request)
123
+
124
+ expect(OverridesTracker::Api.find_or_report_build(api_token, branch_name, last_commit_id, last_commit_name,
125
+ file_hash)).to be false
126
+ end
127
+ end
128
+
129
+ context 'when reference build is found' do
130
+ before do
131
+ allow(response).to receive(:code).and_return('200')
132
+ end
133
+
134
+ it 'sends a POST request to the API with the correct form data and returns true' do
135
+ expect(request).to receive(:set_form).with(form_data)
136
+ expect(client).to receive(:request).with(request)
137
+
138
+ expect(OverridesTracker::Api.find_or_report_build(api_token, branch_name, last_commit_id, last_commit_name,
139
+ file_hash)).to be true
140
+ end
141
+ end
142
+
143
+ context 'when the API request fails' do
144
+ before do
145
+ allow(client).to receive(:request).and_raise(SocketError)
146
+ end
147
+
148
+ it 'raises an error' do
149
+ expect(OverridesTracker::Api.find_or_report_build(api_token, branch_name, last_commit_id, last_commit_name,
150
+ file_hash)).to be false
151
+ end
152
+ end
153
+ end
154
+
155
+ describe '.build_client' do
156
+ context 'when the port is 443' do
157
+ it 'creates a new Net::HTTP object with SSL enabled' do
158
+ uri = URI('https://example.com')
159
+ client = OverridesTracker::Api.build_client(uri)
160
+
161
+ expect(client).to be_a(Net::HTTP)
162
+ expect(client.use_ssl?).to be(true)
163
+ end
164
+ end
165
+
166
+ context 'when the port is not 443' do
167
+ it 'creates a new Net::HTTP object with SSL disabled' do
168
+ uri = URI('http://example.com')
169
+ client = OverridesTracker::Api.build_client(uri)
170
+
171
+ expect(client).to be_a(Net::HTTP)
172
+ expect(client.use_ssl?).to be(false)
173
+ end
174
+ end
175
+ end
176
+
177
+ describe '#disable_net_blockers!' do
178
+ context 'when the WebMock library is loaded' do
179
+ it 'allows the API host' do
180
+ # Set up a stub for the WebMock Config instance to return an array of allowed hosts
181
+ allow(WebMock::Config.instance).to receive(:allow).and_return(OverridesTracker::Api::API_HOST)
182
+
183
+ # Call the disable_net_blockers! method
184
+ OverridesTracker::Api.send(:disable_net_blockers!)
185
+
186
+ # Verify that the API host was added to the array of allowed hosts
187
+ expect(WebMock::Config.instance.allow).to include(OverridesTracker::Api::API_HOST)
188
+ end
189
+ end
190
+
191
+ context 'when the VCR library is loaded' do
192
+ context 'when VCR version is 2 or greater' do
193
+ let(:version) { double('version') }
194
+
195
+ it 'ignores the API host' do
196
+ allow(VCR).to receive(:version).and_return(version)
197
+ allow(version).to receive(:major).and_return(2)
198
+ # Set up a stub for the VCR configure method
199
+ allow(VCR).to receive(:configure).and_call_original
200
+ # Call the disable_net_blockers! method
201
+ OverridesTracker::Api.send(:disable_net_blockers!)
202
+
203
+ # Verify that the VCR configure method was called with the API host added to the list of ignored hosts
204
+ expect(VCR).to have_received(:configure)
205
+ expect(VCR.configuration.ignore_hosts.first).to eq(OverridesTracker::Api::API_HOST)
206
+ end
207
+ end
208
+
209
+ context 'when VCR version is under 2' do
210
+ let(:version) { double('version') }
211
+
212
+ it 'ignores the API host' do
213
+ allow(VCR).to receive(:version).and_return(version)
214
+ allow(version).to receive(:major).and_return(1)
215
+ # Set up a stub for the VCR configure method
216
+ allow(VCR).to receive(:config).and_call_original
217
+ # Call the disable_net_blockers! method
218
+ OverridesTracker::Api.send(:disable_net_blockers!)
219
+
220
+ # Verify that the VCR config method was called with the API host added to the list of ignored hosts
221
+ expect(VCR).to have_received(:config)
222
+ expect(VCR.configuration.ignore_hosts.first).to eq(OverridesTracker::Api::API_HOST)
223
+ end
224
+ end
225
+ end
226
+ end
227
+ end