coverband 3.0.1 → 4.0.0.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Gemfile.rails4.lock +2 -2
- data/README.md +138 -331
- data/changes.md +28 -17
- data/coverband.gemspec +8 -3
- data/lib/coverband.rb +10 -2
- data/lib/coverband/collectors/coverage.rb +4 -12
- data/lib/coverband/configuration.rb +25 -14
- data/lib/coverband/integrations/background.rb +4 -3
- data/lib/coverband/integrations/middleware.rb +5 -1
- data/lib/coverband/reporters/web.rb +1 -1
- data/lib/coverband/utils/railtie.rb +17 -0
- data/lib/coverband/utils/tasks.rb +6 -6
- data/lib/coverband/version.rb +1 -1
- data/test/benchmarks/benchmark.rake +6 -1
- data/test/unit/background_test.rb +11 -3
- data/test/unit/collectors_coverage_test.rb +2 -12
- data/test/unit/full_stack_test.rb +2 -1
- data/test/unit/middleware_test.rb +19 -0
- data/test/unit/rails_full_stack_test.rb +45 -1
- metadata +25 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f4af70bbf7e6cdaf4fd8a83a22fe3586d040bdb03b255f0ede2daef2dd9ec5ae
|
4
|
+
data.tar.gz: 721b4a9029d26e2d182cf55280652f87a0cf1c3f40084bb692ac61417d7224ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8aeef26e11f9cb8e1b674bf97e55252acdbdee766f1870797ff6550495f5a06a2a3b17c92901843db7bdb5bb195d7a7d320fef4c49eddd4da0c36b00e8a8a9f
|
7
|
+
data.tar.gz: ce9ebbb91bbfe94e56646155417946e0d35ae1f757cf45047b12408855224ce9d9abcfa089c80c966222a507b13c2e5bc933ffb142d52643a36629b915a6f34f
|
data/Gemfile.rails4.lock
CHANGED
data/README.md
CHANGED
@@ -4,191 +4,120 @@ Build Status: [![Build Status](https://travis-ci.org/danmayer/coverband.svg?bran
|
|
4
4
|
|
5
5
|
<p align="center">
|
6
6
|
<a href="#key-features">Key Features</a> •
|
7
|
-
<a href="#coverband-demo">Coverband Demo</a> •
|
8
|
-
<a href="#how-to-use">How To Use</a> •
|
9
7
|
<a href="#installation">Installation</a> •
|
10
8
|
<a href="#configuration">Configuration</a> •
|
9
|
+
<a href="#coverband-demo">Coverband Demo</a> •
|
10
|
+
<a href="#how-to-use">How To Use</a> •
|
11
11
|
<a href="#usage">Usage</a> •
|
12
12
|
<a href="#license">License</a> •
|
13
13
|
<a href="/changes.md">Change Log / Roadmap</a>
|
14
14
|
</p>
|
15
15
|
|
16
|
-
A gem to measure production code usage, showing each line of code that is executed. Coverband allows easy configuration to collect and report on production code usage. It can be used as Rack middleware,
|
16
|
+
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.
|
17
17
|
|
18
|
-
|
18
|
+
__Note:__ Coverband is not intended for test code coverage, for that we recommended using [SimpleCov](https://github.com/colszowka/simplecov).
|
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
|
-
![image](https://raw.github.com/danmayer/coverband/master/docs/coverband_index.png)
|
62
|
-
|
63
|
-
Details on a example Sinatra app
|
64
|
-
![image](https://raw.github.com/danmayer/coverband/master/docs/coverband_details.png)
|
29
|
+
* Mountable web interface to easily share reports
|
65
30
|
|
66
31
|
|
67
32
|
# Installation
|
68
33
|
|
69
|
-
|
70
|
-
|
71
|
-
![coverband installation](https://raw.githubusercontent.com/danmayer/coverband/master/docs/coverband-install-resize.gif)
|
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
|
-
```
|
44
|
+
## Rails
|
96
45
|
|
97
|
-
|
46
|
+
The Railtie integration means you shouldn't need to do anything anything else.
|
98
47
|
|
99
|
-
|
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`
|
100
50
|
|
101
|
-
|
102
|
-
2. Configure Rake
|
103
|
-
3. Insert Coverband Rack Middleware
|
51
|
+
## Sinatra
|
104
52
|
|
105
|
-
|
106
|
-
|
107
|
-
You need to configure cover band 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 nothing while will load `config/coverband.rb` expecting it to configure the app correctly. Below is an example config file for a Rails 5 app:
|
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
|
@@ -199,55 +128,21 @@ run ActionController::Dispatcher.new
|
|
199
128
|
* make another request, or enough that your reporting frequency will trigger
|
200
129
|
* run `rake coverband:coverage` and you should see coverage increasing for the endpoints you hit.
|
201
130
|
|
202
|
-
|
203
|
-
|
204
|
-
These are the steps taken to install and configure Coverband
|
205
|
-
|
206
|
-
```
|
207
|
-
rails new coverage_example
|
208
|
-
cd coverage_example
|
209
|
-
atom .
|
210
|
-
|
211
|
-
# open Gemfile, add lines
|
212
|
-
gem 'redis'
|
213
|
-
gem 'coverband', '>= 3.0.0.alpha2', require: false
|
214
|
-
|
215
|
-
bundle install
|
216
|
-
|
217
|
-
# create config/coverband.rb
|
218
|
-
# copy the config from the readme
|
219
|
-
# If you don't set REDIS_URL, remove that to use default localhost
|
220
|
-
|
221
|
-
# Make some code so we can look at the coverage
|
222
|
-
rails generate scaffold blogs
|
223
|
-
rake db:migrate
|
224
|
-
|
225
|
-
# open Rakefile, add lines
|
226
|
-
require 'coverband'
|
227
|
-
Coverband.configure
|
228
|
-
require 'coverband/utils/tasks'
|
229
|
-
|
230
|
-
# verify rake
|
231
|
-
rake -T coverband
|
232
|
-
|
233
|
-
# configure config/application.rb
|
234
|
-
# copy lines from readme
|
235
|
-
|
236
|
-
# start up your app
|
237
|
-
rake coverband:coverage
|
238
|
-
# view boot up coverage
|
239
|
-
|
240
|
-
rails s
|
131
|
+
# Coverband Demo
|
241
132
|
|
242
|
-
|
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.
|
243
134
|
|
244
|
-
#
|
135
|
+
# How To Use
|
245
136
|
|
246
|
-
|
247
|
-
rake coverband:coverage
|
248
|
-
```
|
137
|
+
Below is my Coverband workflow, which hopefully will help other best use this library.
|
249
138
|
|
250
|
-
#
|
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.
|
251
146
|
|
252
147
|
### Example apps
|
253
148
|
|
@@ -255,132 +150,92 @@ rake coverband:coverage
|
|
255
150
|
- [Sinatra app](https://github.com/danmayer/churn-site)
|
256
151
|
- [Non Rack Ruby app](https://github.com/danmayer/coverband_examples)
|
257
152
|
|
258
|
-
###
|
153
|
+
### Example Output
|
259
154
|
|
260
|
-
|
261
|
-
|
262
|
-
`rake coverband:coverage`
|
263
|
-
|
264
|
-
This should auto-open in your browser, but if it doesn't the output file should be in `coverage/index.html`
|
265
|
-
|
266
|
-
### Clear Coverage
|
267
|
-
|
268
|
-
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.
|
269
|
-
|
270
|
-
`rake coverband:clear`
|
271
|
-
|
272
|
-
### Automated Clearing Line Coverage Data
|
273
|
-
|
274
|
-
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.
|
275
156
|
|
276
|
-
|
277
|
-
|
278
|
-
you can live with minor inconsistency for some files.
|
157
|
+
Index Page
|
158
|
+
![image](https://raw.github.com/danmayer/coverband/master/docs/coverband_index.png)
|
279
159
|
|
280
|
-
|
160
|
+
Details on a example Sinatra app
|
161
|
+
![image](https://raw.github.com/danmayer/coverband/master/docs/coverband_details.png)
|
281
162
|
|
282
|
-
|
283
|
-
# defaults to the currently configured Coverband.configuration.redis
|
284
|
-
Coverband::Reporter.clear_coverage
|
285
|
-
# or pass in the current target redis
|
286
|
-
Coverband::Reporter.clear_coverage(Redis.new(:host => 'target.com', :port => 6789))
|
287
|
-
```
|
288
|
-
You can also do this with the included rake tasks.
|
163
|
+
### Advanced Coverband Config
|
289
164
|
|
290
|
-
|
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.
|
291
166
|
|
292
|
-
|
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`
|
293
171
|
|
294
|
-
|
172
|
+
Below is an example config file for a Rails 5 app:
|
295
173
|
|
296
174
|
```ruby
|
297
|
-
|
298
|
-
Coverband.configure
|
299
|
-
|
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']
|
300
182
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
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
|
305
188
|
end
|
306
189
|
```
|
307
190
|
|
308
|
-
|
191
|
+
### Writing Coverband Results to S3
|
309
192
|
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
...
|
322
|
-
chain.add Sidekiq::CoverbandMiddleware
|
193
|
+
If you add some additional Coverband configuration your coverage html report will be written directly to S3, update `config/coverband.rb` like below.
|
194
|
+
|
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']
|
323
201
|
```
|
324
202
|
|
325
|
-
|
203
|
+
Alternatively, Coverband if you don't set via the `config.s3_*` accessor methods will look for the standard S3 environment variables.
|
326
204
|
|
205
|
+
```
|
206
|
+
ENV['AWS_BUCKET']
|
207
|
+
ENV['AWS_REGION']
|
208
|
+
ENV['AWS_ACCESS_KEY_ID']
|
209
|
+
ENV['AWS_SECRET_ACCESS_KEY']
|
210
|
+
```
|
327
211
|
|
328
|
-
|
329
|
-
require "coverband"
|
330
|
-
Coverband.configure
|
331
|
-
Coverband.start
|
212
|
+
### Clear Coverage
|
332
213
|
|
333
|
-
|
334
|
-
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.
|
335
215
|
|
336
|
-
|
216
|
+
`rake coverband:clear`
|
337
217
|
|
338
|
-
###
|
218
|
+
### Adding Rake Tasks outside of Rails
|
339
219
|
|
340
|
-
|
220
|
+
Rails apps should automaticallly include the tasks via the Railtie.
|
341
221
|
|
342
|
-
|
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.
|
343
223
|
|
344
|
-
```
|
224
|
+
```ruby
|
345
225
|
require 'coverband'
|
346
226
|
Coverband.configure
|
347
227
|
require 'coverband/utils/tasks'
|
348
|
-
|
349
|
-
# Wrap all Rake tasks with Coverband
|
350
|
-
current_tasks = Rake.application.top_level_tasks
|
351
|
-
if current_tasks.any? && current_tasks.none? { |t| t.to_s.match?(/^coverband:/) }
|
352
|
-
current_tasks.unshift 'coverband:start'
|
353
|
-
current_tasks.push 'coverband:stop_and_save'
|
354
|
-
end
|
355
|
-
|
356
|
-
namespace :coverband do
|
357
|
-
task :start do
|
358
|
-
Coverband.start
|
359
|
-
end
|
360
|
-
|
361
|
-
task :stop_and_save do
|
362
|
-
Coverband::Collectors::Coverage.instance.report_coverage
|
363
|
-
end
|
364
|
-
end
|
365
228
|
```
|
366
229
|
|
367
|
-
|
230
|
+
Verify it works
|
368
231
|
|
369
|
-
```
|
370
|
-
|
371
|
-
|
372
|
-
#
|
373
|
-
class CoverageRunner < ::Rails::Railtie
|
374
|
-
runner do
|
375
|
-
Coverband.start
|
376
|
-
at_exit do
|
377
|
-
Coverband::Collectors::Coverage.instance.report_coverage
|
378
|
-
end
|
379
|
-
end
|
380
|
-
end
|
232
|
+
```bash
|
233
|
+
rake -T coverband
|
234
|
+
rake coverband:clear # reset coverband coverage data
|
235
|
+
rake coverband:coverage # report runtime coverband code coverage
|
381
236
|
```
|
382
237
|
|
383
|
-
###
|
238
|
+
### Forcing Coverband to Track Coverage on files loaded during boot `safe_reload_files`
|
384
239
|
|
385
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.
|
386
241
|
|
@@ -400,20 +255,18 @@ By adding any files above you will get reporting on those files as part of your
|
|
400
255
|
|
401
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).
|
402
257
|
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
*
|
407
|
-
|
408
|
-
*
|
409
|
-
*
|
410
|
-
* while possible this is currently hard as Rails and most environments load your whole Gemfile
|
411
|
-
* 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.
|
412
265
|
|
413
266
|
|
414
267
|
### Verbose Debug / Development Mode
|
415
268
|
|
416
|
-
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.
|
417
270
|
|
418
271
|
---
|
419
272
|
|
@@ -435,57 +288,6 @@ If you are trying to debug locally wondering what code is being run during a req
|
|
435
288
|
...
|
436
289
|
[517, 1617], [516, 38577]]
|
437
290
|
|
438
|
-
### Writing Coverband Results to S3
|
439
|
-
|
440
|
-
If you add some additional Coverband configuration your coverage html report will be written directly to S3, update `config/coverband.rb` like below.
|
441
|
-
|
442
|
-
```
|
443
|
-
# configure S3 integration
|
444
|
-
config.s3_bucket = 'coverband-demo'
|
445
|
-
config.s3_region = 'us-east-1'
|
446
|
-
config.s3_access_key_id = ENV['AWS_ACCESS_KEY_ID']
|
447
|
-
config.s3_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
|
448
|
-
```
|
449
|
-
|
450
|
-
### Viewing / Hosting S3 Coverband results in app
|
451
|
-
|
452
|
-
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`
|
453
|
-
|
454
|
-
```
|
455
|
-
Rails.application.routes.draw do
|
456
|
-
# ... lots of routes
|
457
|
-
mount Coverband::Reporters::Web.new, at: '/coverage'
|
458
|
-
end
|
459
|
-
```
|
460
|
-
|
461
|
-
__NOTE__: ADD PASSWORD PROTECTION OR YOU CAN EXPOSE ALL YOUR SOURCE CODE
|
462
|
-
|
463
|
-
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.
|
464
|
-
|
465
|
-
```
|
466
|
-
# protect with existing Rails devise configuration
|
467
|
-
devise_constraint = lambda do |request|
|
468
|
-
request.env['warden'] && request.env['warden'].authenticate? && request.env['warden'].user.admin?
|
469
|
-
end
|
470
|
-
|
471
|
-
# protect with http basic auth
|
472
|
-
# curl --user foo:bar http://localhost:3000/coverage
|
473
|
-
Rails.application.routes.draw do
|
474
|
-
# ... lots of routes
|
475
|
-
|
476
|
-
# Create a Rack wrapper around the Coverband Web Reporter to support & prompt the user for basic authentication.
|
477
|
-
AuthenticatedCoverband = Rack::Builder.new do
|
478
|
-
use Rack::Auth::Basic do |username, password|
|
479
|
-
username == 'foo' && password == 'bar'
|
480
|
-
end
|
481
|
-
|
482
|
-
run Coverband::Reporters::Web.new
|
483
|
-
end
|
484
|
-
|
485
|
-
# Connect the wrapper app to your desired endpoint.
|
486
|
-
mount AuthenticatedCoverband, at: '/coverage'
|
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.
|
@@ -536,7 +343,7 @@ If you submit a change please make sure the tests and benchmarks are passing.
|
|
536
343
|
### Known Issues
|
537
344
|
|
538
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.
|
539
|
-
* 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
|
540
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.
|
541
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.
|
542
349
|
|