coverband 4.0.0 → 4.0.1.alpha
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +0 -4
- data/changes.md +57 -52
- data/coverband.gemspec +3 -5
- data/lib/coverband.rb +6 -1
- data/lib/coverband/reporters/html_report.rb +36 -0
- data/lib/coverband/reporters/web.rb +16 -13
- data/lib/coverband/utils/file_list.rb +68 -0
- data/lib/coverband/utils/html_formatter.rb +119 -0
- data/lib/coverband/utils/lines_classifier.rb +54 -0
- data/lib/coverband/utils/result.rb +108 -0
- data/lib/coverband/utils/s3_report.rb +2 -4
- data/lib/coverband/utils/source_file.rb +208 -0
- data/lib/coverband/utils/tasks.rb +2 -6
- data/lib/coverband/version.rb +1 -1
- data/public/application.css +799 -0
- data/public/application.js +1708 -0
- data/public/colorbox/border.png +0 -0
- data/public/colorbox/controls.png +0 -0
- data/public/colorbox/loading.gif +0 -0
- data/public/colorbox/loading_background.png +0 -0
- data/public/favicon_green.png +0 -0
- data/public/favicon_red.png +0 -0
- data/public/favicon_yellow.png +0 -0
- data/public/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/public/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/public/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/public/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/public/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/public/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/public/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/public/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/public/images/ui-icons_222222_256x240.png +0 -0
- data/public/images/ui-icons_2e83ff_256x240.png +0 -0
- data/public/images/ui-icons_454545_256x240.png +0 -0
- data/public/images/ui-icons_888888_256x240.png +0 -0
- data/public/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/public/loading.gif +0 -0
- data/public/magnify.png +0 -0
- data/test/unit/full_stack_test.rb +2 -2
- data/test/unit/reports_console_test.rb +1 -1
- data/test/unit/{reports_simple_cov_test.rb → reports_html_test.rb} +4 -7
- data/test/unit/reports_web_test.rb +3 -4
- data/test/unit/utils_s3_report_test.rb +1 -3
- data/views/file_list.erb +45 -0
- data/views/layout.erb +39 -0
- data/views/source_file.erb +23 -0
- metadata +49 -17
- data/lib/coverband/reporters/simple_cov_report.rb +0 -45
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b703432acb6be1cb77cb0e34fd86bc8e0480463d94a9bdb45f20e66ba34e75f1
|
4
|
+
data.tar.gz: 43c3afcd4f7287463218f53591ebf6182ab1b27a38e3c211663e9b906af39e6b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ddcd44028f889ec0521929a3df8e316a9f66468dbff070a9be8d4a5a80242caf643ea8129eca6bb3affbad07ae500068348a155047af67081a3e5561418ff03
|
7
|
+
data.tar.gz: 18b93fa61005315692a8ed102deb4143778dbc8560e99bbcc0dc0a08b3ccd7919209444b567c10600d165aca9ee36306357d769175fd9a323f2f248c9cc09e01
|
data/.rubocop.yml
CHANGED
@@ -50,10 +50,6 @@ Style/NumericLiteralPrefix:
|
|
50
50
|
Enabled: false
|
51
51
|
Style/ClassAndModuleChildren:
|
52
52
|
Enabled: false
|
53
|
-
Style/MethodMissingSuper:
|
54
|
-
Enabled: true
|
55
|
-
Style/MissingRespondToMissing:
|
56
|
-
Enabled: false
|
57
53
|
Performance/Casecmp:
|
58
54
|
Enabled: false
|
59
55
|
Layout/EmptyLinesAroundArguments:
|
data/changes.md
CHANGED
@@ -2,11 +2,10 @@
|
|
2
2
|
|
3
3
|
### Research Alternative Redis formats
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
5
|
+
- Look at alternative storage formats for Redis
|
6
|
+
- [redis bitmaps](http://blog.getspool.com/2011/11/29/fast-easy-realtime-metrics-using-redis-bitmaps/)
|
7
|
+
- [redis bitfield](https://stackoverflow.com/questions/47100606/optimal-way-to-store-array-of-integers-in-redis-database)
|
8
|
+
- Add support for [zadd](http://redis.io/topics/data-types-intro) so one could determine single call versus multiple calls on a line, letting us determine the most executed code in production.
|
10
9
|
|
11
10
|
### Coverband 4.X
|
12
11
|
|
@@ -29,14 +28,14 @@ Will be the fully modern release that drops maintenance legacy support in favor
|
|
29
28
|
- lists current config options
|
30
29
|
- eventually allow updating remote config
|
31
30
|
- full theming
|
32
|
-
- list redis data dump for debugging
|
31
|
+
- list redis data dump for debugging
|
33
32
|
- additional adapters: Memcache, S3, and ActiveRecord
|
34
33
|
- add articles / podcasts like prontos readme https://github.com/prontolabs/pronto
|
35
34
|
- Add detailed Gem usage report, if we collect and send gem usage we can give percentage of gem code used, which should help application developers know when to remove gem dependencies (0%) or perhaps inline single methods for little usage (using <= 5%) for example.
|
36
35
|
- add additional config / protection options on Coverage clear
|
37
36
|
- add meta data information first seen last recorded to the coverage report views (probably need to drop simplecov for that).
|
38
|
-
|
39
|
-
- Make good video on setup, install, usage
|
37
|
+
- more details in this issue: https://github.com/danmayer/coverband/issues/118
|
38
|
+
- Make good video on setup, install, usage
|
40
39
|
|
41
40
|
### Coverband_jam_session
|
42
41
|
|
@@ -48,8 +47,8 @@ Feature Ideas:
|
|
48
47
|
- move to SimpleCov console out, or make similar console tabular output
|
49
48
|
- Possibly add ability to record code run for a given route
|
50
49
|
- integrate recording with deploy tag or deploy timestamp
|
51
|
-
|
52
|
-
|
50
|
+
- diff code usage across deployed versions
|
51
|
+
- what methods increased usage or decreased
|
53
52
|
- Improve client code api, around manual usage of sampling (like event usage)
|
54
53
|
- ability to change the Coverband config at runtime by changing the config pushed to the Redis hash. In memory cache around the changes to only make that call periodically.
|
55
54
|
- Opposed to just showing code usage on a route allow 'tagging' events which would record line coverage for that tag (this would allow tagging all code that modified an ActiveRecord model for example
|
@@ -59,23 +58,30 @@ Feature Ideas:
|
|
59
58
|
- allow only to collect coverage based on route (limiting or scoped coverage)
|
60
59
|
- coverage over some other variable like a set of alpha users
|
61
60
|
- document how to use this on staging / selenium test suite runs
|
62
|
-
|
61
|
+
- possible add API to pull report at end of run
|
63
62
|
|
64
63
|
# Alpha
|
65
64
|
|
66
|
-
### Coverband 4.0.
|
65
|
+
### Coverband 4.0.1.alpha
|
67
66
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
* Resolves issue requiring submitting initial coverage data pre-fork
|
72
|
-
* Simplified setup with just works sensible defaults for configuration out of the box
|
73
|
-
* Fixes on the pilot release of background reporting in 3.0.1
|
74
|
-
* Rake tasks automatically configured
|
75
|
-
* Updated and simplified documentation
|
67
|
+
- drops simplecov runtime dependency
|
68
|
+
- still used to measure our own code coverage ;)
|
69
|
+
- thanks SimpleCov for all the years of solid HTML reporting, and support!
|
76
70
|
|
77
71
|
# Released
|
78
72
|
|
73
|
+
### Coverband 4.0.0
|
74
|
+
|
75
|
+
- Add support for Railties integration
|
76
|
+
- Reduce configuration options
|
77
|
+
- Default to background reporting vs middleware reporting
|
78
|
+
- Resolves issue requiring submitting initial coverage data pre-fork
|
79
|
+
- Simplified setup with just works sensible defaults for configuration out of the box
|
80
|
+
- Fixes on the pilot release of background reporting in 3.0.1
|
81
|
+
- Rake tasks automatically configured
|
82
|
+
- Updated and simplified documentation
|
83
|
+
- Thanks to Kbaum for all the extensive feedback on the PR
|
84
|
+
|
79
85
|
### Coverband 3.X
|
80
86
|
|
81
87
|
Will be a stable and fast release that drops maintenance legacy support in favor of increased performance and maintainability.
|
@@ -86,50 +92,49 @@ Will be a stable and fast release that drops maintenance legacy support in favor
|
|
86
92
|
- drop collectors adapter
|
87
93
|
- reduced configuration options
|
88
94
|
- add memory benchmarks showing memory overhead of coverband
|
89
|
-
- use full stack tests to prove no memory leaks when used in Rails
|
95
|
+
- use full stack tests to prove no memory leaks when used in Rails
|
90
96
|
|
91
97
|
### Coverband 3.0.1
|
92
98
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
99
|
+
- update documentation around verification steps (https://github.com/danmayer/coverband/issues/135), thanks @kbaum
|
100
|
+
- resolve coverage drift issue, https://github.com/danmayer/coverband/issues/118, thanks for MD5 hash ideas @dnasseri and @kbaum
|
101
|
+
- first version of background thread coverage reporting https://github.com/danmayer/coverband/pull/138, thanks @kbaum
|
102
|
+
- auto-detection of Rack & Rails thanks @kbaum
|
103
|
+
- improved tests allowing exceptions to raise in tests @kbaum
|
104
|
+
- add support for both aws-sdk 1.x and 2.x thanks @jared
|
105
|
+
- adds memory test ensuring no memory leaks
|
106
|
+
- full stack Rails tests for Rails 4 and 5 thanks @kbaum
|
101
107
|
|
102
108
|
### Coverband 3.0.0
|
103
109
|
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
110
|
+
- drops Tracepoint
|
111
|
+
- drops Ruby <= 2.3.0
|
112
|
+
- drops JSON Gem dependency
|
113
|
+
- drops various other features not needed without Tracepoint
|
114
|
+
- memory cache, sampling, restricted to app folders, etc
|
115
|
+
- standardizes on Coverage array format vs sparse hash
|
116
|
+
- rewrites store methods, for 60X perf
|
117
|
+
- implemented for Redis and File store
|
118
|
+
- improved mountable web interface
|
114
119
|
|
115
120
|
# 2.0.3
|
116
121
|
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
122
|
+
- don''t include docs in the gemfile thanks @bquorning
|
123
|
+
- pipeline_redis to reduce network overhead thanks @Kallin
|
124
|
+
- various additional benchmarks @danmayer
|
125
|
+
- Filter out files with no coverage thanks @kbaum
|
121
126
|
|
122
127
|
### 2.0.2
|
123
128
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
- fix possible nil error on files that changed since initial recording @viktor-silakov
|
130
|
+
- add improve error logging in verbose mode (stacktrace) @viktor-silakov
|
131
|
+
- improved logging level support @viktor-silakov
|
132
|
+
- launch Coverband demo and integrate into Readme / Documentation
|
133
|
+
- fix on baseline to show an issue by @viktor-silakov
|
134
|
+
- remove all coverband:baseline related features and documentation
|
135
|
+
- dropped Sinatra requirement for web mountable page
|
136
|
+
- fix on filestore by @danrabinowitz
|
137
|
+
- fixes to the MemoryCacheStore by @kbaum
|
133
138
|
|
134
139
|
### 2.0.1
|
135
140
|
|
data/coverband.gemspec
CHANGED
@@ -31,9 +31,11 @@ Gem::Specification.new do |spec|
|
|
31
31
|
spec.add_development_dependency 'rack'
|
32
32
|
spec.add_development_dependency 'rack-test'
|
33
33
|
spec.add_development_dependency 'rake'
|
34
|
+
spec.add_development_dependency 'simplecov'
|
34
35
|
spec.add_development_dependency 'test-unit'
|
35
36
|
|
36
|
-
# used for benchmarking and tests
|
37
|
+
# TODO: used for benchmarking and tests I think we have other better benchmarking
|
38
|
+
# perhaps time to drop this and refactor.
|
37
39
|
spec.add_development_dependency 'classifier-reborn'
|
38
40
|
# add when debugging
|
39
41
|
# require 'byebug'; byebug
|
@@ -45,8 +47,4 @@ Gem::Specification.new do |spec|
|
|
45
47
|
# quality adapter, I think this is more honest about requirements and reduces confusion
|
46
48
|
# without this there was a race condition on calling coverband configure before redis was loaded
|
47
49
|
spec.add_runtime_dependency 'redis'
|
48
|
-
# TODO: make an optional dependency for simplecov reports
|
49
|
-
# also likely should just require simplecov-html not the whole lib
|
50
|
-
# I tried this but it was harder than I thought
|
51
|
-
spec.add_runtime_dependency 'simplecov', '> 0.11.1'
|
52
50
|
end
|
data/lib/coverband.rb
CHANGED
@@ -10,10 +10,15 @@ require 'coverband/adapters/base'
|
|
10
10
|
require 'coverband/adapters/redis_store'
|
11
11
|
require 'coverband/adapters/file_store'
|
12
12
|
require 'coverband/utils/s3_report'
|
13
|
+
require 'coverband/utils/html_formatter'
|
14
|
+
require 'coverband/utils/result'
|
15
|
+
require 'coverband/utils/file_list'
|
16
|
+
require 'coverband/utils/source_file'
|
17
|
+
require 'coverband/utils/lines_classifier'
|
13
18
|
require 'coverband/utils/railtie' if defined? ::Rails::Railtie
|
14
19
|
require 'coverband/collectors/coverage'
|
15
20
|
require 'coverband/reporters/base'
|
16
|
-
require 'coverband/reporters/
|
21
|
+
require 'coverband/reporters/html_report'
|
17
22
|
require 'coverband/reporters/console_report'
|
18
23
|
require 'coverband/integrations/background'
|
19
24
|
require 'coverband/integrations/rack_server_check'
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Coverband
|
4
|
+
module Reporters
|
5
|
+
class HTMLReport < Base
|
6
|
+
def self.report(store, options = {})
|
7
|
+
scov_style_report = super(store, options)
|
8
|
+
open_report = options.fetch(:open_report) { true }
|
9
|
+
html = options.fetch(:html) { false }
|
10
|
+
|
11
|
+
# list all files, even if not tracked by Coverband (0% coverage)
|
12
|
+
tracked_glob = "#{current_root}/{app,lib,config}/**/*.{rb}"
|
13
|
+
report_files = Coverband::Utils::Result.add_not_loaded_files(scov_style_report, tracked_glob)
|
14
|
+
# apply coverband filters
|
15
|
+
filtered_report_files = {}
|
16
|
+
report_files.each_pair do |file, data|
|
17
|
+
next if Coverband.configuration.ignore.any? { |i| file.match(i) }
|
18
|
+
filtered_report_files[file] = data
|
19
|
+
end
|
20
|
+
|
21
|
+
if html
|
22
|
+
Coverband::Utils::HTMLFormatter.new(filtered_report_files).format_html!
|
23
|
+
else
|
24
|
+
Coverband::Utils::HTMLFormatter.new(filtered_report_files).format!
|
25
|
+
if open_report
|
26
|
+
`open #{Coverband.configuration.root}/coverage/index.html`
|
27
|
+
else
|
28
|
+
Coverband.configuration.logger.info 'report is ready and viewable: open coverage/index.html'
|
29
|
+
end
|
30
|
+
|
31
|
+
Coverband::Utils::S3Report.instance.persist! if Coverband.configuration.s3_bucket
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -9,7 +9,7 @@ module Coverband
|
|
9
9
|
attr_reader :request
|
10
10
|
|
11
11
|
def initialize
|
12
|
-
full_path = Gem::Specification.find_by_name('
|
12
|
+
full_path = Gem::Specification.find_by_name('coverband').full_gem_path
|
13
13
|
@static = Rack::Static.new(self,
|
14
14
|
root: File.expand_path('public', full_path),
|
15
15
|
urls: [/.*\.css/, /.*\.js/, /.*\.gif/, /.*\.png/])
|
@@ -71,13 +71,9 @@ module Coverband
|
|
71
71
|
end
|
72
72
|
|
73
73
|
def show
|
74
|
-
html = Coverband::
|
75
|
-
|
76
|
-
html
|
77
|
-
html = html.gsub("href='", "href='#{base_path}")
|
78
|
-
html = html.gsub('loading.gif', "#{base_path}loading.gif")
|
79
|
-
html = html.gsub('/images/', "#{base_path}images/")
|
80
|
-
html
|
74
|
+
html = Coverband::Reporters::HTMLReport.report(Coverband.configuration.store,
|
75
|
+
html: true, open_report: false)
|
76
|
+
fix_html_paths(html)
|
81
77
|
end
|
82
78
|
|
83
79
|
def collect_update_and_view
|
@@ -87,7 +83,7 @@ module Coverband
|
|
87
83
|
end
|
88
84
|
|
89
85
|
def update_report
|
90
|
-
Coverband::Reporters::
|
86
|
+
Coverband::Reporters::HTMLReport.report(Coverband.configuration.store, open_report: false)
|
91
87
|
notice = 'coverband coverage updated'
|
92
88
|
[301, { 'Location' => "#{base_path}?notice=#{notice}" }, []]
|
93
89
|
end
|
@@ -105,10 +101,8 @@ module Coverband
|
|
105
101
|
end
|
106
102
|
|
107
103
|
def reload_files
|
108
|
-
|
109
|
-
|
110
|
-
load safe_file
|
111
|
-
end
|
104
|
+
Coverband.configuration&.safe_reload_files&.each do |safe_file|
|
105
|
+
load safe_file
|
112
106
|
end
|
113
107
|
# force reload
|
114
108
|
Coverband.configure
|
@@ -118,6 +112,15 @@ module Coverband
|
|
118
112
|
|
119
113
|
private
|
120
114
|
|
115
|
+
def fix_html_paths(html)
|
116
|
+
# HACK: the static HTML assets to link to the path where this was mounted
|
117
|
+
html = html.gsub("src='", "src='#{base_path}")
|
118
|
+
html = html.gsub("href='", "href='#{base_path}")
|
119
|
+
html = html.gsub('loading.gif', "#{base_path}loading.gif")
|
120
|
+
html = html.gsub('/images/', "#{base_path}images/")
|
121
|
+
html.gsub("./assets/#{Coverband::VERSION}/", '')
|
122
|
+
end
|
123
|
+
|
121
124
|
def button(url, title)
|
122
125
|
button = "<form action='#{url}' method='post'>"
|
123
126
|
button += "<button type='submit'>#{title}</button>"
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
####
|
4
|
+
# Thanks for all the help SimpleCov https://github.com/colszowka/simplecov
|
5
|
+
# initial version pulled into Coverband from Simplecov 12/04/2018
|
6
|
+
#
|
7
|
+
# An array of SourceFile instances with additional collection helper
|
8
|
+
# methods for calculating coverage across them etc.
|
9
|
+
####
|
10
|
+
module Coverband
|
11
|
+
module Utils
|
12
|
+
class FileList < Array
|
13
|
+
# Returns the count of lines that have coverage
|
14
|
+
def covered_lines
|
15
|
+
return 0.0 if empty?
|
16
|
+
map { |f| f.covered_lines.count }.inject(:+)
|
17
|
+
end
|
18
|
+
|
19
|
+
# Returns the count of lines that have been missed
|
20
|
+
def missed_lines
|
21
|
+
return 0.0 if empty?
|
22
|
+
map { |f| f.missed_lines.count }.inject(:+)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Returns the count of lines that are not relevant for coverage
|
26
|
+
def never_lines
|
27
|
+
return 0.0 if empty?
|
28
|
+
map { |f| f.never_lines.count }.inject(:+)
|
29
|
+
end
|
30
|
+
|
31
|
+
# Returns the count of skipped lines
|
32
|
+
def skipped_lines
|
33
|
+
return 0.0 if empty?
|
34
|
+
map { |f| f.skipped_lines.count }.inject(:+)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Computes the coverage based upon lines covered and lines missed for each file
|
38
|
+
# Returns an array with all coverage percentages
|
39
|
+
def covered_percentages
|
40
|
+
map(&:covered_percent)
|
41
|
+
end
|
42
|
+
|
43
|
+
# Finds the least covered file and returns that file's name
|
44
|
+
def least_covered_file
|
45
|
+
sort_by(&:covered_percent).first.filename
|
46
|
+
end
|
47
|
+
|
48
|
+
# Returns the overall amount of relevant lines of code across all files in this list
|
49
|
+
def lines_of_code
|
50
|
+
covered_lines + missed_lines
|
51
|
+
end
|
52
|
+
|
53
|
+
# Computes the coverage based upon lines covered and lines missed
|
54
|
+
# @return [Float]
|
55
|
+
def covered_percent
|
56
|
+
return 100.0 if empty? || lines_of_code.zero?
|
57
|
+
Float(covered_lines * 100.0 / lines_of_code)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Computes the strength (hits / line) based upon lines covered and lines missed
|
61
|
+
# @return [Float]
|
62
|
+
def covered_strength
|
63
|
+
return 0.0 if empty? || lines_of_code.zero?
|
64
|
+
Float(map { |f| f.covered_strength * f.lines_of_code }.inject(:+) / lines_of_code)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
require 'cgi'
|
5
|
+
require 'fileutils'
|
6
|
+
require 'digest/sha1'
|
7
|
+
require 'time'
|
8
|
+
|
9
|
+
####
|
10
|
+
# Thanks for all the help SimpleCov https://github.com/colszowka/simplecov-html
|
11
|
+
# initial version pulled into Coverband from Simplecov 12/04/2018
|
12
|
+
####
|
13
|
+
module Coverband
|
14
|
+
module Utils
|
15
|
+
class HTMLFormatter
|
16
|
+
def initialize(report)
|
17
|
+
@coverage_result = Coverband::Utils::Result.new(report)
|
18
|
+
end
|
19
|
+
|
20
|
+
def format!
|
21
|
+
format(@coverage_result)
|
22
|
+
end
|
23
|
+
|
24
|
+
def format_html!
|
25
|
+
format_html(@coverage_result)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def format(result)
|
31
|
+
Dir[File.join(File.dirname(__FILE__), '../../../public/*')].each do |path|
|
32
|
+
FileUtils.cp_r(path, asset_output_path)
|
33
|
+
end
|
34
|
+
|
35
|
+
File.open(File.join(output_path, 'index.html'), 'wb') do |file|
|
36
|
+
file.puts template('layout').result(binding)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def format_html(result)
|
41
|
+
template('layout').result(binding)
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns the an erb instance for the template of given name
|
45
|
+
def template(name)
|
46
|
+
ERB.new(File.read(File.join(File.dirname(__FILE__), '../../../views/', "#{name}.erb")))
|
47
|
+
end
|
48
|
+
|
49
|
+
def output_path
|
50
|
+
"#{File.expand_path(Coverband.configuration.root)}/coverage"
|
51
|
+
end
|
52
|
+
|
53
|
+
def asset_output_path
|
54
|
+
return @asset_output_path if defined?(@asset_output_path) && @asset_output_path
|
55
|
+
@asset_output_path = File.join(output_path, 'assets', Coverband::VERSION)
|
56
|
+
FileUtils.mkdir_p(@asset_output_path)
|
57
|
+
@asset_output_path
|
58
|
+
end
|
59
|
+
|
60
|
+
def assets_path(name)
|
61
|
+
File.join('./assets', Coverband::VERSION, name)
|
62
|
+
end
|
63
|
+
|
64
|
+
# Returns the html for the given source_file
|
65
|
+
def formatted_source_file(source_file)
|
66
|
+
template('source_file').result(binding)
|
67
|
+
rescue Encoding::CompatibilityError => e
|
68
|
+
puts "Encoding problems with file #{source_file.filename}. Coverband/ERB can't handle non ASCII characters in filenames. Error: #{e.message}."
|
69
|
+
end
|
70
|
+
|
71
|
+
# Returns a table containing the given source files
|
72
|
+
def formatted_file_list(title, source_files)
|
73
|
+
title_id = title.gsub(/^[^a-zA-Z]+/, '').gsub(/[^a-zA-Z0-9\-\_]/, '')
|
74
|
+
# Silence a warning by using the following variable to assign to itself:
|
75
|
+
# "warning: possibly useless use of a variable in void context"
|
76
|
+
# The variable is used by ERB via binding.
|
77
|
+
title_id = title_id
|
78
|
+
template('file_list').result(binding)
|
79
|
+
end
|
80
|
+
|
81
|
+
def coverage_css_class(covered_percent)
|
82
|
+
if covered_percent > 90
|
83
|
+
'green'
|
84
|
+
elsif covered_percent > 80
|
85
|
+
'yellow'
|
86
|
+
else
|
87
|
+
'red'
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def strength_css_class(covered_strength)
|
92
|
+
if covered_strength > 1
|
93
|
+
'green'
|
94
|
+
elsif covered_strength == 1
|
95
|
+
'yellow'
|
96
|
+
else
|
97
|
+
'red'
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
# Return a (kind of) unique id for the source file given. Uses SHA1 on path for the id
|
102
|
+
def id(source_file)
|
103
|
+
Digest::SHA1.hexdigest(source_file.filename)
|
104
|
+
end
|
105
|
+
|
106
|
+
def timeago(time)
|
107
|
+
"<abbr class=\"timeago\" title=\"#{time.iso8601}\">#{time.iso8601}</abbr>"
|
108
|
+
end
|
109
|
+
|
110
|
+
def shortened_filename(source_file)
|
111
|
+
source_file.filename.sub(Coverband.configuration.root, '.').gsub(/^\.\//, '')
|
112
|
+
end
|
113
|
+
|
114
|
+
def link_to_source_file(source_file)
|
115
|
+
%(<a href="##{id source_file}" class="src_link" title="#{shortened_filename source_file}">#{shortened_filename source_file}</a>)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|