coverband 2.0.1 → 2.0.2

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.
@@ -0,0 +1,152 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rack'
4
+
5
+ module Coverband
6
+ module Reporters
7
+ # TODO: move to reports and drop need for S3 allow reading from adapters?
8
+ class Web
9
+ attr_reader :request
10
+
11
+ def initialize
12
+ @static = Rack::Static.new(self,
13
+ root: File.expand_path('public', Gem::Specification.find_by_name('simplecov-html').full_gem_path),
14
+ urls: [/.*\.css/, /.*\.js/, /.*\.gif/, /.*\.png/]
15
+ )
16
+ end
17
+
18
+ def call(env)
19
+ @request = Rack::Request.new(env)
20
+
21
+ if request.post?
22
+ case request.path_info
23
+ when /\/collect_update_and_view/
24
+ collect_update_and_view
25
+ when /\/clear/
26
+ clear
27
+ when /\/update_report/
28
+ update_report
29
+ when /\/collect_coverage/
30
+ collect_coverage
31
+ when /\/reload_files/
32
+ reload_files
33
+ else
34
+ [404, {'Content-Type' => 'text/html'}, ['404 error!']]
35
+ end
36
+ else
37
+ case request.path_info
38
+ when /.*\.(css|js|gif|png)/
39
+ @static.call(env)
40
+ when /\/show/
41
+ [200, {'Content-Type' => 'text/html'}, [show]]
42
+ when /\//
43
+ [200, {'Content-Type' => 'text/html'}, [index]]
44
+ else
45
+ [404, {'Content-Type' => 'text/html'}, ['404 error!']]
46
+ end
47
+ end
48
+ end
49
+
50
+ # todo move to file or template
51
+ def index
52
+ html = "<html>"
53
+ html += "<strong>Notice:</strong> #{Rack::Utils.escape_html(request.params['notice'])}<br/>" if request.params['notice']
54
+ html += "<ul>"
55
+ html += "<li><a href='#{base_path}'>Coverband Web Admin Index</a></li>"
56
+ html += "<li>#{button("#{base_path}collect_update_and_view",'collect data, update report, & view')}</li>"
57
+ html += "<li><a href='#{base_path}show'>view coverage report</a></li>"
58
+ html += "<li>#{button("#{base_path}collect_coverage",'update coverage data (collect coverage)')}</li>"
59
+ html += "<li>#{button("#{base_path}update_report",'update coverage report (rebuild report)')}</li>"
60
+ html += "<li>#{button("#{base_path}clear",'clear coverage report')}</li>"
61
+ html += "<li>#{button("#{base_path}reload_files",'reload Coverband files')}</li>"
62
+ html += "</ul>"
63
+ html += "<br/>"
64
+ html += "version: #{Coverband::VERSION}<br/>"
65
+ html += "<a href='https://github.com/danmayer/coverband'>Coverband</a>"
66
+ html += "</html>"
67
+ html
68
+ end
69
+
70
+ def show
71
+ html = s3.get_object(bucket: Coverband.configuration.s3_bucket, key: 'coverband/index.html').body.read
72
+ # hack the static HTML assets to link to the path where this was mounted
73
+ html = html.gsub("src='", "src='#{base_path}")
74
+ html = html.gsub("href='", "href='#{base_path}")
75
+ html = html.gsub("loading.gif", "#{base_path}loading.gif")
76
+ html = html.gsub("/images/", "#{base_path}images/")
77
+ html
78
+ end
79
+
80
+ def collect_update_and_view
81
+ collect_coverage
82
+ update_report
83
+ [301, { 'Location' => "#{base_path}show" }, []]
84
+ end
85
+
86
+ def update_report
87
+ Coverband::Reporters::SimpleCovReport.report(Coverband.configuration.store, open_report: false)
88
+ notice = 'coverband coverage updated'
89
+ [301, { 'Location' => "#{base_path}?notice=#{notice}" }, []]
90
+ end
91
+
92
+ def collect_coverage
93
+ Coverband::Collectors::Base.instance.report_coverage
94
+ notice = 'coverband coverage collected'
95
+ [301, { 'Location' => "#{base_path}?notice=#{notice}" }, []]
96
+ end
97
+
98
+ def clear
99
+ Coverband.configuration.store.clear!
100
+ notice = 'coverband coverage cleared'
101
+ [301, { 'Location' => "#{base_path}?notice=#{notice}" }, []]
102
+ end
103
+
104
+ def reload_files
105
+ if Coverband.configuration.safe_reload_files
106
+ Coverband.configuration.safe_reload_files.each do |safe_file|
107
+ load safe_file
108
+ end
109
+ end
110
+ # force reload
111
+ Coverband.configure
112
+ notice = 'coverband files reloaded'
113
+ [301, { 'Location' => "#{base_path}?notice=#{notice}" }, []]
114
+ end
115
+
116
+ private
117
+
118
+ def button(url, title)
119
+ button = "<form action='#{url}' method='post'>"
120
+ button += "<button type='submit'>#{title}</button>"
121
+ button + '</form>'
122
+ end
123
+
124
+ # This method should get the root mounted endpoint
125
+ # for example if the app is mounted like so:
126
+ # mount Coverband::S3Web, at: '/coverage'
127
+ # "/coverage/collect_coverage?" become:
128
+ # /coverage/
129
+ def base_path
130
+ request.path.match("\/.*\/") ? request.path.match("\/.*\/")[0] : '/'
131
+ end
132
+
133
+ def s3
134
+ begin
135
+ require 'aws-sdk'
136
+ rescue StandardError
137
+ Coverband.configuration.logger.error "coverband requires 'aws-sdk' in order use S3ReportWriter."
138
+ return
139
+ end
140
+ @s3 ||= begin
141
+ client_options = {
142
+ region: Coverband.configuration.s3_region,
143
+ access_key_id: Coverband.configuration.s3_access_key_id,
144
+ secret_access_key: Coverband.configuration.s3_secret_access_key
145
+ }
146
+ client_options = {} if client_options.values.any?(&:nil?)
147
+ Aws::S3::Client.new(client_options)
148
+ end
149
+ end
150
+ end
151
+ end
152
+ end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # possibly move to / make an adapter or more likely a reporter
3
4
  class S3ReportWriter
4
5
  def initialize(bucket_name, options = {})
5
6
  @bucket_name = bucket_name
@@ -1,52 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  namespace :coverband do
4
- def safely_import_files(files_to_cover)
5
- if files_to_cover.any?
6
- files = Coverband::Baseline.exclude_files(files_to_cover)
7
- files.each do |file|
8
- begin
9
- require_dependency file
10
- rescue Exception => err
11
- if Coverband.configuration.verbose
12
- Coverband.configuration.logger.info "error adding file to baseline: #{file}"
13
- Coverband.configuration.logger.info "error: #{err}"
14
- end
15
- end
16
- end
17
- end
18
- end
19
-
20
- desc 'record coverband coverage baseline'
21
- task :baseline do
22
- Coverband::Baseline.record do
23
- if Rake::Task.tasks.any? { |key| key.to_s.match(/environment$/) }
24
- Coverband.configuration.logger.info 'invoking rake environment'
25
- Rake::Task['environment'].invoke
26
- elsif Rake::Task.tasks.any? { |key| key.to_s.match(/env$/) }
27
- Coverband.configuration.logger.info 'invoking rake env'
28
- Rake::Task['env'].invoke
29
- end
30
-
31
- baseline_files = [File.expand_path('./config/boot.rb', Dir.pwd),
32
- File.expand_path('./config/application.rb', Dir.pwd),
33
- File.expand_path('./config/environment.rb', Dir.pwd)]
34
-
35
- baseline_files.each do |baseline_file|
36
- require baseline_file if File.exist?(baseline_file)
37
- end
38
-
39
- safely_import_files(Coverband.configuration.additional_files.flatten)
40
-
41
- if defined? Rails
42
- safely_import_files(Dir.glob("#{Rails.root}/app/**/*.rb"))
43
- if File.exist?("#{Rails.root}/lib")
44
- safely_import_files(Dir.glob("#{Rails.root}/lib/**/*.rb"))
45
- end
46
- end
47
- end
48
- end
49
-
50
4
  ###
51
5
  # note: If your project has set many simplecov filters.
52
6
  # You might want to override them and clear the filters.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Coverband
4
- VERSION = '2.0.1'
4
+ VERSION = '2.0.2'
5
5
  end
data/lib/coverband.rb CHANGED
@@ -12,10 +12,10 @@ require 'coverband/adapters/file_store'
12
12
  require 'coverband/collectors/base'
13
13
  require 'coverband/collectors/trace'
14
14
  require 'coverband/collectors/coverage'
15
- require 'coverband/baseline'
16
15
  require 'coverband/reporters/base'
17
16
  require 'coverband/reporters/simple_cov_report'
18
17
  require 'coverband/reporters/console_report'
18
+ require 'coverband/reporters/web'
19
19
  require 'coverband/middleware'
20
20
  require 'coverband/s3_report_writer'
21
21
 
data/test/test_helper.rb CHANGED
@@ -59,11 +59,6 @@ end
59
59
 
60
60
  require 'coverband'
61
61
 
62
- unless File.exist?('./tmp/coverband_baseline.json')
63
- `mkdir -p ./tmp`
64
- `touch ./tmp/coverband_baseline.json`
65
- end
66
-
67
62
  Coverband.configure do |config|
68
63
  config.root = Dir.pwd
69
64
  config.root_paths = ['/app/']
@@ -5,52 +5,62 @@ require File.expand_path('../test_helper', File.dirname(__FILE__))
5
5
  module Coverband
6
6
  class MemoryCacheStoreTest < Test::Unit::TestCase
7
7
  def setup
8
- Adapters::MemoryCacheStore.reset!
9
- @store = mock('store')
8
+ Adapters::MemoryCacheStore.clear!
9
+ @redis = Redis.new
10
+ @store = Coverband::Adapters::RedisStore.new(@redis)
11
+ @store.clear!
10
12
  @memory_store = Adapters::MemoryCacheStore.new(@store)
11
13
  end
12
14
 
13
- def data
14
- {
15
- 'file1' => { 3 => 1, 5 => 2 },
16
- 'file2' => { 1 => 1, 2 => 1 }
17
- }
18
- end
19
-
20
15
  test 'it passes data into store' do
16
+ data = {
17
+ 'file1' => { 1 => 0, 2 => 1, 3 => 0 },
18
+ 'file2' => { 1 => 5, 2 => 2 }
19
+ }
21
20
  @store.expects(:save_report).with data
22
- @store.expects(:covered_lines_for_file).with('file1').returns []
23
- @store.expects(:covered_lines_for_file).with('file2').returns []
24
21
  @memory_store.save_report data
25
22
  end
26
23
 
27
- test 'it passes data into store only once' do
24
+
25
+ test 'it filters coverage with same exact data' do
26
+ data = {
27
+ 'file1' => { 1 => 0, 2 => 1, 3 => 0 },
28
+ 'file2' => { 1 => 5, 2 => 2 }
29
+ }
28
30
  @store.expects(:save_report).once.with data
29
- @store.expects(:covered_lines_for_file).with('file1').returns []
30
- @store.expects(:covered_lines_for_file).with('file2').returns []
31
31
  2.times { @memory_store.save_report data }
32
32
  end
33
+
34
+ test 'it filters coverage for files with same exact data' do
35
+
36
+ report_first_request = {
37
+ 'file1' => { 1 => 0, 2 => 1, 3 => 0 },
38
+ 'file2' => { 1 => 5, 2 => 2 }
39
+ }
33
40
 
34
- test 'it only passes files and lines we have not hit yet' do
35
- second_data = {
36
- 'file1' => { 3 => 1, 5 => 1, 10 => 1 },
37
- 'file2' => { 1 => 1, 2 => 1 }
41
+ report_second_request = {
42
+ 'file1' => { 1 => 0, 2 => 1, 3 => 0 },
43
+ 'file2' => { 1 => 5, 2 => 3 }
38
44
  }
39
- @store.expects(:covered_lines_for_file).with('file1').returns []
40
- @store.expects(:covered_lines_for_file).with('file2').returns []
41
- @store.expects(:save_report).once.with data
42
- @store.expects(:save_report).once.with(
43
- 'file1' => { 10 => 1 }
44
- )
45
- @memory_store.save_report data
46
- @memory_store.save_report second_data
45
+ @store.expects(:save_report).with({
46
+ 'file1' => { 1 => 0, 2 => 1, 3 => 0 },
47
+ 'file2' => { 1 => 5, 2 => 2 }
48
+ })
49
+ @store.expects(:save_report).with({
50
+ 'file2' => { 1 => 5, 2 => 3 }
51
+ })
52
+ @memory_store.save_report(report_first_request)
53
+ @memory_store.save_report(report_second_request)
47
54
  end
48
55
 
49
56
  test 'it initializes cache with what is in store' do
50
- @store.expects(:covered_lines_for_file).with('file1').returns [3, 5]
51
- @store.expects(:covered_lines_for_file).with('file2').returns [2]
52
- @store.expects(:save_report).with('file2' => { 1 => 1 })
53
- @memory_store.save_report data
57
+ data = {
58
+ 'file1' => { 1 => 0, 2 => 1, 3 => 0 },
59
+ 'file2' => { 1 => 5, 2 => 2 }
60
+ }
61
+ Coverband::Adapters::RedisStore.new(@redis).save_report(data)
62
+ @store.expects(:save_report).never
63
+ @memory_store.save_report(data)
54
64
  end
55
65
  end
56
66
  end
@@ -49,6 +49,7 @@ class CollectorsBaseTest < Test::Unit::TestCase
49
49
  coverband.instance_variable_set('@store', nil)
50
50
  assert_equal false, coverband.instance_variable_get('@enabled')
51
51
  logger.expects(:info).at_least_once
52
+ logger.stubs('debug')
52
53
  coverband.sample { 1 + 1 }
53
54
  assert_equal true, coverband.instance_variable_get('@enabled')
54
55
  end
@@ -62,8 +63,8 @@ class CollectorsBaseTest < Test::Unit::TestCase
62
63
  coverband.instance_variable_set('@store', nil)
63
64
  assert_equal false, coverband.instance_variable_get('@enabled')
64
65
  logger.expects(:info).at_least_once
66
+ logger.stubs('debug')
65
67
  coverband.start
66
- logger.info(1 + 1)
67
68
  coverband.stop
68
69
  coverband.save
69
70
  end
@@ -74,6 +75,7 @@ class CollectorsBaseTest < Test::Unit::TestCase
74
75
  coverband.instance_variable_set('@sample_percentage', 100.0)
75
76
  coverband.instance_variable_set('@verbose', true)
76
77
  Coverband.configuration.logger.stubs('info')
78
+ Coverband.configuration.logger.stubs('debug')
77
79
  store = Coverband::Adapters::RedisStore.new(Redis.new)
78
80
  coverband.instance_variable_set('@store', store)
79
81
  store.expects(:save_report).once.with(has_entries(dog_file => {5 => 5}))
@@ -61,7 +61,8 @@ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.3.0')
61
61
  coverband.instance_variable_set('@logger', logger)
62
62
  coverband.instance_variable_set('@store', nil)
63
63
  assert_equal false, coverband.instance_variable_get('@enabled')
64
- logger.expects(:info).at_least_once
64
+ logger.stubs('info')
65
+ logger.expects(:debug).at_least_once
65
66
  coverband.sample { 1 + 1 }
66
67
  assert_equal true, coverband.instance_variable_get('@enabled')
67
68
  end
@@ -74,6 +75,7 @@ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.3.0')
74
75
  coverband.instance_variable_set('@store', nil)
75
76
  assert_equal false, coverband.instance_variable_get('@enabled')
76
77
  logger.expects(:info).at_least_once
78
+ logger.stubs('debug')
77
79
  coverband.start
78
80
  logger.info(1 + 1)
79
81
  coverband.stop
@@ -83,8 +85,6 @@ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.3.0')
83
85
  test 'allow reporting to redis start stop save' do
84
86
  dog_file = File.expand_path('./dog.rb', File.dirname(__FILE__))
85
87
  coverband.instance_variable_set('@sample_percentage', 100.0)
86
- coverband.instance_variable_set('@verbose', true)
87
- Coverband.configuration.logger.stubs('info')
88
88
  store = Coverband::Adapters::RedisStore.new(Redis.new)
89
89
  coverband.instance_variable_set('@store', store)
90
90
 
@@ -50,6 +50,7 @@ class CollectorsTraceTest < Test::Unit::TestCase
50
50
  coverband.instance_variable_set('@store', nil)
51
51
  assert_equal false, coverband.instance_variable_get('@enabled')
52
52
  logger.expects(:info).at_least_once
53
+ logger.stubs('debug')
53
54
  coverband.sample { 1 + 1 }
54
55
  assert_equal true, coverband.instance_variable_get('@enabled')
55
56
  end
@@ -63,8 +64,8 @@ class CollectorsTraceTest < Test::Unit::TestCase
63
64
  coverband.instance_variable_set('@store', nil)
64
65
  assert_equal false, coverband.instance_variable_get('@enabled')
65
66
  logger.expects(:info).at_least_once
67
+ logger.stubs('debug')
66
68
  coverband.start
67
- logger.info(1 + 1)
68
69
  coverband.stop
69
70
  coverband.save
70
71
  end
@@ -75,6 +76,7 @@ class CollectorsTraceTest < Test::Unit::TestCase
75
76
  coverband.instance_variable_set('@sample_percentage', 100.0)
76
77
  coverband.instance_variable_set('@verbose', true)
77
78
  Coverband.configuration.logger.stubs('info')
79
+ Coverband.configuration.logger.stubs('debug')
78
80
  store = Coverband::Adapters::RedisStore.new(Redis.new)
79
81
  coverband.instance_variable_set('@store', store)
80
82
  store.expects(:save_report).once.with(has_entries(dog_file => { 5 => 5 }))
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../test_helper', File.dirname(__FILE__))
4
+ require 'aws-sdk'
5
+ require File.expand_path('../../lib/coverband/reporters/web', File.dirname(__FILE__))
6
+ require 'rack/test'
7
+
8
+ ENV['RACK_ENV'] = 'test'
9
+
10
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.2.0')
11
+ module Coverband
12
+ class S3WebTest < Test::Unit::TestCase
13
+ include Rack::Test::Methods
14
+
15
+ def app
16
+ Coverband::Reporters::Web.new
17
+ end
18
+
19
+ # TODO add tests for all endpoints
20
+ test 'renders index content' do
21
+ get '/'
22
+ assert last_response.ok?
23
+ assert_match 'Coverband Web Admin Index', last_response.body
24
+ end
25
+
26
+ test 'renders show content' do
27
+ Coverband.configuration.s3_bucket = 'coverage-bucket'
28
+ s3 = mock('s3')
29
+ Aws::S3::Client.expects(:new).returns(s3)
30
+ s3.expects(:get_object).with(bucket: 'coverage-bucket', key: 'coverband/index.html').returns mock('response', body: mock('body', read: 'content'))
31
+ get '/show'
32
+ assert last_response.ok?
33
+ assert_equal 'content', last_response.body
34
+ end
35
+ end
36
+ end
37
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coverband
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Mayer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-08 00:00:00.000000000 Z
11
+ date: 2018-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk
@@ -108,20 +108,6 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
- - !ruby/object:Gem::Dependency
112
- name: sinatra
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
111
  - !ruby/object:Gem::Dependency
126
112
  name: test-unit
127
113
  requirement: !ruby/object:Gem::Requirement
@@ -207,6 +193,7 @@ files:
207
193
  - README.md
208
194
  - Rakefile
209
195
  - changes.md
196
+ - config.ru
210
197
  - coverband.gemspec
211
198
  - docs/coverband-install-resize.gif
212
199
  - docs/coverband_details.png
@@ -217,7 +204,6 @@ files:
217
204
  - lib/coverband/adapters/file_store.rb
218
205
  - lib/coverband/adapters/memory_cache_store.rb
219
206
  - lib/coverband/adapters/redis_store.rb
220
- - lib/coverband/baseline.rb
221
207
  - lib/coverband/collectors/base.rb
222
208
  - lib/coverband/collectors/coverage.rb
223
209
  - lib/coverband/collectors/trace.rb
@@ -226,8 +212,8 @@ files:
226
212
  - lib/coverband/reporters/base.rb
227
213
  - lib/coverband/reporters/console_report.rb
228
214
  - lib/coverband/reporters/simple_cov_report.rb
215
+ - lib/coverband/reporters/web.rb
229
216
  - lib/coverband/s3_report_writer.rb
230
- - lib/coverband/s3_web.rb
231
217
  - lib/coverband/tasks.rb
232
218
  - lib/coverband/version.rb
233
219
  - test/benchmarks/.gitignore
@@ -238,7 +224,6 @@ files:
238
224
  - test/unit/adapters_file_store_test.rb
239
225
  - test/unit/adapters_memory_cache_store_test.rb
240
226
  - test/unit/adapters_redis_store_test.rb
241
- - test/unit/baseline_test.rb
242
227
  - test/unit/collectors_base_test.rb
243
228
  - test/unit/collectors_coverage_test.rb
244
229
  - test/unit/collectors_trace_test.rb
@@ -248,8 +233,8 @@ files:
248
233
  - test/unit/reports_base_test.rb
249
234
  - test/unit/reports_console_test.rb
250
235
  - test/unit/reports_simple_cov_test.rb
236
+ - test/unit/reports_web_test.rb
251
237
  - test/unit/s3_report_writer_test.rb
252
- - test/unit/s3_web_test.rb
253
238
  homepage: https://github.com/danmayer/coverband
254
239
  licenses:
255
240
  - MIT
@@ -283,7 +268,6 @@ test_files:
283
268
  - test/unit/adapters_file_store_test.rb
284
269
  - test/unit/adapters_memory_cache_store_test.rb
285
270
  - test/unit/adapters_redis_store_test.rb
286
- - test/unit/baseline_test.rb
287
271
  - test/unit/collectors_base_test.rb
288
272
  - test/unit/collectors_coverage_test.rb
289
273
  - test/unit/collectors_trace_test.rb
@@ -293,5 +277,5 @@ test_files:
293
277
  - test/unit/reports_base_test.rb
294
278
  - test/unit/reports_console_test.rb
295
279
  - test/unit/reports_simple_cov_test.rb
280
+ - test/unit/reports_web_test.rb
296
281
  - test/unit/s3_report_writer_test.rb
297
- - test/unit/s3_web_test.rb
@@ -1,44 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Coverband
4
- class Baseline
5
- def self.record
6
- require 'coverage'
7
- Coverage.start
8
- yield
9
-
10
- project_directory = File.expand_path(Coverband.configuration.root)
11
- results = Coverage.result
12
- results = results.reject { |key, _val| !key.match(project_directory) || Coverband.configuration.ignore.any? { |pattern| key.match(/#{pattern}/) } }
13
-
14
- Coverband.configuration.store.save_report(convert_coverage_format(results))
15
- end
16
-
17
- def self.parse_baseline(_back_compat = nil)
18
- Coverband.configuration.store.coverage
19
- end
20
-
21
- def self.exclude_files(files)
22
- Coverband.configuration.ignore.each do |ignore|
23
- path = Coverband.configuration.root + "/#{ignore}"
24
- excludes = File.directory?(path) ? Dir.glob("#{path}/**/*") : [path]
25
- files -= excludes
26
- end
27
- files
28
- end
29
-
30
- private
31
-
32
- def self.convert_coverage_format(results)
33
- file_map = {}
34
- results.each_pair do |file, data|
35
- lines_map = {}
36
- data.each_with_index do |hits, index|
37
- lines_map[(index + 1)] = hits unless hits.nil?
38
- end
39
- file_map[file] = lines_map
40
- end
41
- file_map
42
- end
43
- end
44
- end
@@ -1,62 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'sinatra/base'
4
-
5
- module Coverband
6
- class S3Web < Sinatra::Base
7
- set :public_folder, proc(){ File.expand_path('public', Gem::Specification.find_by_name('simplecov-html').full_gem_path) }
8
-
9
- get '/' do
10
- html = s3.get_object(bucket: Coverband.configuration.s3_bucket, key: 'coverband/index.html').body.read
11
- # hack the static HTML assets to account for where this was mounted
12
- html = html.gsub("src='", "src='#{request.path}")
13
- html = html.gsub("href='", "href='#{request.path}")
14
- html = html.gsub("loading.gif", "#{request.path}loading.gif")
15
- html = html.gsub("/images/", "#{request.path}/images/")
16
- html
17
- end
18
-
19
- post '/update_report' do
20
- Coverband::Reporters::SimpleCovReport.report(Coverband.configuration.store, open_report: false)
21
- notice = "coverband coverage updated"
22
- redirect "/?notice=#{notice}", 301
23
- end
24
-
25
- post '/clear' do
26
- Coverband.configuration.store.clear!
27
- notice = "coverband coverage cleared"
28
- redirect "/?notice=#{notice}", 301
29
- end
30
-
31
- post '/reload_files' do
32
- if Coverband.configuration.safe_reload_files
33
- Coverband.configuration.safe_reload_files.each do |safe_file|
34
- load safe_file
35
- end
36
- end
37
- Coverband.configure
38
- notice = "coverband files reloaded"
39
- redirect "/?notice=#{notice}", 301
40
- end
41
-
42
- private
43
-
44
- def s3
45
- begin
46
- require 'aws-sdk'
47
- rescue StandardError
48
- Coverband.configuration.logger.error "coverband requires 'aws-sdk' in order use S3ReportWriter."
49
- return
50
- end
51
- @s3 ||= begin
52
- client_options = {
53
- region: Coverband.configuration.s3_region,
54
- access_key_id: Coverband.configuration.s3_access_key_id,
55
- secret_access_key: Coverband.configuration.s3_secret_access_key
56
- }
57
- client_options = {} if client_options.values.any?(&:nil?)
58
- Aws::S3::Client.new(client_options)
59
- end
60
- end
61
- end
62
- end