coverband 5.0.1 → 5.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
  3. data/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
  4. data/.github/workflows/main.yml +30 -0
  5. data/CONTRIBUTING.md +1 -0
  6. data/Gemfile +4 -5
  7. data/Gemfile.rails4 +2 -0
  8. data/Gemfile.rails6 +2 -0
  9. data/LICENSE.txt +1 -1
  10. data/README.md +43 -7
  11. data/changes.md +14 -9
  12. data/coverband.gemspec +6 -4
  13. data/lib/coverband/adapters/base.rb +5 -1
  14. data/lib/coverband/adapters/file_store.rb +1 -1
  15. data/lib/coverband/adapters/redis_store.rb +1 -1
  16. data/lib/coverband/at_exit.rb +3 -0
  17. data/lib/coverband/collectors/view_tracker.rb +16 -7
  18. data/lib/coverband/reporters/web.rb +2 -1
  19. data/lib/coverband/utils/dead_methods.rb +63 -0
  20. data/lib/coverband/utils/method_definition_scanner.rb +96 -0
  21. data/lib/coverband/utils/tasks.rb +17 -3
  22. data/lib/coverband/version.rb +1 -1
  23. data/test/coverband/collectors/view_tracker_test.rb +10 -0
  24. data/test/coverband/reporters/web_test.rb +34 -0
  25. data/test/coverband/utils/dead_methods_test.rb +53 -0
  26. data/test/coverband/utils/method_definition_scanner_test.rb +85 -0
  27. data/test/fixtures/casting_invitor.rb +60 -0
  28. data/test/forked/rails_full_stack_test.rb +1 -1
  29. data/test/forked/rails_full_stack_views_test.rb +51 -0
  30. data/test/forked/rails_view_tracker_stack_test.rb +44 -0
  31. data/test/rails4_dummy/app/controllers/dummy_view_controller.rb +16 -0
  32. data/test/rails4_dummy/app/views/dummy_view/show.html.erb +5 -0
  33. data/test/rails4_dummy/app/views/dummy_view/show_haml.html.haml +4 -0
  34. data/test/rails4_dummy/app/views/dummy_view/show_slim.html.slim +4 -0
  35. data/test/rails4_dummy/config/application.rb +1 -0
  36. data/test/rails4_dummy/config/routes.rb +3 -0
  37. data/test/rails5_dummy/app/controllers/dummy_view_controller.rb +16 -0
  38. data/test/rails5_dummy/app/views/dummy_view/show.html.erb +5 -0
  39. data/test/rails5_dummy/app/views/dummy_view/show_haml.html.haml +4 -0
  40. data/test/rails5_dummy/app/views/dummy_view/show_slim.html.slim +4 -0
  41. data/test/rails5_dummy/config/application.rb +2 -0
  42. data/test/rails5_dummy/config/coverband.rb +3 -1
  43. data/test/rails5_dummy/config/routes.rb +3 -0
  44. data/test/rails6_dummy/app/controllers/dummy_view_controller.rb +16 -0
  45. data/test/rails6_dummy/app/views/dummy_view/show.html.erb +5 -0
  46. data/test/rails6_dummy/app/views/dummy_view/show_haml.html.haml +4 -0
  47. data/test/rails6_dummy/app/views/dummy_view/show_slim.html.slim +4 -0
  48. data/test/rails6_dummy/config/application.rb +1 -0
  49. data/test/rails6_dummy/config/routes.rb +3 -0
  50. data/test/test_helper.rb +1 -0
  51. data/views/view_tracker.erb +2 -2
  52. metadata +42 -3
  53. data/.travis.yml +0 -48
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2869a30161428e6236dee380660fe39797c6fd6029225c4987d8de79cfce9019
4
- data.tar.gz: 43f2998da3c1735f452c71aaf93179d714933e4f7da11d420477155a8427ab85
3
+ metadata.gz: a5cd2e1c2877aa5eefb57baf7b1c51c5e708ef8d5869f01b51a37c3b6e37c931
4
+ data.tar.gz: 4f0a6bc520d84917f989b3c13ec1c5bba2d6ab04db26fb87331cfed536b142f9
5
5
  SHA512:
6
- metadata.gz: d083c07eb9c101e87f19902b9f7c531e4f06f7b7f8421912f77cd25d74340f1f6824d97059d410711b092a36e5a52dc01afa1ea30af714331fb3bdc905ac4ce7
7
- data.tar.gz: e1fd6726954fdb473fc21570207923942953faa3360ca4dfea9a6fb825fbb42fef77e3b593469f5a28e42f9a1e7115f96815822405ad26d34c113f364aa8ee69
6
+ metadata.gz: cb077ceeb315e92dd7f51e355057d855b00701e05d8b4ef7836ff8cae624c2db71ba0ce67ac6e3be5dd5fb87182c4a68d8e8d1ab3c6e4554f2d792db9f214c65
7
+ data.tar.gz: 0ab9e096d137f1babd34b3cc32899095b6b3f0f87bb0a9aee7d987bf8b116b1815a3fc630ad0f1f73d4550563c2cf08a4bb9e8e20e8c9553dd9246d0dee6414a
@@ -0,0 +1,38 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Describe the bug**
11
+ A clear and concise description of what the bug is.
12
+
13
+ **To Reproduce**
14
+ Steps to reproduce the behavior:
15
+ 1. Go to '...'
16
+ 2. Click on '....'
17
+ 3. Scroll down to '....'
18
+ 4. See error
19
+
20
+ **Expected behavior**
21
+ A clear and concise description of what you expected to happen.
22
+
23
+ **Screenshots**
24
+ If applicable, add screenshots to help explain your problem.
25
+
26
+ **Desktop (please complete the following information):**
27
+ - OS: [e.g. iOS]
28
+ - Browser [e.g. chrome, safari]
29
+ - Version [e.g. 22]
30
+
31
+ **Smartphone (please complete the following information):**
32
+ - Device: [e.g. iPhone6]
33
+ - OS: [e.g. iOS8.1]
34
+ - Browser [e.g. stock browser, safari]
35
+ - Version [e.g. 22]
36
+
37
+ **Additional context**
38
+ Add any other context about the problem here.
@@ -0,0 +1,20 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+ title: ''
5
+ labels: ''
6
+ assignees: ''
7
+
8
+ ---
9
+
10
+ **Is your feature request related to a problem? Please describe.**
11
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12
+
13
+ **Describe the solution you'd like**
14
+ A clear and concise description of what you want to happen.
15
+
16
+ **Describe alternatives you've considered**
17
+ A clear and concise description of any alternative solutions or features you've considered.
18
+
19
+ **Additional context**
20
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,30 @@
1
+ name: CI
2
+ # Controls when the action will run.
3
+ on:
4
+ # Triggers the workflow on push or pull request events but only for the master branch
5
+ push:
6
+ branches: [master]
7
+ pull_request:
8
+ branches: [master]
9
+ jobs:
10
+ test:
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ # need to figure out how to use redis on macos github actions
15
+ # os: [ubuntu, macos]
16
+ os: [ubuntu]
17
+ # remove until I sort out CI issues for truffle
18
+ # truffleruby,
19
+ # truffleruby-head,
20
+ ruby: [2.3, 2.4, 2.5, 2.6, 2.7, jruby, jruby-head]
21
+ redis-version: [5]
22
+ runs-on: ${{ matrix.os }}-latest
23
+ steps:
24
+ - uses: actions/checkout@v2
25
+ - uses: supercharge/redis-github-action@1.1.0
26
+ - uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: ${{ matrix.ruby }}
29
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
30
+ - run: bundle exec rake
@@ -0,0 +1 @@
1
+ See our [code of conduct](https://github.com/danmayer/coverband/blob/master/CODE_OF_CONDUCT.md)
data/Gemfile CHANGED
@@ -7,13 +7,12 @@ gemspec
7
7
 
8
8
  # add when debugging
9
9
  # require 'byebug'; byebug
10
- if ENV["CI"]
11
- # skipping pry-byebug as it has issues on Ruby 2.3 on travis
12
- # and we don't really need it on CI
13
- else
14
- gem "pry-byebug", platforms: [:mri, :mingw, :x64_mingw]
10
+ unless ENV["CI"]
11
+ gem "pry-byebug"
15
12
  end
16
13
 
17
14
  gem "rails", "~>5"
15
+ gem "haml"
16
+ gem "slim"
18
17
  # these gems are used for testing gem tracking
19
18
  gem "irb", require: false
@@ -5,3 +5,5 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in coverband.gemspec
6
6
  gemspec
7
7
  gem 'rails', '~>4'
8
+ gem "haml"
9
+ gem "slim"
@@ -5,3 +5,5 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in coverband.gemspec
6
6
  gemspec
7
7
  gem 'rails', '~>6'
8
+ gem "haml"
9
+ gem "slim"
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2018 Dan Mayer
1
+ Copyright (c) 2010-2020 Dan Mayer
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Coverband
4
4
 
5
- [![Build Status](https://travis-ci.org/danmayer/coverband.svg?branch=master)](https://travis-ci.org/danmayer/coverband)
5
+ [![GithubCI](https://github.com/danmayer/coverband/workflows/CI/badge.svg)](https://github.com/danmayer/coverband/actions)
6
6
  [![Coverage Status](https://coveralls.io/repos/github/danmayer/coverband/badge.svg?branch=master)](https://coveralls.io/github/danmayer/coverband?branch=master)
7
7
  [![Maintainability](https://api.codeclimate.com/v1/badges/1e6682f9540d75f26da7/maintainability)](https://codeclimate.com/github/danmayer/coverband/maintainability)
8
8
  [![Discord Shield](https://img.shields.io/discord/609509533999562753)](https://discord.gg/KAH38EV)
@@ -12,6 +12,7 @@
12
12
  <a href="#installation">Installation</a> •
13
13
  <a href="#coverband-web-ui">Coverband Web UI</a> •
14
14
  <a href="#advanced-config">Advanced Config</a> •
15
+ <a href="#newer-features">Newer Features</a> •
15
16
  <a href="#license">License</a> •
16
17
  <a href="/changes.md">Change Log / Roadmap</a> •
17
18
  <a href="/CODE_OF_CONDUCT.md">Code of Conduct</a>
@@ -33,6 +34,7 @@ The primary goal of Coverband is giving deep insight into your production runtim
33
34
  - Development mode, offers deep insight of code usage details (number of LOC execution during single request, etc) during development.
34
35
  - Mountable web interface to easily share reports
35
36
 
37
+
36
38
  # Installation
37
39
 
38
40
  ## Redis
@@ -65,7 +67,7 @@ The Railtie integration means you shouldn't need to do anything else other than
65
67
 
66
68
  ## Sinatra
67
69
 
68
- For the best coverage you want this loaded as early as possible. We recommend requiring cover band directly in the `config.ru`. Requiring coverband within an initializer could also work, but you may end up missing some boot up coverage. To start collection require Coverband as early as possible.
70
+ For the best coverage you want this loaded as early as possible. We recommend requiring cover band directly in the `config.ru`. Requiring coverband within an initializer could also work, but you may end up missing some boot up coverage. To start collection require Coverband as early as possible.
69
71
 
70
72
  ```ruby
71
73
  require 'coverband'
@@ -91,7 +93,7 @@ run ActionController::Dispatcher.new
91
93
 
92
94
  - Clear coverage report
93
95
 
94
- This will clear the coverage data. This wipes out all collected data.
96
+ This will clear the coverage data. This wipes out all collected data.
95
97
 
96
98
  - Clear individual file coverage
97
99
 
@@ -128,10 +130,16 @@ or you can enable basic auth by setting `ENV['COVERBAND_PASSWORD']` or via your
128
130
  The coverage server can also be started standalone with a rake task:
129
131
 
130
132
  ```
131
- bundle exec rake coverband:coverage_server
133
+ bundle exec rake coverband:coverage_server
132
134
  ```
133
135
 
134
- The web UI should then be available here: http://localhost:1022/
136
+ The web UI should then be available here: http://localhost:9022/
137
+
138
+ If you want to run on an alternative port:
139
+
140
+ ```
141
+ COVERBAND_COVERAGE_PORT=8086 bundle exec rake coverband:coverage_server
142
+ ```
135
143
 
136
144
  This is especially useful for projects that are api only and cannot support the mounted rack app. To get production coverage, point coverband at your production redis server and ensure to checkout the production version of your project code locally.
137
145
 
@@ -298,6 +306,8 @@ rake coverband:coverage # report runtime coverband code coverage
298
306
 
299
307
  Coverband starts on require of the the library which is usually done within the Gemfile. This can be disabled by setting the `COVERBAND_DISABLE_AUTO_START` environment variable. This environment variable can be useful to toggle coverband on and off in certain environments.
300
308
 
309
+ **NOTE:** That any value set for `COVERBAND_DISABLE_AUTO_START` is considered true, it does not match the string content but only checks the presence of the ENV variable.
310
+
301
311
  In order to start coverband manually yourself when this flag is enabled, call `Coverband.configure` followed by `Coverband.start`.
302
312
 
303
313
  ```ruby
@@ -327,7 +337,31 @@ If you currently have require: false, remove the 'coverband' string from the req
327
337
  gem 'coverband', require: ['alternative_coverband_patch']
328
338
  ```
329
339
 
330
- This conflict happens when a ruby method is patched twice, once using module prepend, and once using method aliasing. See this ruby issue for details. The fix is to apply all patches the same way. Coverband by default will apply its patch using prepend, but you can change that to method aliasing by adding require: ['alternative_coverband_patch'] to the gem line as shown above.
340
+ This conflict happens when a ruby method is patched twice, once using module prepend, and once using method aliasing. See this ruby issue for details. The fix is to apply all patches the same way. Coverband by default will apply its patch using prepend, but you can change that to method aliasing by adding require: ['alternative_coverband_patch'] to the gem line as shown above.
341
+
342
+ # Newer Features
343
+
344
+ ### Dead Method Scanning (ruby 2.6+)
345
+
346
+ Rake task that outputs dead methods based on current coverage data:
347
+
348
+ ```
349
+ bundle exec rake coverband:dead_methods
350
+ ```
351
+
352
+ Outputs:
353
+
354
+ ```
355
+ ---------------------------------------------------------------------------------------------------
356
+ | file | class | method | line_number |
357
+ | ./config/routes.rb | AdminConstraint | matches? | 20 |
358
+ | ./app/controllers/home_controller.rb | HomeController | trigger_jobs | 8 |
359
+ | ./app/controllers/home_controller.rb | HomeController | data_tracer | 14 |
360
+ | ./app/controllers/posts_controller.rb | PostsController | edit | 22 |
361
+ | ./app/controllers/posts_controller.rb | PostsController | destroy_bad_dangerously | 73 |
362
+ ---------------------------------------------------------------------------------------------------
363
+ ```
364
+
331
365
 
332
366
  # Prerequisites
333
367
 
@@ -379,7 +413,9 @@ If you submit a change please make sure the tests and benchmarks are passing.
379
413
  - **total fail** on front end code, for line for line coverage, because of the precompiled template step basically coverage doesn't work well for `erb`, `slim`, and the like.
380
414
  - related it will try to report something, but the line numbers reported for `ERB` files are often off and aren't considered useful. I recommend filtering out .erb using the `config.ignore` option. The default configuration excludes these files
381
415
  - **NOTE:** We now have file level coverage for view files, but don't support line level detail
382
- - The view file detection doesn't workf or mailers at the moment only for web related views / JSON templates. This is due to how Rails active mailer notifications work.
416
+ - **Coverage does NOT work when used alongside Scout APM Auto Instrumentation**
417
+ - In an environment that uses Scout's `AUTO_INSTRUMENT=true` (usually production or staging) it stops reporting any coverage, it will show one or two files that have been loaded at the start but everything else will show up as having 0% coverage
418
+ - Bug tracked here: https://github.com/scoutapp/scout_apm_ruby/issues/343
383
419
 
384
420
  ### Debugging Redis Store
385
421
 
data/changes.md CHANGED
@@ -53,12 +53,23 @@ Will be the fully modern release that drops maintenance legacy support in favor
53
53
 
54
54
  # Alpha / Beta / Release Candidates
55
55
 
56
- ### Coverband 5.0.2
56
+ ### Coverband 5.0.4
57
57
 
58
- - ?
58
+ - add support for tracking email view templates/partials
59
59
 
60
60
  # Released
61
61
 
62
+ ### Coverband 5.0.3
63
+
64
+ - fix for non standard root paths for view_tracker thx @markshawtoronto
65
+ - support basic auth for Rack prior to 2.0 thx @kadru
66
+
67
+ ### Coverband 5.0.2
68
+
69
+ - change default port of local server
70
+ - update on readme about issue with scout app, thanks @mrbongiolo
71
+ - fix on configuration page not loading when redis can't load
72
+
62
73
  ### Coverband 5.0.1
63
74
 
64
75
  - fix for race condition on view tracker redis configuration setting ensuring it is set after it is configured... bug only impacted apps that have multiple redis connections for the same system and have Coverband not on the default REDIS_URL
@@ -71,13 +82,7 @@ Will be the fully modern release that drops maintenance legacy support in favor
71
82
  - drops static report support
72
83
  - drops gem support
73
84
  - only loaded web reporter files when required
74
- - configuration improvements
75
- - improved load order allowing more time for ENV vars (better dotenv, figaro, rails secrets support)
76
- - all config options can be set via coverband config, not requiring ENV var support
77
- - deprecation notices on soon to be removed config options
78
- - config exceptions on invalid configuration combinations
79
- - additional testing around configurations
80
- - improved defaults and reduced configuration options
85
+ - configuration improvements - improved load order allowing more time for ENV vars (better dotenv, figaro, rails secrets support) - all config options can be set via coverband config, not requiring ENV var support - deprecation notices on soon to be removed config options - config exceptions on invalid configuration combinations - additional testing around configurations - improved defaults and reduced configuration options
81
86
  - improved resque patching pattern
82
87
  - improved default ignores
83
88
  - additional adapters
@@ -8,16 +8,18 @@ Gem::Specification.new do |spec|
8
8
  spec.name = "coverband"
9
9
  spec.version = Coverband::VERSION
10
10
  spec.authors = ["Dan Mayer", "Karl Baum"]
11
- spec.email = ["dan@mayerdan.com"]
12
- spec.description = "Rack middleware to measure production code usage (LOC runtime usage)"
13
- spec.summary = "Rack middleware to measure production code usage (LOC runtime usage)"
11
+ spec.email = %w[dan@mayerdan.com]
12
+ spec.description =
13
+ "Rack middleware to measure production code usage (LOC runtime usage)"
14
+ spec.summary =
15
+ "Rack middleware to measure production code usage (LOC runtime usage)"
14
16
  spec.homepage = "https://github.com/danmayer/coverband"
15
17
  spec.license = "MIT"
16
18
 
17
19
  spec.files = `git ls-files`.split("\n").reject { |f| f.start_with?("docs") }
18
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
- spec.require_paths = ["lib"]
22
+ spec.require_paths = %w[lib]
21
23
 
22
24
  spec.add_development_dependency "benchmark-ips"
23
25
  spec.add_development_dependency "capybara"
@@ -40,7 +40,11 @@ module Coverband
40
40
  end
41
41
 
42
42
  def size_in_mib
43
- format("%<size>.2f", size: (size.to_f / 2**20))
43
+ if size
44
+ format("%<size>.2f", size: (size.to_f / 2**20))
45
+ else
46
+ "N/A"
47
+ end
44
48
  end
45
49
 
46
50
  def save_report(_report)
@@ -20,7 +20,7 @@ module Coverband
20
20
  # files matching the path pattern, in this case `log/coverage.log.*`
21
21
  #
22
22
  # run: `bundle exec rake coverband:coverage_server`
23
- # open http://localhost:1022/
23
+ # open http://localhost:9022/
24
24
  #
25
25
  # one could also build a report via code, the output is suitable to feed into SimpleCov
26
26
  #
@@ -44,7 +44,7 @@ module Coverband
44
44
  end
45
45
 
46
46
  def size
47
- @redis.get(base_key).bytesize
47
+ @redis.get(base_key) ? @redis.get(base_key).bytesize : "N/A"
48
48
  end
49
49
 
50
50
  ###
@@ -20,6 +20,9 @@ module Coverband
20
20
  # skip reporting
21
21
  else
22
22
  Coverband.report_coverage
23
+ # to ensure we track mailer views we now need to report views tracking
24
+ # at exit as well for rake tasks and background tasks that can trigger email
25
+ Coverband.configuration.view_tracker&.report_views_tracked
23
26
  end
24
27
  end
25
28
  end
@@ -10,22 +10,20 @@ module Coverband
10
10
  # This is a port of Flatfoot, a project I open sourced years ago,
11
11
  # but am now rolling into Coverband
12
12
  # https://github.com/livingsocial/flatfoot
13
- #
14
- # TODO: test and ensure slim, haml, and other support
15
13
  ###
16
14
  class ViewTracker
17
- DEFAULT_TARGET = Dir.glob("app/views/**/*.html.erb").reject { |file| file.match(/(_mailer)/) }
18
15
  attr_accessor :target, :logged_views, :views_to_record
19
16
  attr_reader :logger, :roots, :store, :ignore_patterns
20
17
 
21
18
  def initialize(options = {})
22
19
  raise NotImplementedError, "View Tracker requires Rails 4 or greater" unless self.class.supported_version?
20
+ raise "Coverband: view tracker initialized before configuration!" if !Coverband.configured? && ENV["COVERBAND_TEST"] == "test"
23
21
 
24
22
  @project_directory = File.expand_path(Coverband.configuration.root)
25
23
  @ignore_patterns = Coverband.configuration.ignore
26
24
  @store = options.fetch(:store) { Coverband.configuration.store }
27
25
  @logger = options.fetch(:logger) { Coverband.configuration.logger }
28
- @target = options.fetch(:target) { DEFAULT_TARGET }
26
+ @target = options.fetch(:target) { Dir.glob("#{@project_directory}/app/views/**/*.html.{erb,haml,slim}") }
29
27
 
30
28
  @roots = options.fetch(:roots) { Coverband.configuration.all_root_patterns }
31
29
  @roots = @roots.split(",") if @roots.is_a?(String)
@@ -65,18 +63,29 @@ module Coverband
65
63
  normalized_views = {}
66
64
  views.each_pair do |view, time|
67
65
  roots.each do |root|
68
- view = view.gsub(/#{root}/, "")
66
+ view = view.gsub(root, "")
69
67
  end
70
68
  normalized_views[view] = time
71
69
  end
72
70
  normalized_views
73
71
  end
74
72
 
73
+ def all_views
74
+ all_views = []
75
+ target.each do |view|
76
+ roots.each do |root|
77
+ view = view.gsub(root, "")
78
+ end
79
+ all_views << view
80
+ end
81
+ all_views.uniq
82
+ end
83
+
75
84
  def unused_views
76
85
  recently_used_views = used_views.keys
77
- all_views = target.reject { |view| recently_used_views.include?(view) }
86
+ unused_views = all_views.reject { |view| recently_used_views.include?(view) }
78
87
  # since layouts don't include format we count them used if they match with ANY formats
79
- all_views.reject { |view| view.match(/\/layouts\//) && recently_used_views.any? { |used_view| view.include?(used_view) } }
88
+ unused_views.reject { |view| view.match(/\/layouts\//) && recently_used_views.any? { |used_view| view.include?(used_view) } }
80
89
  end
81
90
 
82
91
  def as_json
@@ -23,7 +23,8 @@ module Coverband
23
23
  def check_auth
24
24
  return true unless Coverband.configuration.password
25
25
 
26
- auth_header = request.get_header("HTTP_AUTHORIZATION")
26
+ # support rack 1.6.x and rack 2.0 (get_header)
27
+ auth_header = request.respond_to?(:get_header) ? request.get_header("HTTP_AUTHORIZATION") : request.env["HTTP_AUTHORIZATION"]
27
28
  return unless auth_header
28
29
 
29
30
  Coverband.configuration.password == Base64.decode64(auth_header.split[1]).split(":")[1]
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: ntrue
2
+
3
+ require "coverband/utils/method_definition_scanner"
4
+
5
+ module Coverband
6
+ module Utils
7
+ module ArrayToTableInConsole
8
+ refine Array do
9
+ def to_table
10
+ column_sizes =
11
+ reduce([]) { |lengths, row|
12
+ row.each_with_index.map do |iterand, index|
13
+ [lengths[index] || 0, iterand.to_s.length].max
14
+ end
15
+ }
16
+ puts head =
17
+ "-" * (column_sizes.inject(&:+) + (3 * column_sizes.count) + 1)
18
+ each do |row|
19
+ row = row.fill(nil, row.size..(column_sizes.size - 1))
20
+ row =
21
+ row.each_with_index.map { |v, i|
22
+ v.to_s + " " * (column_sizes[i] - v.to_s.length)
23
+ }
24
+ puts "| " + row.join(" | ") + " |"
25
+ end
26
+ puts head
27
+ end
28
+ end
29
+ end
30
+
31
+ class DeadMethods
32
+ using ArrayToTableInConsole
33
+ def self.scan(file_path:, coverage:)
34
+ MethodDefinitionScanner.scan(file_path).reject do |method_definition|
35
+ method_definition.body.coverage?(coverage)
36
+ end
37
+ end
38
+
39
+ def self.scan_all
40
+ coverage = Coverband.configuration.store.coverage
41
+ coverage.flat_map do |file_path, coverage|
42
+ scan(file_path: file_path, coverage: coverage["data"])
43
+ end
44
+ end
45
+
46
+ def self.output_all
47
+ rows =
48
+ scan_all.each_with_object(
49
+ [%w[file class method line_number]]
50
+ ) { |dead_method, rows|
51
+ rows <<
52
+ [
53
+ dead_method.file_path,
54
+ dead_method.class_name,
55
+ dead_method.name,
56
+ dead_method.first_line_number
57
+ ]
58
+ }
59
+ rows.to_table
60
+ end
61
+ end
62
+ end
63
+ end