coverband 4.2.5 → 5.0.0.rc.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +25 -0
  3. data/.travis.yml +2 -1
  4. data/Gemfile +5 -7
  5. data/Gemfile.rails4 +0 -3
  6. data/Gemfile.rails6 +0 -3
  7. data/README.md +24 -77
  8. data/Rakefile +17 -17
  9. data/changes.md +31 -34
  10. data/config.ru +1 -1
  11. data/coverband.gemspec +30 -34
  12. data/lib/alternative_coverband_patch.rb +5 -0
  13. data/lib/coverband.rb +68 -44
  14. data/lib/coverband/adapters/base.rb +17 -18
  15. data/lib/coverband/adapters/file_store.rb +38 -6
  16. data/lib/coverband/adapters/hash_redis_store.rb +24 -21
  17. data/lib/coverband/adapters/redis_store.rb +12 -12
  18. data/lib/coverband/adapters/stdout_store.rb +41 -0
  19. data/lib/coverband/adapters/web_service_store.rb +157 -0
  20. data/lib/coverband/at_exit.rb +1 -1
  21. data/lib/coverband/collectors/coverage.rb +15 -27
  22. data/lib/coverband/collectors/delta.rb +29 -9
  23. data/lib/coverband/collectors/view_tracker.rb +19 -11
  24. data/lib/coverband/collectors/view_tracker_service.rb +59 -0
  25. data/lib/coverband/configuration.rb +121 -88
  26. data/lib/coverband/integrations/background.rb +6 -6
  27. data/lib/coverband/integrations/rack_server_check.rb +3 -3
  28. data/lib/coverband/integrations/resque.rb +13 -1
  29. data/lib/coverband/reporters/base.rb +10 -10
  30. data/lib/coverband/reporters/console_report.rb +1 -1
  31. data/lib/coverband/reporters/html_report.rb +10 -30
  32. data/lib/coverband/reporters/web.rb +55 -50
  33. data/lib/coverband/utils/absolute_file_converter.rb +6 -6
  34. data/lib/coverband/utils/html_formatter.rb +32 -61
  35. data/lib/coverband/utils/railtie.rb +23 -6
  36. data/lib/coverband/utils/relative_file_converter.rb +2 -2
  37. data/lib/coverband/utils/result.rb +6 -11
  38. data/lib/coverband/utils/results.rb +0 -10
  39. data/lib/coverband/utils/source_file.rb +21 -30
  40. data/lib/coverband/utils/tasks.rb +8 -11
  41. data/lib/coverband/version.rb +1 -1
  42. data/public/application.js +0 -30
  43. data/test/benchmarks/benchmark.rake +97 -92
  44. data/test/benchmarks/dog.rb +1 -1
  45. data/test/benchmarks/init_rails.rake +4 -4
  46. data/test/coverband/adapters/base_test.rb +29 -30
  47. data/test/coverband/adapters/file_store_test.rb +19 -20
  48. data/test/coverband/adapters/hash_redis_store_test.rb +57 -57
  49. data/test/coverband/adapters/redis_store_test.rb +26 -26
  50. data/test/coverband/adapters/web_service_store_test.rb +56 -0
  51. data/test/coverband/at_exit_test.rb +2 -2
  52. data/test/coverband/collectors/coverage_test.rb +33 -47
  53. data/test/coverband/collectors/delta_test.rb +52 -23
  54. data/test/coverband/collectors/view_tracker_test.rb +35 -35
  55. data/test/coverband/configuration_test.rb +27 -53
  56. data/test/coverband/coverband_test.rb +11 -11
  57. data/test/coverband/integrations/background_middleware_test.rb +10 -10
  58. data/test/coverband/integrations/background_test.rb +6 -5
  59. data/test/coverband/integrations/rack_server_check_test.rb +7 -7
  60. data/test/coverband/integrations/report_middleware_test.rb +9 -9
  61. data/test/coverband/integrations/resque_worker_test.rb +9 -9
  62. data/test/coverband/integrations/test_resque_job.rb +1 -1
  63. data/test/coverband/reporters/base_test.rb +9 -9
  64. data/test/coverband/reporters/console_test.rb +6 -6
  65. data/test/coverband/reporters/html_test.rb +36 -48
  66. data/test/coverband/reporters/web_test.rb +16 -18
  67. data/test/coverband/utils/absolute_file_converter_test.rb +22 -22
  68. data/test/coverband/utils/file_hasher_test.rb +6 -12
  69. data/test/coverband/utils/file_list_test.rb +13 -13
  70. data/test/coverband/utils/html_formatter_test.rb +9 -23
  71. data/test/coverband/utils/lines_classifier_test.rb +29 -29
  72. data/test/coverband/utils/relative_file_converter_test.rb +13 -13
  73. data/test/coverband/utils/result_test.rb +18 -18
  74. data/test/coverband/utils/results_test.rb +17 -17
  75. data/test/coverband/utils/source_file_line_test.rb +46 -46
  76. data/test/coverband/utils/source_file_test.rb +38 -88
  77. data/test/dog.rb +1 -1
  78. data/test/fake_app/basic_rack.rb +2 -2
  79. data/test/fixtures/app/controllers/sample_controller.rb +1 -1
  80. data/test/fixtures/app/models/user.rb +1 -1
  81. data/test/fixtures/sample.rb +1 -1
  82. data/test/fixtures/utf-8.rb +0 -2
  83. data/test/forked/rails_full_stack_test.rb +24 -27
  84. data/test/forked/rails_rake_full_stack_test.rb +7 -26
  85. data/test/integration/full_stack_test.rb +11 -22
  86. data/test/jruby_check.rb +2 -3
  87. data/test/rails4_dummy/Rakefile +1 -1
  88. data/test/rails4_dummy/config.ru +1 -1
  89. data/test/rails4_dummy/config/application.rb +4 -4
  90. data/test/rails4_dummy/config/boot.rb +2 -2
  91. data/test/rails4_dummy/config/coverband.rb +1 -1
  92. data/test/rails4_dummy/config/coverband_missing_redis.rb +1 -1
  93. data/test/rails4_dummy/config/environment.rb +1 -1
  94. data/test/rails4_dummy/config/routes.rb +2 -2
  95. data/test/rails5_dummy/Rakefile +1 -1
  96. data/test/rails5_dummy/config.ru +1 -1
  97. data/test/rails5_dummy/config/application.rb +3 -3
  98. data/test/rails5_dummy/config/coverband.rb +8 -8
  99. data/test/rails5_dummy/config/coverband_missing_redis.rb +8 -8
  100. data/test/rails5_dummy/config/environment.rb +1 -1
  101. data/test/rails5_dummy/config/routes.rb +2 -2
  102. data/test/rails6_dummy/Rakefile +1 -1
  103. data/test/rails6_dummy/config.ru +1 -1
  104. data/test/rails6_dummy/config/application.rb +4 -4
  105. data/test/rails6_dummy/config/boot.rb +2 -2
  106. data/test/rails6_dummy/config/coverband.rb +1 -1
  107. data/test/rails6_dummy/config/coverband_missing_redis.rb +1 -1
  108. data/test/rails6_dummy/config/environment.rb +1 -1
  109. data/test/rails6_dummy/config/routes.rb +2 -2
  110. data/test/rails_test_helper.rb +11 -11
  111. data/test/test_helper.rb +43 -34
  112. data/test/unique_files.rb +10 -10
  113. data/views/layout.erb +2 -12
  114. metadata +15 -34
  115. data/.rubocop.yml +0 -84
  116. data/lib/coverband/integrations/bundler.rb +0 -8
  117. data/lib/coverband/utils/file_groups.rb +0 -53
  118. data/lib/coverband/utils/gem_list.rb +0 -31
  119. data/lib/coverband/utils/s3_report.rb +0 -105
  120. data/test/coverband/utils/file_groups_test.rb +0 -61
  121. data/test/coverband/utils/gem_list_test.rb +0 -48
  122. data/test/coverband/utils/s3_report_test.rb +0 -44
  123. data/views/gem_list.erb +0 -63
@@ -1,29 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'securerandom'
4
- require 'fileutils'
5
- require 'erb'
6
- require 'ostruct'
3
+ require "securerandom"
4
+ require "fileutils"
5
+ require "erb"
6
+ require "ostruct"
7
7
 
8
- UNIQUE_FILES_DIR = './test/unique_files'
8
+ UNIQUE_FILES_DIR = "./test/unique_files"
9
9
 
10
- def require_unique_file(file = 'dog.rb', variables = {})
10
+ def require_unique_file(file = "dog.rb", variables = {})
11
11
  uuid = SecureRandom.uuid
12
12
  dir = "#{UNIQUE_FILES_DIR}/#{uuid}"
13
- file_name = file.sub('.erb', '')
13
+ file_name = file.sub(".erb", "")
14
14
  temp_file = "#{dir}/#{file_name}"
15
15
  FileUtils.mkdir_p(Pathname.new(temp_file).dirname.to_s)
16
16
  file_contents = File.read("./test/#{file}")
17
17
  file_contents = ERB.new(file_contents).result(OpenStruct.new(variables).instance_eval { binding }) if variables.any?
18
- File.open(temp_file, 'w') { |w| w.write(file_contents) }
18
+ File.open(temp_file, "w") { |w| w.write(file_contents) }
19
19
  require temp_file
20
20
  Coverband::Utils::RelativeFileConverter.convert(File.expand_path(temp_file))
21
21
  end
22
22
 
23
23
  @@dogs = 0
24
24
  def require_class_unique_file
25
- @@dogs +=1
26
- require_unique_file('dog.rb.erb', dog_number: @@dogs)
25
+ @@dogs += 1
26
+ require_unique_file("dog.rb.erb", dog_number: @@dogs)
27
27
  end
28
28
 
29
29
  def remove_unique_files
@@ -18,11 +18,7 @@
18
18
  <%= display_nav %>
19
19
 
20
20
  <div id="content">
21
- <%= formatted_file_list("All Files", result, result.source_files) unless view_gems? %>
22
-
23
- <% result.groups.each do |name, files| %>
24
- <%= formatted_file_list(name, result, files) %>
25
- <% end %>
21
+ <%= formatted_file_list("Coverage", result, result.source_files) %>
26
22
  </div>
27
23
 
28
24
  <div id="footer">
@@ -31,13 +27,7 @@
31
27
 
32
28
  <div class="source_files">
33
29
  <% result.source_files.each do |source_file| %>
34
- <% if (!source_file.gem? || (view_gems? && gem_details? && source_file.gem? )) %>
35
- <% if static_html? %>
36
- <%= formatted_source_file(result, source_file) %>
37
- <% else %>
38
- <%= formatted_source_file_loader(result, source_file) %>
39
- <% end %>
40
- <% end %>
30
+ <%= formatted_source_file_loader(result, source_file) %>
41
31
  <% end %>
42
32
  </div>
43
33
  </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coverband
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.5
4
+ version: 5.0.0.rc.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Mayer
@@ -9,22 +9,8 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-04-27 00:00:00.000000000 Z
12
+ date: 2020-08-17 00:00:00.000000000 Z
13
13
  dependencies:
14
- - !ruby/object:Gem::Dependency
15
- name: aws-sdk-s3
16
- requirement: !ruby/object:Gem::Requirement
17
- requirements:
18
- - - "~>"
19
- - !ruby/object:Gem::Version
20
- version: '1'
21
- type: :development
22
- prerelease: false
23
- version_requirements: !ruby/object:Gem::Requirement
24
- requirements:
25
- - - "~>"
26
- - !ruby/object:Gem::Version
27
- version: '1'
28
14
  - !ruby/object:Gem::Dependency
29
15
  name: benchmark-ips
30
16
  requirement: !ruby/object:Gem::Requirement
@@ -180,7 +166,7 @@ dependencies:
180
166
  - !ruby/object:Gem::Version
181
167
  version: '0'
182
168
  - !ruby/object:Gem::Dependency
183
- name: rubocop
169
+ name: standardrb
184
170
  requirement: !ruby/object:Gem::Requirement
185
171
  requirements:
186
172
  - - ">="
@@ -194,7 +180,7 @@ dependencies:
194
180
  - !ruby/object:Gem::Version
195
181
  version: '0'
196
182
  - !ruby/object:Gem::Dependency
197
- name: rubocop-performance
183
+ name: coveralls
198
184
  requirement: !ruby/object:Gem::Requirement
199
185
  requirements:
200
186
  - - ">="
@@ -208,7 +194,7 @@ dependencies:
208
194
  - !ruby/object:Gem::Version
209
195
  version: '0'
210
196
  - !ruby/object:Gem::Dependency
211
- name: coveralls
197
+ name: minitest-profile
212
198
  requirement: !ruby/object:Gem::Requirement
213
199
  requirements:
214
200
  - - ">="
@@ -222,7 +208,7 @@ dependencies:
222
208
  - !ruby/object:Gem::Version
223
209
  version: '0'
224
210
  - !ruby/object:Gem::Dependency
225
- name: minitest-profile
211
+ name: webmock
226
212
  requirement: !ruby/object:Gem::Requirement
227
213
  requirements:
228
214
  - - ">="
@@ -258,7 +244,7 @@ extra_rdoc_files: []
258
244
  files:
259
245
  - ".gitignore"
260
246
  - ".jrubyrc"
261
- - ".rubocop.yml"
247
+ - ".standard.yml"
262
248
  - ".travis.yml"
263
249
  - CODE_OF_CONDUCT.md
264
250
  - Gemfile
@@ -271,19 +257,22 @@ files:
271
257
  - changes.md
272
258
  - config.ru
273
259
  - coverband.gemspec
260
+ - lib/alternative_coverband_patch.rb
274
261
  - lib/coverband.rb
275
262
  - lib/coverband/adapters/base.rb
276
263
  - lib/coverband/adapters/file_store.rb
277
264
  - lib/coverband/adapters/hash_redis_store.rb
278
265
  - lib/coverband/adapters/redis_store.rb
266
+ - lib/coverband/adapters/stdout_store.rb
267
+ - lib/coverband/adapters/web_service_store.rb
279
268
  - lib/coverband/at_exit.rb
280
269
  - lib/coverband/collectors/coverage.rb
281
270
  - lib/coverband/collectors/delta.rb
282
271
  - lib/coverband/collectors/view_tracker.rb
272
+ - lib/coverband/collectors/view_tracker_service.rb
283
273
  - lib/coverband/configuration.rb
284
274
  - lib/coverband/integrations/background.rb
285
275
  - lib/coverband/integrations/background_middleware.rb
286
- - lib/coverband/integrations/bundler.rb
287
276
  - lib/coverband/integrations/rack_server_check.rb
288
277
  - lib/coverband/integrations/report_middleware.rb
289
278
  - lib/coverband/integrations/resque.rb
@@ -292,10 +281,8 @@ files:
292
281
  - lib/coverband/reporters/html_report.rb
293
282
  - lib/coverband/reporters/web.rb
294
283
  - lib/coverband/utils/absolute_file_converter.rb
295
- - lib/coverband/utils/file_groups.rb
296
284
  - lib/coverband/utils/file_hasher.rb
297
285
  - lib/coverband/utils/file_list.rb
298
- - lib/coverband/utils/gem_list.rb
299
286
  - lib/coverband/utils/html_formatter.rb
300
287
  - lib/coverband/utils/jruby_ext.rb
301
288
  - lib/coverband/utils/lines_classifier.rb
@@ -303,7 +290,6 @@ files:
303
290
  - lib/coverband/utils/relative_file_converter.rb
304
291
  - lib/coverband/utils/result.rb
305
292
  - lib/coverband/utils/results.rb
306
- - lib/coverband/utils/s3_report.rb
307
293
  - lib/coverband/utils/source_file.rb
308
294
  - lib/coverband/utils/tasks.rb
309
295
  - lib/coverband/version.rb
@@ -350,6 +336,7 @@ files:
350
336
  - test/coverband/adapters/file_store_test.rb
351
337
  - test/coverband/adapters/hash_redis_store_test.rb
352
338
  - test/coverband/adapters/redis_store_test.rb
339
+ - test/coverband/adapters/web_service_store_test.rb
353
340
  - test/coverband/at_exit_test.rb
354
341
  - test/coverband/collectors/coverage_test.rb
355
342
  - test/coverband/collectors/delta_test.rb
@@ -367,16 +354,13 @@ files:
367
354
  - test/coverband/reporters/html_test.rb
368
355
  - test/coverband/reporters/web_test.rb
369
356
  - test/coverband/utils/absolute_file_converter_test.rb
370
- - test/coverband/utils/file_groups_test.rb
371
357
  - test/coverband/utils/file_hasher_test.rb
372
358
  - test/coverband/utils/file_list_test.rb
373
- - test/coverband/utils/gem_list_test.rb
374
359
  - test/coverband/utils/html_formatter_test.rb
375
360
  - test/coverband/utils/lines_classifier_test.rb
376
361
  - test/coverband/utils/relative_file_converter_test.rb
377
362
  - test/coverband/utils/result_test.rb
378
363
  - test/coverband/utils/results_test.rb
379
- - test/coverband/utils/s3_report_test.rb
380
364
  - test/coverband/utils/source_file_line_test.rb
381
365
  - test/coverband/utils/source_file_test.rb
382
366
  - test/dog.rb
@@ -429,7 +413,6 @@ files:
429
413
  - test/unique_files.rb
430
414
  - views/data.erb
431
415
  - views/file_list.erb
432
- - views/gem_list.erb
433
416
  - views/layout.erb
434
417
  - views/nav.erb
435
418
  - views/settings.erb
@@ -451,9 +434,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
451
434
  version: '0'
452
435
  required_rubygems_version: !ruby/object:Gem::Requirement
453
436
  requirements:
454
- - - ">="
437
+ - - ">"
455
438
  - !ruby/object:Gem::Version
456
- version: '0'
439
+ version: 1.3.1
457
440
  requirements: []
458
441
  rubygems_version: 3.0.3
459
442
  signing_key:
@@ -471,6 +454,7 @@ test_files:
471
454
  - test/coverband/adapters/file_store_test.rb
472
455
  - test/coverband/adapters/hash_redis_store_test.rb
473
456
  - test/coverband/adapters/redis_store_test.rb
457
+ - test/coverband/adapters/web_service_store_test.rb
474
458
  - test/coverband/at_exit_test.rb
475
459
  - test/coverband/collectors/coverage_test.rb
476
460
  - test/coverband/collectors/delta_test.rb
@@ -488,16 +472,13 @@ test_files:
488
472
  - test/coverband/reporters/html_test.rb
489
473
  - test/coverband/reporters/web_test.rb
490
474
  - test/coverband/utils/absolute_file_converter_test.rb
491
- - test/coverband/utils/file_groups_test.rb
492
475
  - test/coverband/utils/file_hasher_test.rb
493
476
  - test/coverband/utils/file_list_test.rb
494
- - test/coverband/utils/gem_list_test.rb
495
477
  - test/coverband/utils/html_formatter_test.rb
496
478
  - test/coverband/utils/lines_classifier_test.rb
497
479
  - test/coverband/utils/relative_file_converter_test.rb
498
480
  - test/coverband/utils/result_test.rb
499
481
  - test/coverband/utils/results_test.rb
500
- - test/coverband/utils/s3_report_test.rb
501
482
  - test/coverband/utils/source_file_line_test.rb
502
483
  - test/coverband/utils/source_file_test.rb
503
484
  - test/dog.rb
@@ -1,84 +0,0 @@
1
- AllCops:
2
- TargetRubyVersion: 2.4
3
- Exclude:
4
- - vendor/bundle/**/*
5
- - docs/**/*
6
- - test/rails6_dummy/**/*
7
- - test/rails5_dummy/**/*
8
- - test/fixtures/**/*
9
- # Get the code passing first then we will enable for tests
10
- - test/**/*
11
- Documentation:
12
- Enabled: false
13
- Metrics/MethodLength:
14
- Enabled: false
15
- Layout/LineLength:
16
- Max: 160
17
- Metrics/BlockNesting:
18
- Max: 5
19
- Metrics/BlockLength:
20
- Max: 30
21
- Metrics/CyclomaticComplexity:
22
- Enabled: false
23
- Metrics/PerceivedComplexity:
24
- Enabled: false
25
- Metrics/AbcSize:
26
- Enabled: false
27
- Metrics/ClassLength:
28
- Enabled: false
29
- Metrics/ModuleLength:
30
- Enabled: false
31
- Metrics/ParameterLists:
32
- Max: 10
33
- Naming/AccessorMethodName:
34
- Enabled: false
35
- Naming/RescuedExceptionsVariableName:
36
- Enabled: false
37
- Naming/PredicateName:
38
- Enabled: true
39
- Style/TernaryParentheses:
40
- Enabled: false
41
- Style/MutableConstant:
42
- Enabled: false
43
- Style/IdenticalConditionalBranches:
44
- Enabled: false
45
- Style/ClassVars:
46
- Enabled: false
47
- Style/MultilineBlockChain:
48
- Enabled: false
49
- Style/StringLiterals:
50
- Enabled: false
51
- Style/IfInsideElse:
52
- Enabled: false
53
- Style/FrozenStringLiteralComment:
54
- Enabled: true
55
- Style/GuardClause:
56
- Enabled: true
57
- Style/NumericPredicate:
58
- Enabled: true
59
- Style/NumericLiterals:
60
- Enabled: false
61
- Style/NumericLiteralPrefix:
62
- Enabled: false
63
- Style/ClassAndModuleChildren:
64
- Enabled: false
65
- Style/SymbolArray:
66
- Enabled: false
67
- Style/SymbolProc:
68
- Enabled: false
69
- Style/RegexpLiteral:
70
- Enabled: false
71
- Layout/MultilineMethodCallIndentation:
72
- Enabled: true
73
- Layout/MultilineOperationIndentation:
74
- Enabled: true
75
- Lint/RescueException:
76
- Enabled: true
77
- Lint/UselessAccessModifier:
78
- Enabled: true
79
- Lint/ShadowingOuterLocalVariable:
80
- Enabled: true
81
- Style/FormatString:
82
- Enabled: true
83
- Security/Eval:
84
- Enabled: true
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module BundlerEagerLoad
4
- def require(*groups)
5
- Coverband.eager_loading_coverage { super }
6
- end
7
- end
8
- Bundler.singleton_class.prepend BundlerEagerLoad
@@ -1,53 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- #
4
- # Applies the configured groups to the given array of Coverband::SourceFile items
5
- #
6
- module Coverband
7
- module Utils
8
- class FileGroups
9
- def initialize(files)
10
- @grouped = {}
11
- @files = files
12
- filter_to_groups
13
- end
14
-
15
- def grouped_results
16
- @grouped
17
- end
18
-
19
- private
20
-
21
- def filter_to_groups
22
- grouped_files = []
23
- Coverband.configuration.groups.each do |name, filter|
24
- if name == 'Gems'
25
- gem_lists = gem_files(name, filter)
26
- grouped_files.concat(gem_lists.flatten) if gem_lists.flatten.any?
27
- else
28
- app_files(name, filter)
29
- grouped_files += @grouped[name]
30
- end
31
- end
32
- if !Coverband.configuration.groups.empty? && !(other_files = @files.reject do |source_file|
33
- grouped_files.include?(source_file)
34
- end).empty?
35
- @grouped['Ungrouped'] = Coverband::Utils::FileList.new(other_files)
36
- end
37
- end
38
-
39
- def gem_files(name, filter)
40
- grouped_gems = @files.select { |source_file| source_file.filename =~ /#{filter}/ }.group_by(&:gem_name)
41
- gem_lists = grouped_gems.values.map { |gem_files| Coverband::Utils::FileList.new(gem_files) }
42
- @grouped[name] = Coverband::Utils::GemList.new(gem_lists) if gem_lists.flatten.any?
43
- gem_lists
44
- end
45
-
46
- def app_files(name, filter)
47
- @grouped[name] = Coverband::Utils::FileList.new(@files.select do |source_file|
48
- source_file.filename =~ /#{filter}/ && source_file.filename !~ /#{Coverband.configuration.gem_paths.first}/
49
- end)
50
- end
51
- end
52
- end
53
- end
@@ -1,31 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- ####
4
- # An array of FileLists instances with helpers to roll up the stats
5
- # methods for calculating coverage across them etc.
6
- ####
7
- module Coverband
8
- module Utils
9
- class GemList < FileList
10
- # Returns the count of lines that have coverage
11
- def covered_lines
12
- to_a.map(&:covered_lines).inject(:+)
13
- end
14
-
15
- # Returns the count of lines that have been missed
16
- def missed_lines
17
- to_a.map(&:missed_lines).inject(:+)
18
- end
19
-
20
- # Returns the count of lines that are not relevant for coverage
21
- def never_lines
22
- to_a.map(&:never_lines).inject(:+)
23
- end
24
-
25
- # Returns the count of skipped lines
26
- def skipped_lines
27
- to_a.map(&:skipped_lines).inject(:+)
28
- end
29
- end
30
- end
31
- end
@@ -1,105 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Coverband
4
- module Utils
5
- ###
6
- # TODO: this is currently a html report writer
7
- # this should support writing coverage the current method should be fine
8
- # to write every report to S3 and sum them later or use the 2 pass
9
- # method we do for redis if in a background thread
10
- ###
11
- class S3Report
12
- def self.instance
13
- s3_options = {
14
- region: Coverband.configuration.s3_region,
15
- access_key_id: Coverband.configuration.s3_access_key_id,
16
- secret_access_key: Coverband.configuration.s3_secret_access_key
17
- }
18
- new(Coverband.configuration.s3_bucket, s3_options)
19
- end
20
-
21
- def initialize(bucket_name, options = {})
22
- @bucket_name = bucket_name
23
- @region = options[:region]
24
- @access_key_id = options[:access_key_id]
25
- @secret_access_key = options[:secret_access_key]
26
- begin
27
- require 'aws-sdk-s3'
28
- rescue StandardError
29
- err_msg = 'Coverband requires aws-sdk in order use S3Report.'
30
- Coverband.configuration.logger&.error err_msg
31
- end
32
- end
33
-
34
- def persist!
35
- if defined?(Aws)
36
- object.put(body: coverage_content)
37
- else
38
- object.write(coverage_content)
39
- end
40
- end
41
-
42
- def retrieve
43
- if defined?(Aws)
44
- s3_client.get_object(bucket: Coverband.configuration.s3_bucket,
45
- key: 'coverband/index.html').body.read
46
- else
47
- object.read
48
- end
49
- end
50
-
51
- private
52
-
53
- def coverage_content
54
- version = Coverband::VERSION
55
- File.read("#{Coverband.configuration.root}/coverage/index.html").gsub("./assets/#{version}/", '')
56
- end
57
-
58
- def object
59
- if defined?(Aws)
60
- bucket.object('coverband/index.html')
61
- else
62
- bucket.objects['coverband/index.html']
63
- end
64
- end
65
-
66
- def client_options
67
- {
68
- region: @region,
69
- access_key_id: @access_key_id,
70
- secret_access_key: @secret_access_key
71
- }
72
- end
73
-
74
- def s3_client
75
- if defined?(Aws)
76
- # AWS SDK v2
77
- Aws::S3::Client.new(client_options)
78
- else
79
- # AWS SDK v1
80
- AWS::S3::Client.new(client_options)
81
- end
82
- end
83
-
84
- def s3
85
- resource_options = { client: s3_client }
86
- resource_options = {} if client_options.values.any?(&:nil?)
87
- if defined?(Aws)
88
- # AWS SDK v2
89
- Aws::S3::Resource.new(resource_options)
90
- else
91
- # AWS SDK v1
92
- AWS::S3.new(resource_options)
93
- end
94
- end
95
-
96
- def bucket
97
- if defined?(Aws)
98
- s3.bucket(@bucket_name)
99
- else
100
- s3.buckets[@bucket_name]
101
- end
102
- end
103
- end
104
- end
105
- end