coverband 3.0.0 → 4.0.0
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.travis.yml +3 -0
- data/Gemfile +1 -0
- data/Gemfile.rails4 +7 -0
- data/Gemfile.rails4.lock +164 -0
- data/README.md +143 -334
- data/changes.md +41 -17
- data/coverband.gemspec +16 -4
- data/lib/coverband/adapters/base.rb +57 -8
- data/lib/coverband/adapters/file_store.rb +4 -22
- data/lib/coverband/adapters/redis_store.rb +7 -27
- data/lib/coverband/collectors/coverage.rb +7 -10
- data/lib/coverband/configuration.rb +27 -13
- data/lib/coverband/integrations/background.rb +26 -1
- data/lib/coverband/integrations/middleware.rb +5 -1
- data/lib/coverband/integrations/rack_server_check.rb +27 -0
- data/lib/coverband/reporters/simple_cov_report.rb +1 -7
- data/lib/coverband/reporters/web.rb +3 -21
- data/lib/coverband/utils/railtie.rb +17 -0
- data/lib/coverband/utils/s3_report.rb +108 -0
- data/lib/coverband/utils/tasks.rb +6 -6
- data/lib/coverband/version.rb +1 -1
- data/lib/coverband.rb +14 -3
- data/test/benchmarks/benchmark.rake +53 -2
- data/test/rails4_dummy/app/controllers/dummy_controller.rb +5 -0
- data/test/rails4_dummy/config/application.rb +15 -0
- data/test/rails4_dummy/config/boot.rb +3 -0
- data/test/rails4_dummy/config/coverband.rb +8 -0
- data/test/rails4_dummy/config/environment.rb +5 -0
- data/test/rails4_dummy/config/routes.rb +3 -0
- data/test/rails4_dummy/config/secrets.yml +3 -0
- data/test/rails4_dummy/config.ru +4 -0
- data/test/rails5_dummy/app/controllers/dummy_controller.rb +5 -0
- data/test/rails5_dummy/config/application.rb +16 -0
- data/test/rails5_dummy/config/coverband.rb +8 -0
- data/test/rails5_dummy/config/environment.rb +2 -0
- data/test/rails5_dummy/config/routes.rb +3 -0
- data/test/rails5_dummy/config.ru +3 -0
- data/test/rails_test_helper.rb +11 -0
- data/test/test_helper.rb +14 -9
- data/test/unit/adapters_base_test.rb +34 -13
- data/test/unit/adapters_file_store_test.rb +8 -4
- data/test/unit/adapters_redis_store_test.rb +7 -13
- data/test/unit/background_test.rb +24 -0
- data/test/unit/collectors_coverage_test.rb +14 -0
- data/test/unit/configuration_test.rb +12 -0
- data/test/unit/coverband_test.rb +26 -0
- data/test/unit/full_stack_test.rb +2 -1
- data/test/unit/middleware_test.rb +19 -0
- data/test/unit/rack_server_checkout_test.rb +24 -0
- data/test/unit/rails_full_stack_test.rb +60 -0
- data/test/unit/reports_base_test.rb +0 -2
- data/test/unit/reports_console_test.rb +1 -0
- data/test/unit/reports_simple_cov_test.rb +1 -10
- data/test/unit/reports_web_test.rb +1 -3
- data/test/unit/utils_s3_report_test.rb +44 -0
- metadata +89 -19
- data/lib/coverband/utils/s3_report_writer.rb +0 -59
- data/test/unit/utils_s3_report_writer_test.rb +0 -30
data/README.md
CHANGED
|
@@ -4,249 +4,145 @@ Build Status: [.
|
|
19
19
|
|
|
20
20
|
## Key Features
|
|
21
21
|
|
|
22
22
|
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.
|
|
23
23
|
|
|
24
24
|
* Low performance overhead
|
|
25
|
-
*
|
|
26
|
-
*
|
|
25
|
+
* Very simple setup and configuration
|
|
26
|
+
* Out of the box support for all standard code execution paths (web, cron, background jobs, rake tasks, etc)
|
|
27
|
+
* Easy to understand actionable insights from the report
|
|
27
28
|
* Development mode, offers deep insight of code usage details (number of LOC execution during single request, etc) during development.
|
|
28
|
-
*
|
|
29
|
-
* Allows for integration with any other Ruby application flows (background jobs, crons, scripts)
|
|
30
|
-
|
|
31
|
-
## Coverband Demo
|
|
32
|
-
|
|
33
|
-
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 configuration and understanding of basic usage.
|
|
34
|
-
|
|
35
|
-
# How To Use
|
|
36
|
-
|
|
37
|
-
Below is my Coverband workflow, which hopefully will help other best use this library.
|
|
38
|
-
|
|
39
|
-
* install coverband
|
|
40
|
-
* start your app and hit a few endpoints
|
|
41
|
-
* validate data collection and code coverage with `rake coverband:coverage`
|
|
42
|
-
* test setup in development (hit endpoints and generate new report)
|
|
43
|
-
* deploy to staging and verify functionality
|
|
44
|
-
* deploy to production and verify functionality
|
|
45
|
-
* every 2 weeks or so, with major releases
|
|
46
|
-
* clear old coverage: `rake coverband:clear`
|
|
47
|
-
* deploy and verify coverage is matching expectations
|
|
48
|
-
* __COVERAGE DRIFT__
|
|
49
|
-
* we are working to address this early in the 3.0.x feature set
|
|
50
|
-
* https://github.com/danmayer/coverband/issues/118
|
|
51
|
-
* if you never clear you have lines of code drift from when they were recorded
|
|
52
|
-
* if you clear on every deploy you don't capture as useful of data
|
|
53
|
-
* there is a tradeoff on accuracy and data value
|
|
54
|
-
* I recommend clearing after major code changes, significant releases, or some regular schedule.
|
|
55
|
-
|
|
56
|
-
## Example Output
|
|
57
|
-
|
|
58
|
-
Since Coverband is [Simplecov](https://github.com/colszowka/simplecov) output compatible it should work with any of the `SimpleCov::Formatter`'s available. The output below is produced using the default Simplecov HTML formatter.
|
|
59
|
-
|
|
60
|
-
Index Page
|
|
61
|
-

|
|
62
|
-
|
|
63
|
-
Details on a example Sinatra app
|
|
64
|
-

|
|
29
|
+
* Mountable web interface to easily share reports
|
|
65
30
|
|
|
66
31
|
|
|
67
32
|
# Installation
|
|
68
33
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-

|
|
72
|
-
|
|
73
|
-
## Prerequisites
|
|
74
|
-
|
|
75
|
-
* Coverband 3.0 requres Ruby 2.3+
|
|
34
|
+
Coverband should be near zero config for Rails apps, if you have an issue with that, please [file an issue](https://github.com/danmayer/coverband/issues).
|
|
76
35
|
|
|
77
36
|
## Gem Installation
|
|
78
37
|
|
|
79
|
-
Add this line to your application's Gemfile:
|
|
38
|
+
Add this line to your application's `Gemfile`, remember to `bundle install` after updating:
|
|
80
39
|
|
|
81
40
|
```bash
|
|
82
41
|
gem 'coverband'
|
|
83
42
|
```
|
|
84
43
|
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
```bash
|
|
88
|
-
$ bundle
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Or install it yourself as:
|
|
92
|
-
|
|
93
|
-
```bash
|
|
94
|
-
$ gem install coverband
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
# Configuration
|
|
44
|
+
## Rails
|
|
98
45
|
|
|
99
|
-
|
|
46
|
+
The Railtie integration means you shouldn't need to do anything anything else.
|
|
100
47
|
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
3. Insert Coverband Rack Middleware
|
|
48
|
+
* By default Coverband will try to stored data to Redis
|
|
49
|
+
* Redis endpoint is looked for in this order: `ENV['COVERBAND_REDIS_URL']`, `ENV['REDIS_URL']`, or `localhost`
|
|
104
50
|
|
|
105
|
-
|
|
51
|
+
## Sinatra
|
|
106
52
|
|
|
107
|
-
|
|
53
|
+
For the best coverage you want this loaded as early as possible. I have been putting it directly in my `config.ru` but you could use an initializer, though you may end up missing some boot up coverage. To start collection require Coverband as early as possible.
|
|
108
54
|
|
|
109
55
|
```ruby
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
config.root = Dir.pwd
|
|
113
|
-
config.store = Coverband::Adapters::RedisStore.new(Redis.new(url: ENV['REDIS_URL'])) if defined? Redis
|
|
114
|
-
config.ignore = %w[vendor .erb$ .slim$]
|
|
115
|
-
# add paths that you deploy to that might be different than your local dev root path
|
|
116
|
-
config.root_paths = []
|
|
117
|
-
|
|
118
|
-
# reporting frequency, how often coverage data is sent to the store
|
|
119
|
-
# if you are debugging changes to coverband I recommend setting to 100.0
|
|
120
|
-
config.reporting_frequency = Rails.env.production? ? 1.0 : 100.0
|
|
121
|
-
config.logger = Rails.logger
|
|
56
|
+
require 'coverband'
|
|
57
|
+
require File.dirname(__FILE__) + '/config/environment'
|
|
122
58
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
# they both increase the performance overhead of the gem a little.
|
|
126
|
-
# they can also help with initially debugging the installation.
|
|
127
|
-
# config.verbose = 'debug'
|
|
128
|
-
end
|
|
59
|
+
use Coverband::Middleware
|
|
60
|
+
run ActionController::Dispatcher.new
|
|
129
61
|
```
|
|
130
62
|
|
|
131
|
-
|
|
63
|
+
# Report Generation
|
|
132
64
|
|
|
133
|
-
|
|
65
|
+
There are two primary ways to generate and view the report
|
|
134
66
|
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
require 'coverband/utils/tasks'
|
|
139
|
-
```
|
|
140
|
-
This should give you access to a number of Coverband tasks
|
|
67
|
+
## Rake Tasks
|
|
68
|
+
|
|
69
|
+
After installing the gem in Rails you should have these Rake tasks
|
|
141
70
|
|
|
142
71
|
```bash
|
|
143
72
|
rake -T coverband
|
|
144
|
-
rake coverband:
|
|
145
|
-
rake coverband:
|
|
73
|
+
rake coverband:coverage # report runtime Coverband code coverage
|
|
74
|
+
rake coverband:clear # reset Coverband coverage data, helpful for development, debugging, etc
|
|
146
75
|
```
|
|
147
76
|
|
|
148
|
-
|
|
77
|
+
You can view the report different ways, but the easiest is the Rake task which opens the SimpleCov formatted HTML.
|
|
149
78
|
|
|
150
|
-
|
|
79
|
+
`rake coverband:coverage`
|
|
151
80
|
|
|
152
|
-
|
|
81
|
+
This should auto-open in your browser, but if it doesn't the output file should be in `coverage/index.html`
|
|
153
82
|
|
|
154
|
-
|
|
83
|
+
## Viewing the Report in App
|
|
155
84
|
|
|
156
|
-
|
|
85
|
+
First setup Coverband to [write reports to S3](#writing-coverband-results-to-s3) you can host the S3 file with a built in rack app in Coverband. Just configure your Rails route `config/routes.rb`
|
|
157
86
|
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
module MyApplication
|
|
163
|
-
class Application < Rails::Application
|
|
164
|
-
[...]
|
|
165
|
-
|
|
166
|
-
# Coverband needs to be setup before any of the initializers to capture usage of them
|
|
167
|
-
require 'coverband'
|
|
168
|
-
Coverband.configure
|
|
169
|
-
config.middleware.use Coverband::Middleware
|
|
170
|
-
|
|
171
|
-
# if one uses before_eager_load as I did previously
|
|
172
|
-
# any files that get loaded as part of railties will have no coverage
|
|
173
|
-
config.before_initialize do
|
|
174
|
-
Coverband.start
|
|
175
|
-
end
|
|
176
|
-
end
|
|
87
|
+
```
|
|
88
|
+
Rails.application.routes.draw do
|
|
89
|
+
# ... lots of routes
|
|
90
|
+
mount Coverband::Reporters::Web.new, at: '/coverage'
|
|
177
91
|
end
|
|
178
92
|
```
|
|
179
93
|
|
|
180
|
-
|
|
94
|
+
__NOTE__: ADD PASSWORD PROTECTION OR YOU CAN EXPOSE ALL YOUR SOURCE CODE
|
|
181
95
|
|
|
182
|
-
|
|
96
|
+
It is easy to add basic protection around the coverage data, below shows how you can use devise or basic auth, by adding a bit of code to your `config/routes.rb` file.
|
|
183
97
|
|
|
184
|
-
```
|
|
185
|
-
|
|
98
|
+
```
|
|
99
|
+
# protect with existing Rails devise configuration
|
|
100
|
+
devise_constraint = lambda do |request|
|
|
101
|
+
request.env['warden'] && request.env['warden'].authenticate? && request.env['warden'].user.admin?
|
|
102
|
+
end
|
|
186
103
|
|
|
187
|
-
|
|
188
|
-
|
|
104
|
+
# protect with http basic auth
|
|
105
|
+
# curl --user foo:bar http://localhost:3000/coverage
|
|
106
|
+
Rails.application.routes.draw do
|
|
107
|
+
# ... lots of routes
|
|
189
108
|
|
|
190
|
-
|
|
191
|
-
|
|
109
|
+
# Create a Rack wrapper around the Coverband Web Reporter to support & prompt the user for basic authentication.
|
|
110
|
+
AuthenticatedCoverband = Rack::Builder.new do
|
|
111
|
+
use Rack::Auth::Basic do |username, password|
|
|
112
|
+
username == 'foo' && password == 'bar'
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
run Coverband::Reporters::Web.new
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Connect the wrapper app to your desired endpoint.
|
|
119
|
+
mount AuthenticatedCoverband, at: '/coverage'
|
|
120
|
+
end
|
|
192
121
|
```
|
|
193
122
|
|
|
194
123
|
# Verify Correct Installation
|
|
195
124
|
|
|
196
125
|
* boot up your application
|
|
126
|
+
* run app and hit a controller (via a web request, at least one request must complete)
|
|
197
127
|
* run `rake coverband:coverage` this will show app initialization coverage
|
|
198
|
-
*
|
|
128
|
+
* make another request, or enough that your reporting frequency will trigger
|
|
199
129
|
* run `rake coverband:coverage` and you should see coverage increasing for the endpoints you hit.
|
|
200
130
|
|
|
201
|
-
|
|
131
|
+
# Coverband Demo
|
|
202
132
|
|
|
203
|
-
|
|
133
|
+
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.
|
|
204
134
|
|
|
205
|
-
|
|
206
|
-
rails new coverage_example
|
|
207
|
-
cd coverage_example
|
|
208
|
-
atom .
|
|
209
|
-
|
|
210
|
-
# open Gemfile, add lines
|
|
211
|
-
gem 'redis'
|
|
212
|
-
gem 'coverband', '>= 3.0.0.alpha2', require: false
|
|
213
|
-
|
|
214
|
-
bundle install
|
|
215
|
-
|
|
216
|
-
# create config/coverband.rb
|
|
217
|
-
# copy the config from the readme
|
|
218
|
-
# If you don't set REDIS_URL, remove that to use default localhost
|
|
219
|
-
|
|
220
|
-
# Make some code so we can look at the coverage
|
|
221
|
-
rails generate scaffold blogs
|
|
222
|
-
rake db:migrate
|
|
223
|
-
|
|
224
|
-
# open Rakefile, add lines
|
|
225
|
-
require 'coverband'
|
|
226
|
-
Coverband.configure
|
|
227
|
-
require 'coverband/utils/tasks'
|
|
228
|
-
|
|
229
|
-
# verify rake
|
|
230
|
-
rake -T coverband
|
|
231
|
-
|
|
232
|
-
# configure config/application.rb
|
|
233
|
-
# copy lines from readme
|
|
234
|
-
|
|
235
|
-
# start up your app
|
|
236
|
-
rake coverband:coverage
|
|
237
|
-
# view boot up coverage
|
|
238
|
-
|
|
239
|
-
rails s
|
|
240
|
-
|
|
241
|
-
open http://localhost:3000/blogs
|
|
242
|
-
|
|
243
|
-
# click around some to trigger usage
|
|
135
|
+
# How To Use
|
|
244
136
|
|
|
245
|
-
|
|
246
|
-
rake coverband:coverage
|
|
247
|
-
```
|
|
137
|
+
Below is my Coverband workflow, which hopefully will help other best use this library.
|
|
248
138
|
|
|
249
|
-
#
|
|
139
|
+
* <a href="#installation">Install Coverband</a>
|
|
140
|
+
* Start your app and hit a few endpoints
|
|
141
|
+
* Validate data collection and code coverage with `rake coverband:coverage`
|
|
142
|
+
* If you see app startup and recent visits showing, setup is correct
|
|
143
|
+
* I generally configure the mountable web endpoint to [view the data via the web-app](https://github.com/danmayer/coverband#viewing--hosting-s3-coverband-results-in-app)
|
|
144
|
+
* After Coverband has been verified to be working on production, I let it run for a few weeks.
|
|
145
|
+
* Then I view the report and start submitting PRs for the team to review delete large related sets of code that no longer are in use.
|
|
250
146
|
|
|
251
147
|
### Example apps
|
|
252
148
|
|
|
@@ -254,132 +150,92 @@ rake coverband:coverage
|
|
|
254
150
|
- [Sinatra app](https://github.com/danmayer/churn-site)
|
|
255
151
|
- [Non Rack Ruby app](https://github.com/danmayer/coverband_examples)
|
|
256
152
|
|
|
257
|
-
###
|
|
153
|
+
### Example Output
|
|
258
154
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
`rake coverband:coverage`
|
|
262
|
-
|
|
263
|
-
This should auto-open in your browser, but if it doesn't the output file should be in `coverage/index.html`
|
|
264
|
-
|
|
265
|
-
### Clear Coverage
|
|
266
|
-
|
|
267
|
-
If your code has changed and your coverage line data doesn't seem to match run time. You probably need to clear your old line data... You will need to run this in the environment you wish to clear the data from.
|
|
268
|
-
|
|
269
|
-
`rake coverband:clear`
|
|
270
|
-
|
|
271
|
-
### Automated Clearing Line Coverage Data
|
|
272
|
-
|
|
273
|
-
After a deploy where code has changed significantly. This is to avoid coverage drift
|
|
155
|
+
Since Coverband is [Simplecov](https://github.com/colszowka/simplecov) output compatible it should work with any of the `SimpleCov::Formatter`'s available. The output below is produced using the default Simplecov HTML formatter.
|
|
274
156
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
you can live with minor inconsistency for some files.
|
|
157
|
+
Index Page
|
|
158
|
+

|
|
278
159
|
|
|
279
|
-
|
|
160
|
+
Details on a example Sinatra app
|
|
161
|
+

|
|
280
162
|
|
|
281
|
-
|
|
282
|
-
# defaults to the currently configured Coverband.configuration.redis
|
|
283
|
-
Coverband::Reporter.clear_coverage
|
|
284
|
-
# or pass in the current target redis
|
|
285
|
-
Coverband::Reporter.clear_coverage(Redis.new(:host => 'target.com', :port => 6789))
|
|
286
|
-
```
|
|
287
|
-
You can also do this with the included rake tasks.
|
|
163
|
+
### Advanced Coverband Config
|
|
288
164
|
|
|
289
|
-
|
|
165
|
+
You may need to configure Coverband you can either do that passing in all configuration options to `Coverband.configure` in block format, or a simpler style is to call `Coverband.configure` with no params which will load `config/coverband.rb` expecting it to configure the app correctly.
|
|
290
166
|
|
|
291
|
-
|
|
167
|
+
* See [lib/coverband/configuration.rb](https://github.com/danmayer/coverband/blob/master/lib/coverband/configuration.rb) for all options
|
|
168
|
+
* I strongly recommend setting up the S3 report adapter, which can't be automatically configured
|
|
169
|
+
* By default Coverband will try to stored data to Redis
|
|
170
|
+
* Redis endpoint is looked for in this order: `ENV['COVERBAND_REDIS_URL']`, `ENV['REDIS_URL']`, or `localhost`
|
|
292
171
|
|
|
293
|
-
|
|
172
|
+
Below is an example config file for a Rails 5 app:
|
|
294
173
|
|
|
295
174
|
```ruby
|
|
296
|
-
|
|
297
|
-
Coverband.configure
|
|
298
|
-
|
|
175
|
+
#config/coverband.rb
|
|
176
|
+
Coverband.configure do |config|
|
|
177
|
+
# configure S3 integration
|
|
178
|
+
config.s3_bucket = 'coverband-demo'
|
|
179
|
+
config.s3_region = 'us-east-1'
|
|
180
|
+
config.s3_access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
|
181
|
+
config.s3_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
|
299
182
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
183
|
+
# config options false, true, or 'debug'. Always use false in production
|
|
184
|
+
# true and debug can give helpful and interesting code usage information
|
|
185
|
+
# they both increase the performance overhead of the gem a little.
|
|
186
|
+
# they can also help with initially debugging the installation.
|
|
187
|
+
config.verbose = false
|
|
304
188
|
end
|
|
305
189
|
```
|
|
306
190
|
|
|
307
|
-
|
|
191
|
+
### Writing Coverband Results to S3
|
|
192
|
+
|
|
193
|
+
If you add some additional Coverband configuration your coverage html report will be written directly to S3, update `config/coverband.rb` like below.
|
|
308
194
|
|
|
309
|
-
```
|
|
310
|
-
#
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
ensure
|
|
316
|
-
Coverband::Collectors::Coverage.instance.report_coverage
|
|
317
|
-
end
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
...
|
|
321
|
-
chain.add Sidekiq::CoverbandMiddleware
|
|
195
|
+
```
|
|
196
|
+
# configure S3 integration
|
|
197
|
+
config.s3_bucket = 'coverband-demo'
|
|
198
|
+
config.s3_region = 'us-east-1'
|
|
199
|
+
config.s3_access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
|
200
|
+
config.s3_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
|
322
201
|
```
|
|
323
202
|
|
|
324
|
-
|
|
203
|
+
Alternatively, Coverband if you don't set via the `config.s3_*` accessor methods will look for the standard S3 environment variables.
|
|
325
204
|
|
|
205
|
+
```
|
|
206
|
+
ENV['AWS_BUCKET']
|
|
207
|
+
ENV['AWS_REGION']
|
|
208
|
+
ENV['AWS_ACCESS_KEY_ID']
|
|
209
|
+
ENV['AWS_SECRET_ACCESS_KEY']
|
|
210
|
+
```
|
|
326
211
|
|
|
327
|
-
|
|
328
|
-
require "coverband"
|
|
329
|
-
Coverband.configure
|
|
330
|
-
Coverband.start
|
|
212
|
+
### Clear Coverage
|
|
331
213
|
|
|
332
|
-
|
|
333
|
-
Coverband::Collectors::Coverage.instance.report_coverage
|
|
214
|
+
Now that Coverband uses MD5 hashes there should be no reason to manually clear coverage unless one is testing, changing versions, possibly debugging Coberband itself.
|
|
334
215
|
|
|
335
|
-
|
|
216
|
+
`rake coverband:clear`
|
|
336
217
|
|
|
337
|
-
###
|
|
218
|
+
### Adding Rake Tasks outside of Rails
|
|
338
219
|
|
|
339
|
-
|
|
220
|
+
Rails apps should automaticallly include the tasks via the Railtie.
|
|
340
221
|
|
|
341
|
-
|
|
222
|
+
For non Rails apps, either add the below to your `Rakefile` or to a file included in your `Rakefile` such as `lib/tasks/coverband.rake` if you want to break it up that way.
|
|
342
223
|
|
|
343
|
-
```
|
|
224
|
+
```ruby
|
|
344
225
|
require 'coverband'
|
|
345
226
|
Coverband.configure
|
|
346
227
|
require 'coverband/utils/tasks'
|
|
347
|
-
|
|
348
|
-
# Wrap all Rake tasks with Coverband
|
|
349
|
-
current_tasks = Rake.application.top_level_tasks
|
|
350
|
-
if current_tasks.any? && current_tasks.none? { |t| t.to_s.match?(/^coverband:/) }
|
|
351
|
-
current_tasks.unshift 'coverband:start'
|
|
352
|
-
current_tasks.push 'coverband:stop_and_save'
|
|
353
|
-
end
|
|
354
|
-
|
|
355
|
-
namespace :coverband do
|
|
356
|
-
task :start do
|
|
357
|
-
Coverband.start
|
|
358
|
-
end
|
|
359
|
-
|
|
360
|
-
task :stop_and_save do
|
|
361
|
-
Coverband::Collectors::Coverage.instance.report_coverage
|
|
362
|
-
end
|
|
363
|
-
end
|
|
364
228
|
```
|
|
365
229
|
|
|
366
|
-
|
|
230
|
+
Verify it works
|
|
367
231
|
|
|
368
|
-
```
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
#
|
|
372
|
-
class CoverageRunner < ::Rails::Railtie
|
|
373
|
-
runner do
|
|
374
|
-
Coverband.start
|
|
375
|
-
at_exit do
|
|
376
|
-
Coverband::Collectors::Coverage.instance.report_coverage
|
|
377
|
-
end
|
|
378
|
-
end
|
|
379
|
-
end
|
|
232
|
+
```bash
|
|
233
|
+
rake -T coverband
|
|
234
|
+
rake coverband:clear # reset coverband coverage data
|
|
235
|
+
rake coverband:coverage # report runtime coverband code coverage
|
|
380
236
|
```
|
|
381
237
|
|
|
382
|
-
###
|
|
238
|
+
### Forcing Coverband to Track Coverage on files loaded during boot `safe_reload_files`
|
|
383
239
|
|
|
384
240
|
The way Coverband is built it will record and report code usage in production for anything `required` or `loaded` after calling `Coverband.start`. This means some of Rails initial files and Gems are loaded before you can generally call `Coverband.start` for example if you use the `application.rb` to initialize and start Coverband, that file will be reported as having no coverage, as it can't possibly start Coverband before the file is loaded.
|
|
385
241
|
|
|
@@ -399,20 +255,18 @@ By adding any files above you will get reporting on those files as part of your
|
|
|
399
255
|
|
|
400
256
|
By default Coverband has assumed you are trying to track your application code usage not all the supporting framework and library (Gems) code usage. There has been some good points and reasons folks want to track library usage, for example to find out which Gems they aren't actually using in production. See some of the discussion on [issue 21](https://github.com/danmayer/coverband/issues/21).
|
|
401
257
|
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
*
|
|
406
|
-
|
|
407
|
-
*
|
|
408
|
-
*
|
|
409
|
-
* while possible this is currently hard as Rails and most environments load your whole Gemfile
|
|
410
|
-
* looking for an improve and easier way to support this.
|
|
258
|
+
How to collect gem usage with Coverband:
|
|
259
|
+
|
|
260
|
+
* use the `safe_reload_files` feature to add the path of all gem files you wish to track
|
|
261
|
+
* --- or ---
|
|
262
|
+
* ensure you call `require 'coverband'` which triggers `Coverband.start` before loading all your gems
|
|
263
|
+
* while possible this is currently hard as Rails and most environments load your whole Gemfile
|
|
264
|
+
* we are looking for an improve and easier way to support this.
|
|
411
265
|
|
|
412
266
|
|
|
413
267
|
### Verbose Debug / Development Mode
|
|
414
268
|
|
|
415
|
-
Note: To debug issues getting
|
|
269
|
+
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.
|
|
416
270
|
|
|
417
271
|
---
|
|
418
272
|
|
|
@@ -434,58 +288,6 @@ If you are trying to debug locally wondering what code is being run during a req
|
|
|
434
288
|
...
|
|
435
289
|
[517, 1617], [516, 38577]]
|
|
436
290
|
|
|
437
|
-
### Writing Coverband Results to S3
|
|
438
|
-
|
|
439
|
-
If you add some additional Coverband configuration your coverage html report will be written directly to S3, update `config/coverband.rb` like below.
|
|
440
|
-
|
|
441
|
-
```
|
|
442
|
-
# configure S3 integration
|
|
443
|
-
config.s3_bucket = 'coverband-demo'
|
|
444
|
-
config.s3_region = 'us-east-1'
|
|
445
|
-
config.s3_access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
|
446
|
-
config.s3_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
|
447
|
-
```
|
|
448
|
-
|
|
449
|
-
### Viewing / Hosting S3 Coverband results in app
|
|
450
|
-
|
|
451
|
-
Beyond writing to S3 you can host the S3 file with a build in Sintatra app in Coverband. Just configure your Rails route `config/routes.rb`
|
|
452
|
-
|
|
453
|
-
```
|
|
454
|
-
Rails.application.routes.draw do
|
|
455
|
-
# ... lots of routes
|
|
456
|
-
mount Coverband::Reporters::Web.new, at: '/coverage'
|
|
457
|
-
end
|
|
458
|
-
```
|
|
459
|
-
|
|
460
|
-
__NOTE__: ADD PASSWORD PROTECTION OR YOU CAN EXPOSE ALL YOUR SOURCE CODE
|
|
461
|
-
|
|
462
|
-
It is easy to add some basic protect around the coverage data, below shows how you can use devise or basic auth, by adding a bit of code to your `config/routes.rb` file.
|
|
463
|
-
|
|
464
|
-
```
|
|
465
|
-
# protect with existing Rails devise configuration
|
|
466
|
-
devise_constraint = lambda do |request|
|
|
467
|
-
request.env['warden'] && request.env['warden'].authenticate? && request.env['warden'].user.admin?
|
|
468
|
-
end
|
|
469
|
-
|
|
470
|
-
# protect with http basic auth
|
|
471
|
-
# curl --user foo:bar http://localhost:3000/coverage
|
|
472
|
-
basic_constraint = lambda do |request|
|
|
473
|
-
return true if Rails.env.development?
|
|
474
|
-
if ActionController::HttpAuthentication::Basic.has_basic_credentials?(request)
|
|
475
|
-
credentials = ActionController::HttpAuthentication::Basic.decode_credentials(request)
|
|
476
|
-
email, password = credentials.split(':')
|
|
477
|
-
|
|
478
|
-
email == 'foo' && password = 'bar'
|
|
479
|
-
end
|
|
480
|
-
end
|
|
481
|
-
|
|
482
|
-
Rails.application.routes.draw do
|
|
483
|
-
# ... lots of routes
|
|
484
|
-
constraints basic_constraint do
|
|
485
|
-
mount Coverband::Reporters::Web.new, at: '/coverage'
|
|
486
|
-
end
|
|
487
|
-
end
|
|
488
|
-
```
|
|
489
291
|
|
|
490
292
|
### Conflicting .Simplecov: Issue with Missing or 0% Coverage Report
|
|
491
293
|
|
|
@@ -511,6 +313,11 @@ You could see some confusing results... To avoid this issue Coverband has a Rake
|
|
|
511
313
|
|
|
512
314
|
This will build the report after disabling any `.simplecov` applied settings.
|
|
513
315
|
|
|
316
|
+
# Prerequisites
|
|
317
|
+
|
|
318
|
+
* Coverband 3.0.X+ requires Ruby 2.3+
|
|
319
|
+
* Coverband currently requires Redis for production usage
|
|
320
|
+
|
|
514
321
|
# Contributing To Coverband
|
|
515
322
|
|
|
516
323
|
If you are working on adding features, PRs, or bugfixes to Coverband this section should help get you going.
|
|
@@ -526,7 +333,9 @@ If you are working on adding features, PRs, or bugfixes to Coverband this sectio
|
|
|
526
333
|
|
|
527
334
|
If you submit a change please make sure the tests and benchmarks are passing.
|
|
528
335
|
|
|
529
|
-
* run tests:
|
|
336
|
+
* run tests:
|
|
337
|
+
* `bundle exec rake`
|
|
338
|
+
* `BUNDLE_GEMFILE=Gemfile.rails4 bundle exec rake` (Same tests using rails 4 instead of 5)
|
|
530
339
|
* view test coverage: `open coverage/index.html`
|
|
531
340
|
* run the benchmarks before and after your change to see impact
|
|
532
341
|
* `rake benchmarks`
|
|
@@ -534,7 +343,7 @@ If you submit a change please make sure the tests and benchmarks are passing.
|
|
|
534
343
|
### Known Issues
|
|
535
344
|
|
|
536
345
|
* __total fail__ on front end code, because of the precompiled template step basically coverage doesn't work well for `erb`, `slim`, and the like.
|
|
537
|
-
* 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.
|
|
346
|
+
* 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
|
|
538
347
|
* If you have SimpleCov filters, you need to clear them prior to generating your coverage report. As the filters will be applied to Coverband as well and can often filter out everything we are recording.
|
|
539
348
|
* 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.
|
|
540
349
|
|