coverband 4.2.0 → 4.2.4

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.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +29 -10
  3. data/.travis.yml +16 -8
  4. data/CODE_OF_CONDUCT.md +76 -0
  5. data/Gemfile +3 -1
  6. data/Gemfile.rails4 +1 -0
  7. data/README.md +108 -59
  8. data/Rakefile +19 -3
  9. data/changes.md +85 -10
  10. data/coverband.gemspec +3 -5
  11. data/lib/coverband/adapters/base.rb +64 -45
  12. data/lib/coverband/adapters/file_store.rb +15 -9
  13. data/lib/coverband/adapters/hash_redis_store.rb +190 -0
  14. data/lib/coverband/adapters/redis_store.rb +35 -11
  15. data/lib/coverband/at_exit.rb +2 -11
  16. data/lib/coverband/collectors/coverage.rb +35 -41
  17. data/lib/coverband/collectors/delta.rb +34 -28
  18. data/lib/coverband/collectors/view_tracker.rb +157 -0
  19. data/lib/coverband/configuration.rb +115 -33
  20. data/lib/coverband/integrations/background.rb +12 -4
  21. data/lib/coverband/integrations/{middleware.rb → background_middleware.rb} +2 -6
  22. data/lib/coverband/integrations/bundler.rb +8 -0
  23. data/lib/coverband/integrations/report_middleware.rb +15 -0
  24. data/lib/coverband/integrations/resque.rb +3 -5
  25. data/lib/coverband/reporters/base.rb +40 -16
  26. data/lib/coverband/reporters/console_report.rb +1 -0
  27. data/lib/coverband/reporters/html_report.rb +31 -27
  28. data/lib/coverband/reporters/web.rb +63 -18
  29. data/lib/coverband/utils/absolute_file_converter.rb +47 -0
  30. data/lib/coverband/utils/file_hasher.rb +16 -0
  31. data/lib/coverband/utils/file_list.rb +16 -5
  32. data/lib/coverband/utils/html_formatter.rb +45 -8
  33. data/lib/coverband/utils/lines_classifier.rb +5 -0
  34. data/lib/coverband/utils/railtie.rb +28 -10
  35. data/lib/coverband/utils/relative_file_converter.rb +41 -0
  36. data/lib/coverband/utils/result.rb +6 -39
  37. data/lib/coverband/utils/results.rb +51 -0
  38. data/lib/coverband/utils/s3_report.rb +2 -3
  39. data/lib/coverband/utils/source_file.rb +34 -8
  40. data/lib/coverband/utils/tasks.rb +10 -10
  41. data/lib/coverband/version.rb +5 -1
  42. data/lib/coverband.rb +49 -27
  43. data/lua/install.sh +15 -0
  44. data/lua/lib/persist-coverage.lua +28 -0
  45. data/lua/test/bootstrap.lua +5 -0
  46. data/lua/test/harness.lua +19 -0
  47. data/lua/test/redis-call.lua +55 -0
  48. data/lua/test/test-persist-coverage.lua +132 -0
  49. data/public/application.css +14 -6
  50. data/public/application.js +27 -0
  51. data/test/benchmarks/benchmark.rake +167 -73
  52. data/test/benchmarks/init_rails.rake +10 -0
  53. data/test/coverband/adapters/base_test.rb +73 -42
  54. data/test/coverband/adapters/file_store_test.rb +48 -37
  55. data/test/coverband/adapters/hash_redis_store_test.rb +195 -0
  56. data/test/coverband/adapters/redis_store_test.rb +102 -59
  57. data/test/coverband/at_exit_test.rb +0 -2
  58. data/test/coverband/collectors/coverage_test.rb +71 -13
  59. data/test/coverband/collectors/delta_test.rb +36 -6
  60. data/test/coverband/collectors/view_tracker_test.rb +113 -0
  61. data/test/coverband/configuration_test.rb +47 -7
  62. data/test/coverband/coverband_test.rb +14 -2
  63. data/test/coverband/integrations/background_middleware_test.rb +44 -0
  64. data/test/coverband/integrations/background_test.rb +11 -3
  65. data/test/coverband/integrations/report_middleware_test.rb +44 -0
  66. data/test/coverband/integrations/resque_worker_test.rb +5 -6
  67. data/test/coverband/integrations/test_resque_job.rb +3 -1
  68. data/test/coverband/reporters/base_test.rb +5 -81
  69. data/test/coverband/reporters/console_test.rb +3 -10
  70. data/test/coverband/reporters/html_test.rb +71 -21
  71. data/test/coverband/reporters/web_test.rb +0 -10
  72. data/test/coverband/utils/absolute_file_converter_test.rb +56 -0
  73. data/test/coverband/utils/file_groups_test.rb +11 -5
  74. data/test/coverband/utils/file_hasher_test.rb +29 -0
  75. data/test/coverband/utils/file_list_test.rb +5 -5
  76. data/test/coverband/utils/html_formatter_test.rb +41 -0
  77. data/test/coverband/utils/relative_file_converter_test.rb +39 -0
  78. data/test/coverband/utils/result_test.rb +6 -47
  79. data/test/coverband/utils/results_test.rb +54 -0
  80. data/test/coverband/utils/s3_report_test.rb +2 -0
  81. data/test/coverband/utils/source_file_test.rb +54 -0
  82. data/test/dog.rb.erb +12 -0
  83. data/test/forked/rails_full_stack_test.rb +106 -0
  84. data/test/forked/rails_rake_full_stack_test.rb +58 -0
  85. data/test/integration/full_stack_test.rb +15 -16
  86. data/test/rails4_dummy/Rakefile +6 -0
  87. data/test/rails4_dummy/config/application.rb +8 -9
  88. data/test/rails4_dummy/config/coverband.rb +3 -11
  89. data/test/rails4_dummy/config/coverband_missing_redis.rb +3 -0
  90. data/test/rails5_dummy/Rakefile +6 -0
  91. data/test/rails5_dummy/config/application.rb +6 -10
  92. data/test/rails5_dummy/config/coverband.rb +7 -3
  93. data/test/rails5_dummy/config/coverband_missing_redis.rb +15 -0
  94. data/test/rails_test_helper.rb +22 -5
  95. data/test/test_helper.rb +52 -11
  96. data/test/unique_files.rb +17 -9
  97. data/views/data.erb +1 -0
  98. data/views/file_list.erb +13 -12
  99. data/views/gem_list.erb +10 -1
  100. data/views/layout.erb +6 -18
  101. data/views/nav.erb +36 -0
  102. data/views/source_file.erb +20 -4
  103. data/views/source_file_loader.erb +1 -1
  104. data/views/view_tracker.erb +52 -0
  105. metadata +71 -12
  106. data/lib/coverband/utils/file_path_helper.rb +0 -57
  107. data/test/coverband/integrations/middleware_test.rb +0 -96
  108. data/test/integration/rails_full_stack_test.rb +0 -95
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e214b1bd6119046657daa64ed6d69f77f821c6c670b72e98d307ede5f08e61f
4
- data.tar.gz: 469d9470799f90b5b52d53d3a630fae75b3b6bff0390375987902331878f530e
3
+ metadata.gz: 1c094b4a6ef2b76f771cb96aa1fbdc246dc8beea74033ffca4cb466ef96c0a08
4
+ data.tar.gz: 1162d9244c0e1a1b28c0fa051d7cd53d29b6a4fdfc50c1fadb7d6793229aaf8b
5
5
  SHA512:
6
- metadata.gz: f1b0f503941ab9dbc2dee6a184fe6d6d937a5f505a5c9112ae7343197372586d6cb42df758f24effde0ee30fb359c0e2e651c64a1f5ee4c9a588a4499683dc73
7
- data.tar.gz: ee700abfe4c730011dcc5c1c8521f55a2cc7ec5149e44b08187c8d09419023160a0f7c8aaba4b2aa0bb405eb13f4aeee1d8ce9cabce4860738d4ea94cac63c04
6
+ metadata.gz: d9eba70b91d87992d1e450490f7fd4545cccb5092bf093c424c51b964cb4b31ad5c8a1d49d1cc774ce6470c6466b7d3b7a7a1df92ecbc4e574a203467f621b55
7
+ data.tar.gz: 815c462d38f7a27b26f5d209044c53b2e0058c4ea2534db3f6663a267ad0cc435bd6c895128c5ea8f85c0aec61e4e31d9f61c426526b71423e24c941852f74be
data/.rubocop.yml CHANGED
@@ -1,15 +1,23 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.4
3
3
  Exclude:
4
+ - vendor/bundle/**/*
4
5
  - docs/**/*
6
+ - test/rails4_dummy/**/*
7
+ - test/rails5_dummy/**/*
8
+ - test/fixtures/**/*
9
+ # Get the code passing first then we will enable for tests
10
+ - test/**/*
5
11
  Documentation:
6
12
  Enabled: false
7
13
  Metrics/MethodLength:
8
14
  Enabled: false
9
- Metrics/LineLength:
10
- Max: 120
15
+ Layout/LineLength:
16
+ Max: 160
11
17
  Metrics/BlockNesting:
12
18
  Max: 5
19
+ Metrics/BlockLength:
20
+ Max: 30
13
21
  Metrics/CyclomaticComplexity:
14
22
  Enabled: false
15
23
  Metrics/PerceivedComplexity:
@@ -22,38 +30,49 @@ Metrics/ModuleLength:
22
30
  Enabled: false
23
31
  Metrics/ParameterLists:
24
32
  Max: 10
25
- Style/AccessorMethodName:
33
+ Naming/AccessorMethodName:
26
34
  Enabled: false
27
- Style/PredicateName:
35
+ Naming/RescuedExceptionsVariableName:
28
36
  Enabled: false
37
+ Naming/PredicateName:
38
+ Enabled: true
29
39
  Style/TernaryParentheses:
30
40
  Enabled: false
31
41
  Style/MutableConstant:
32
42
  Enabled: false
43
+ Style/IdenticalConditionalBranches:
44
+ Enabled: false
45
+ Style/ClassVars:
46
+ Enabled: false
47
+ Style/MultilineBlockChain:
48
+ Enabled: false
33
49
  Style/FrozenStringLiteralComment:
34
50
  Enabled: true
35
51
  Style/GuardClause:
36
52
  Enabled: true
37
53
  Style/NumericPredicate:
38
- Enabled: false
54
+ Enabled: true
39
55
  Style/NumericLiterals:
40
56
  Enabled: false
41
57
  Style/NumericLiteralPrefix:
42
58
  Enabled: false
43
59
  Style/ClassAndModuleChildren:
44
60
  Enabled: false
45
- Performance/Casecmp:
61
+ Style/SymbolProc:
46
62
  Enabled: false
47
- Style/MultilineMethodCallIndentation:
63
+ Style/RegexpLiteral:
64
+ Enabled: false
65
+ Layout/MultilineMethodCallIndentation:
48
66
  Enabled: true
49
- Style/MultilineOperationIndentation:
67
+ Layout/MultilineOperationIndentation:
50
68
  Enabled: true
51
69
  Lint/RescueException:
52
70
  Enabled: true
71
+ Lint/UselessAccessModifier:
72
+ Enabled: true
53
73
  Lint/ShadowingOuterLocalVariable:
54
74
  Enabled: true
55
75
  Style/FormatString:
56
76
  Enabled: true
57
- Lint/Eval:
77
+ Security/Eval:
58
78
  Enabled: true
59
-
data/.travis.yml CHANGED
@@ -4,16 +4,24 @@ rvm:
4
4
  - "2.4"
5
5
  - "2.5"
6
6
  - "2.6.1"
7
+ cache:
8
+ bundler: true
9
+ directories:
10
+ - $HOME/lua51
7
11
  gemfile:
8
12
  - Gemfile
9
13
  - Gemfile.rails4
10
14
  services:
11
15
  - redis-server
12
- before_install:
13
- - echo 'this is a hack to clear default bundler and force bundler 1.17.3'
14
- - ls /home/travis/.rvm/gems/
15
- - rm /home/travis/.rvm/gems/ruby-2.3.7@global/specifications/bundler-2.0.1.gemspec || true
16
- - rm /home/travis/.rvm/gems/ruby-2.5.4@global/specifications/bundler-2.0.1.gemspec || true
17
- - gem uninstall bundler || true
18
- - gem install bundler -v '1.17.3'
19
- - bundler --version
16
+ script:
17
+ - sudo ./lua/install.sh
18
+ - $HOME/lua51/bin/busted lua/test/*
19
+ - bundle exec rake rubocop
20
+ - COVERBAND_HASH_REDIS_STORE=t bundle exec rake
21
+ - COVERBAND_HASH_REDIS_STORE=t bundle exec rake forked_tests
22
+ - bundle exec rake
23
+ - bundle exec rake forked_tests
24
+ # remove this for now as it is flaky
25
+ # passes locally on 2.3.5 on travis passes sometimes on 2.4 and always on 2.6.1
26
+ #- bundle exec rake benchmarks:memory
27
+ - bundle exec rake benchmarks
@@ -0,0 +1,76 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, sex characteristics, gender identity and expression,
9
+ level of experience, education, socio-economic status, nationality, personal
10
+ appearance, race, religion, or sexual identity and orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at danmayer@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
72
+
73
+ [homepage]: https://www.contributor-covenant.org
74
+
75
+ For answers to common questions about this code of conduct, see
76
+ https://www.contributor-covenant.org/faq
data/Gemfile CHANGED
@@ -5,5 +5,7 @@ source 'https://rubygems.org'
5
5
  # Specify your gem's dependencies in coverband.gemspec
6
6
  gemspec
7
7
  gem 'rails', '~>5'
8
- # this is used for testing gem tracking
8
+ # these gems are used for testing gem tracking
9
+ gem 'irb', require: false
10
+ gem 'pundit'
9
11
  gem 'rainbow', require: false
data/Gemfile.rails4 CHANGED
@@ -7,3 +7,4 @@ gemspec
7
7
  gem 'rails', '~>4'
8
8
  # this is used for testing gem tracking
9
9
  gem 'rainbow', require: false
10
+ gem 'pundit'
data/README.md CHANGED
@@ -4,15 +4,18 @@
4
4
 
5
5
  [![Build Status](https://travis-ci.org/danmayer/coverband.svg?branch=master)](https://travis-ci.org/danmayer/coverband)
6
6
  [![Coverage Status](https://coveralls.io/repos/github/danmayer/coverband/badge.svg?branch=master)](https://coveralls.io/github/danmayer/coverband?branch=master)
7
+ [![Maintainability](https://api.codeclimate.com/v1/badges/1e6682f9540d75f26da7/maintainability)](https://codeclimate.com/github/danmayer/coverband/maintainability)
8
+ [![Discord Shield](https://img.shields.io/discord/609509533999562753)](https://discord.gg/KAH38EV)
9
+
7
10
 
8
11
  <p align="center">
9
12
  <a href="#key-features">Key Features</a> •
10
13
  <a href="#installation">Installation</a> •
11
14
  <a href="#coverage-report">Coverage Report</a> •
12
- <a href="#verify-correct-installation">Verify Correct Installation</a> •
13
15
  <a href="#advanced-config">Advanced Config</a> •
14
16
  <a href="#license">License</a> •
15
- <a href="/changes.md">Change Log / Roadmap</a>
17
+ <a href="/changes.md">Change Log / Roadmap</a>
18
+ <a href="/CODE_OF_CONDUCT.md">Code of Conduct</a>
16
19
  </p>
17
20
 
18
21
  A gem to measure production code usage, showing a counter for the number of times each line of code that is executed. Coverband allows easy configuration to collect and report on production code usage. It reports in the background via a thread or can be used as Rack middleware, or manually configured to meet any need.
@@ -24,9 +27,11 @@ A gem to measure production code usage, showing a counter for the number of time
24
27
  The primary goal of Coverband is giving deep insight into your production runtime usage of your application code, while having the least impact on performance possible.
25
28
 
26
29
  - Low performance overhead
27
- - Very simple setup and configuration
30
+ - Simple setup and configuration
28
31
  - Out of the box support for all standard code execution paths (web, cron, background jobs, rake tasks, etc)
32
+ - Splits load time (Rails eager load) and Run time metrics
29
33
  - Easy to understand actionable insights from the report
34
+ - Tracks Gem usage (still in experimental stages and not recommended for production)
30
35
  - Development mode, offers deep insight of code usage details (number of LOC execution during single request, etc) during development.
31
36
  - Mountable web interface to easily share reports
32
37
 
@@ -52,9 +57,17 @@ gem 'coverband'
52
57
 
53
58
  If [tracking gem usage](#collecting-gem--library-usage), be sure to include coverband before other gems you would like to track.
54
59
 
60
+ ## Upgrading to Latest
61
+
62
+ ### No custom code or middleware required
63
+
64
+ With older versions of coverband, projects would report to redis using rack or sidekiq middleware. After coverband 4.0, this should no longer be required and could cause performance issues. Reporting to redis is now automatically done within a background thread with no custom code needed.
65
+
66
+ See [changelog](https://github.com/danmayer/coverband/blob/master/changes.md).
67
+
55
68
  ## Rails
56
69
 
57
- The Railtie integration means you shouldn't need to do anything anything else other than ensure coverband is required after rails within your Gemfile.
70
+ The Railtie integration means you shouldn't need to do anything else other than ensure coverband is required after rails within your Gemfile. The only exception to this is gem tracking of `Bundle.require` which depends on requiring coverband within the application.rb. See [Collecting Gem / Library Usage](https://github.com/danmayer/coverband#collecting-gem--library-usage).
58
71
 
59
72
  ## Sinatra
60
73
 
@@ -64,7 +77,7 @@ For the best coverage you want this loaded as early as possible. I have been put
64
77
  require 'coverband'
65
78
  require File.dirname(__FILE__) + '/config/environment'
66
79
 
67
- use Coverband::Middleware
80
+ use Coverband::BackgroundMiddleware
68
81
  run ActionController::Dispatcher.new
69
82
  ```
70
83
 
@@ -88,17 +101,20 @@ Rails.application.routes.draw do
88
101
  end
89
102
  ```
90
103
 
104
+ or you can enable basic auth by setting `ENV['COVERBAND_PASSWORD']` or via your configuration `config.password = 'my_pass'`
105
+
91
106
  ### Coverband Web Endpoint
92
107
 
93
108
  The web endpoint is a barebones endpoint that you can either expose direct (after authentication) or you can just link to the actions you wish to expose. The index is intended as a example to showcase all the features.
94
109
 
95
- ![image](https://raw.github.com/danmayer/coverband/master/docs/coverband_web_update.png)
110
+ ![image](https://raw.github.com/danmayer/coverband/master/docs/coverband_web_ui.png)
96
111
 
97
112
  > The web index as available on the Coverband Demo site
98
113
 
99
114
  - **force coverage collection:** This triggers coverage collection on the current webserver process
100
- - **reload Coverband files:** This has Coverband reload files as configured (force reload of some files that might not capture Coverage on boot). This can be used to reload files on demand.
101
115
  - **clear coverage report:** This will clear the coverage data. This wipes out all collected data (**dangerous**)
116
+ - View individual file details
117
+ - **clear individual file coverage:** This will clear the details of the file you are looking at. This is helpful if you don't want to lose all Coverage data but made a change that you expect would impact a particular file.
102
118
 
103
119
  ### Rake Tasks
104
120
 
@@ -118,14 +134,6 @@ Index Page
118
134
  Details on an example Sinatra app
119
135
  ![image](https://raw.github.com/danmayer/coverband/master/docs/coverband_details.png)
120
136
 
121
- # Verify Correct Installation
122
-
123
- - boot up your application
124
- - run app and hit a controller (via a web request, at least one request must complete)
125
- - run `rake coverband:coverage` this will show app initialization coverage
126
- - make another request, or enough that your reporting frequency will trigger
127
- - run `rake coverband:coverage` and you should see coverage increasing for the endpoints you hit.
128
-
129
137
  # Coverband Demo
130
138
 
131
139
  Take Coverband for a spin on the live Heroku deployed [Coverband Demo](https://coverband-demo.herokuapp.com/). The [full source code for the demo](https://github.com/danmayer/coverband_demo) is available to help with installation, configuration, and understanding of basic usage.
@@ -156,14 +164,34 @@ Coverband.configure do |config|
156
164
  config.s3_access_key_id = ENV['AWS_ACCESS_KEY_ID']
157
165
  config.s3_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
158
166
 
159
- # config options false, true, or 'debug'. Always use false in production
167
+ # config options false, true. (defaults to false)
160
168
  # true and debug can give helpful and interesting code usage information
161
- # they both increase the performance overhead of the gem a little.
162
- # they can also help with initially debugging the installation.
169
+ # and is safe to use if one is investigating issues in production, but it will slightly
170
+ # hit perf.
163
171
  config.verbose = false
172
+
173
+ # default false. button at the top of the web interface which clears all data
174
+ config.web_enable_clear = true
175
+
176
+ # default false. Experimental support for tracking view layer tracking.
177
+ # Does not track line-level usage, only indicates if an entire file
178
+ # is used or not.
179
+ config.track_views = true
164
180
  end
165
181
  ```
166
182
 
183
+ ### Working with environment variables
184
+
185
+ Do you use figaro, mc-settings, dotenv or something else to inject environment variables into your app? If so ensure you have that done BEFORE coverband is required.
186
+
187
+ For example if you use dotenv, you need to do this, see https://github.com/bkeepers/dotenv#note-on-load-order
188
+
189
+ ```
190
+ gem 'dotenv-rails', require: 'dotenv/rails-now'
191
+ gem 'coverband'
192
+ gem 'other-gem-that-requires-env-variables'
193
+ ```
194
+
167
195
  ### Ignoring Files
168
196
 
169
197
  Sometimes you have files that are known to be valuable perhaps in other environments or something that is just run very infrequently. Opposed to having to mentally filter them out of the report, you can just have them ignored in the Coverband reporting by using `config.ignore` as shown below. Ignore takes a string but can also match with regex rules see how below ignores all rake tasks as an example.
@@ -173,11 +201,21 @@ config.ignore += ['config/application.rb',
173
201
  'config/boot.rb',
174
202
  'config/puma.rb',
175
203
  'config/schedule.rb',
176
- 'bin/*'
204
+ 'bin/*',
177
205
  'config/environments/*',
178
206
  'lib/tasks/*']
179
207
  ```
180
208
 
209
+ ### View Tracking
210
+
211
+ Coverband allows an optional feature to track all view files that are used by an application.
212
+
213
+ To opt-in to this feature... enable the feature in your Coverband config.
214
+
215
+ `config.track_views = true`
216
+
217
+ ![image](https://raw.github.com/danmayer/coverband/master/docs/coverband_view_tracker.png)
218
+
181
219
  ### Writing Coverband Results to S3
182
220
 
183
221
  If you add some additional Coverband configuration your coverage html report will be written directly to S3, update `config/coverband.rb` like below.
@@ -199,13 +237,21 @@ ENV['AWS_ACCESS_KEY_ID']
199
237
  ENV['AWS_SECRET_ACCESS_KEY']
200
238
  ```
201
239
 
202
- ### Coverage Data Migration
240
+ ### Avoiding Cache Stampede
203
241
 
204
- Between the release of 4.0 and 4.1 our data format changed. This resets all your coverage data. If you want to restore your previous coverage data, feel free to migrate.
242
+ If you have many servers and they all hit Redis at the same time you can see spikes in your Redis CPU, and memory. This is do to a concept called [cache stampede](https://en.wikipedia.org/wiki/Cache_stampede). It is better to spread out the reporting across your servers. A simple way to do this is to add a random wiggle on your background reporting. This configuration option allows a wiggle. The right amount of wiggle depends on the numbers of servers you have and how willing you are to have delays in your coverage reporting. I would recommend at least 1 second per server.
205
243
 
206
- `rake coverband:migrate`
244
+ Add a wiggle (in seconds) to the background thread to avoid all your servers reporting at the same time:
207
245
 
208
- - We will be working to support migrations going forward, when possible
246
+ `config.reporting_wiggle = 30`
247
+
248
+ ### Redis Hash Store
249
+
250
+ Coverband on very high volume sites with many server processes reporting can have a race condition. To resolve the race condition and reduce Ruby memory overhead we have introduced a new Redis storage option. This moves the some of the work from the Ruby processes to Redis. It is worth noting because of this, it has a larger demands on the Redis server. So adjust your Redis instance accordingly. To help reduce the extra redis load you can also change the background reporting time period.
251
+
252
+ * set the new Redis store: `config.store = Coverband::Adapters::HashRedisStore.new(Redis.new(url: redis_url))`
253
+ * adjust from default 30s reporting `config.background_reporting_sleep_seconds = 120`
254
+ * reminder it is recommended to have a unique Redis per workload (background jobs, caching, Coverband), for this store, it may be more important to have a dedicated Redis.
209
255
 
210
256
  ### Clear Coverage
211
257
 
@@ -213,6 +259,14 @@ Now that Coverband uses MD5 hashes there should be no reason to manually clear c
213
259
 
214
260
  `rake coverband:clear`
215
261
 
262
+ ### Coverage Data Migration
263
+
264
+ Between the release of 4.0 and 4.1 our data format changed. This resets all your coverage data. If you want to restore your previous coverage data, feel free to migrate.
265
+
266
+ `rake coverband:migrate`
267
+
268
+ - We will be working to support migrations going forward, when possible
269
+
216
270
  ### Adding Rake Tasks outside of Rails
217
271
 
218
272
  Rails apps should automaticallly include the tasks via the Railtie.
@@ -233,35 +287,34 @@ rake coverband:clear # reset coverband coverage data
233
287
  rake coverband:coverage # report runtime coverband code coverage
234
288
  ```
235
289
 
236
- ### Forcing Coverband to Track Coverage on files loaded during boot `safe_reload_files`
290
+ ### Collecting Gem / Library Usage
237
291
 
238
- Coverband will report code usage for anything `required` or `loaded` after calling `Coverband.start` which happens automatically when coverband is required. This means some of the files loaded before coverband such as the Rails application.rb will be reported as having no coverage.
292
+ __WARNING:__ Gem Tracking is still in experimental stages and not recommended for production. We have some performance issues when view reports on large applications. Gem tracing also during background thread data collection has HIGH memory requirements, during report merging (seemingly around 128mb of extra memory, which is crazy). We recommend deploying WITHOUT `track_gems` first and only enabling it after confirming that Coverband is working and performing well.
239
293
 
240
- The `safe_reload_files` reload option in the configuration options can help to ensure you can track any files regardless of loading before Coverband. For example if I wanted to show the coverage of `config/coverband.rb`, which has to be loaded before calling `Coverband.start`, I could do that by adding that path to the `safe_reload_files` option.
294
+ Gem usage can be tracked by enabling the `track_gems` config.
241
295
 
242
296
  ```
243
297
  Coverband.configure do |config|
244
- # ... a bunch of other options
245
- # using the new safe reload to enforce files loaded
246
- config.safe_reload_files = ['config/coverband.rb']
298
+ config.track_gems = true
247
299
  end
248
300
  ```
249
301
 
250
- By adding any files above you will get reporting on those files as part of your coverage runtime report. The files are reloaded when Coverband first starts, you can also trigger a reload via the web interface.
251
-
252
- ### Collecting Gem / Library Usage
302
+ The `track_gems` feature exposes a Gems tab in the report which prints out the percentage usage of each Gem. See demo [here](https://coverband-demo.herokuapp.com/coverage?#_Gems).
253
303
 
254
- Gem usage can be tracked by enabling the `track_gems` config.
304
+ When tracking gems, it is important that `Coverband#start` is called before the gems to be tracked are required. The best way to do this is to require coverband before Bundle.require is called. Within rails, require coverband within the application.rb like so:
255
305
 
256
- ```
257
- Coverband.configure do |config|
258
- config.track_gems = true
259
- end
306
+ ```ruby
307
+ require 'coverband'
308
+ Bundler.require(*Rails.groups)
260
309
  ```
261
310
 
262
- The `track_gems` feature exposes a Gems tab in the report which prints out the percentage usage of each Gem. See demo [here](https://coverband-demo.herokuapp.com/coverage?#_Gems).
311
+ If you are using the resque integration, resque needs to be required before coverband since the integration will not run unless resque is loaded. Within the application.rb just require resque before coverband.
263
312
 
264
- When tracking gems, it is important that `Coverband#start` is called before the gems to be tracked are required. Since `Coverband#start` is automatically called by default when coverband is required, list coverband before the other gems to be tracked within your Gemfile. The exception to this are gems like rails and resque. Since coverband has some specific intergrations for these frameworks, these two gems should be required first.
313
+ ```ruby
314
+ require 'resque'
315
+ require 'coverband'
316
+ Bundler.require(*Rails.groups)
317
+ ```
265
318
 
266
319
  The track_gems config only exposes the overall usage of a gem. In order to see the detail of each file, enable the `gem_details` flag.
267
320
 
@@ -287,33 +340,23 @@ Coverband.start
287
340
 
288
341
  ### Verbose Debug / Development Mode
289
342
 
290
- Note: To debug issues getting Coverband working. I recommend running in development mode, by turning verbose logging on `config.verbose = true` and passing in the Rails.logger `config.logger = Rails.logger` to the Coverband config. This makes it easy to follow in development mode. Be careful to not leave these on in production as they will affect performance.
343
+ Note: To debug issues getting Coverband working. I recommend running in development mode, by turning verbose logging on `config.verbose = true` and passing in the Rails.logger `config.logger = Rails.logger` to the Coverband config. We respect the log level, and I would recommend log level info generally, but if you are investigating a prolbem Coverband logs additional data at the `debug` level. This makes it easy to follow in development mode. Be careful to not leave these on in production as they will affect performance.
291
344
 
292
345
  ---
293
346
 
294
- If you are trying to debug locally wondering what code is being run during a request. The verbose modes `config.verbose = true` and `config.verbose = 'debug'` can be useful. With true set it will output the number of lines executed per file, to the passed in log. The files are sorted from least used file to most active file. I have even run that mode in production without much of a problem. The debug verbose mode outputs both file usage and provides the number of calls per line of code. For example if you see something like below which indicates that the `application_helper` has 43150 lines executed. That might seem odd. Then looking at the breakdown of `application_helper` we can see that line `516` was executed 38,577 times. That seems bad, and is likely worth investigating perhaps memoizing or cacheing is required.
295
-
296
- config.verbose = 'debug'
297
-
298
- coverband file usage:
299
- [["/Users/danmayer/projects/app_name/lib/facebook.rb", 6],
300
- ["/Users/danmayer/projects/app_name/app/models/some_modules.rb", 9],
301
- ...
302
- ["/Users/danmayer/projects/app_name/app/models/user.rb", 2606],
303
- ["/Users/danmayer/projects/app_name/app/helpers/application_helper.rb",
304
- 43150]]
305
-
306
- file:
307
- /Users/danmayer/projects/app_name/app/helpers/application_helper.rb =>
308
- [[448, 1], [202, 1],
309
- ...
310
- [517, 1617], [516, 38577]]
347
+ If you are trying to debug locally wondering what code is being run during a request. The verbose modes `config.verbose = true` && `Rails.logger.level = :debug`. With true set it will output the number of lines executed per file, to the passed in log.
311
348
 
312
349
  # Prerequisites
313
350
 
314
351
  - Coverband 3.0.X+ requires Ruby 2.3+
315
352
  - Coverband currently requires Redis for production usage
316
353
 
354
+ ### Ruby and Rails Version Support
355
+
356
+ We will match Heroku & Ruby's support lifetime, supporting the last 3 major Ruby releases. For details see [supported runtimes](https://devcenter.heroku.com/articles/ruby-support#supported-runtimes).
357
+
358
+ For Rails, we will follow the policy of the [Rails team maintenance policy](https://guides.rubyonrails.org/maintenance_policy.html). We officially support the last two major release versions, while providing minimal support (major bugs / security fixes) for an additional version. This means at the moment we primaryly target Rails 6.x, 5.x, and will try to keep current functionality working for Rails 4.x but may release new features that do not work on that target.
359
+
317
360
  # Contributing To Coverband
318
361
 
319
362
  If you are working on adding features, PRs, or bugfixes to Coverband this section should help get you going.
@@ -335,12 +378,14 @@ If you submit a change please make sure the tests and benchmarks are passing.
335
378
  - view test coverage: `open coverage/index.html`
336
379
  - run the benchmarks before and after your change to see impact
337
380
  - `rake benchmarks`
381
+ - run a single test by line number like rspec: `bundle exec m test/coverband/reporters/html_test.rb:29`
338
382
 
339
383
  ### Known Issues
340
384
 
341
- - **total fail** on front end code, because of the precompiled template step basically coverage doesn't work well for `erb`, `slim`, and the like.
385
+ - **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.
342
386
  - 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
343
- - coverage doesn't show for Rails `config/application.rb` or `config/boot.rb` as they get loaded when loading the Rake environment prior to starting the `Coverage` library. See [reload files section](#forcing-coverband-to-track-coverage-on-files-loaded-during-boot-safe_reload_files).
387
+ - **NOTE:** We now have file level coverage for view files, but don't support line level detail
388
+ - 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.
344
389
 
345
390
  ### Debugging Redis Store
346
391
 
@@ -352,6 +397,10 @@ What is the coverage data in Redis?
352
397
 
353
398
  `Coverband.configuration.store.coverage`
354
399
 
400
+ ## Logo
401
+
402
+ The Coverband logo was created by [Dave Woodall](http://davewoodall.com). Thanks Dave!
403
+
355
404
  # License
356
405
 
357
406
  This is a MIT License project...
data/Rakefile CHANGED
@@ -1,10 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'bundler/gem_tasks'
4
-
5
4
  import 'test/benchmarks/benchmark.rake'
5
+ require 'rubocop/rake_task'
6
+
7
+ RuboCop::RakeTask.new
8
+
9
+ task default: %i[test]
6
10
 
7
- task default: [:test, :benchmarks]
11
+ task 'test:all': %i[rubocop test forked_tests benchmarks:memory benchmarks]
8
12
 
9
13
  task :test
10
14
  require 'rake/testtask'
@@ -17,9 +21,16 @@ Rake::TestTask.new(:test) do |test|
17
21
  test.verbose = true
18
22
  end
19
23
 
24
+ Rake::TestTask.new(:forked_tests) do |test|
25
+ test.libs << 'lib' << 'test'
26
+ test.test_files = FileList['test/forked/**/*_test.rb']
27
+ test.verbose = true
28
+ end
29
+
20
30
  desc 'load irb with this gem'
21
31
  task :console do
22
- exec 'irb -I lib -r coverband'
32
+ puts 'running console'
33
+ exec 'bundle console'
23
34
  end
24
35
 
25
36
  # This is really just for testing and development because without configuration
@@ -28,3 +39,8 @@ desc 'start webserver'
28
39
  task :server do
29
40
  exec 'rackup -I lib'
30
41
  end
42
+
43
+ desc 'publish gem with 2 factor auth, reminder how'
44
+ task :publish_gem do
45
+ exec 'gem push pkg/coverband-4.2.3.XXX.gem'
46
+ end