coverband 4.2.7 → 5.0.0.rc.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.standard.yml +25 -0
- data/.travis.yml +2 -1
- data/Gemfile +5 -7
- data/Gemfile.rails4 +0 -3
- data/Gemfile.rails6 +0 -3
- data/README.md +8 -77
- data/Rakefile +17 -17
- data/changes.md +18 -27
- data/config.ru +1 -1
- data/coverband.gemspec +29 -34
- data/lib/coverband.rb +55 -43
- data/lib/coverband/adapters/base.rb +17 -17
- data/lib/coverband/adapters/file_store.rb +2 -2
- data/lib/coverband/adapters/hash_redis_store.rb +24 -21
- data/lib/coverband/adapters/redis_store.rb +12 -12
- data/lib/coverband/at_exit.rb +1 -1
- data/lib/coverband/collectors/coverage.rb +15 -27
- data/lib/coverband/collectors/delta.rb +19 -9
- data/lib/coverband/collectors/view_tracker.rb +10 -10
- data/lib/coverband/configuration.rb +47 -83
- data/lib/coverband/integrations/background.rb +3 -3
- data/lib/coverband/integrations/rack_server_check.rb +3 -3
- data/lib/coverband/reporters/base.rb +10 -10
- data/lib/coverband/reporters/console_report.rb +1 -1
- data/lib/coverband/reporters/html_report.rb +10 -30
- data/lib/coverband/reporters/web.rb +56 -49
- data/lib/coverband/utils/absolute_file_converter.rb +6 -6
- data/lib/coverband/utils/html_formatter.rb +32 -61
- data/lib/coverband/utils/railtie.rb +16 -4
- data/lib/coverband/utils/relative_file_converter.rb +2 -2
- data/lib/coverband/utils/result.rb +6 -11
- data/lib/coverband/utils/results.rb +0 -10
- data/lib/coverband/utils/source_file.rb +21 -30
- data/lib/coverband/utils/tasks.rb +7 -11
- data/lib/coverband/version.rb +1 -1
- data/public/application.js +0 -30
- data/test/benchmarks/benchmark.rake +97 -92
- data/test/benchmarks/dog.rb +1 -1
- data/test/benchmarks/init_rails.rake +4 -4
- data/test/coverband/adapters/base_test.rb +29 -30
- data/test/coverband/adapters/file_store_test.rb +15 -16
- data/test/coverband/adapters/hash_redis_store_test.rb +57 -57
- data/test/coverband/adapters/redis_store_test.rb +26 -26
- data/test/coverband/at_exit_test.rb +2 -2
- data/test/coverband/collectors/coverage_test.rb +33 -47
- data/test/coverband/collectors/delta_test.rb +51 -23
- data/test/coverband/collectors/view_tracker_test.rb +35 -35
- data/test/coverband/configuration_test.rb +15 -41
- data/test/coverband/coverband_test.rb +11 -11
- data/test/coverband/integrations/background_middleware_test.rb +10 -10
- data/test/coverband/integrations/background_test.rb +3 -2
- data/test/coverband/integrations/rack_server_check_test.rb +7 -7
- data/test/coverband/integrations/report_middleware_test.rb +9 -9
- data/test/coverband/integrations/resque_worker_test.rb +9 -9
- data/test/coverband/integrations/test_resque_job.rb +1 -1
- data/test/coverband/reporters/base_test.rb +9 -9
- data/test/coverband/reporters/console_test.rb +6 -6
- data/test/coverband/reporters/html_test.rb +36 -48
- data/test/coverband/reporters/web_test.rb +16 -18
- data/test/coverband/utils/absolute_file_converter_test.rb +22 -22
- data/test/coverband/utils/file_hasher_test.rb +6 -12
- data/test/coverband/utils/file_list_test.rb +13 -13
- data/test/coverband/utils/html_formatter_test.rb +9 -23
- data/test/coverband/utils/lines_classifier_test.rb +29 -29
- data/test/coverband/utils/relative_file_converter_test.rb +13 -13
- data/test/coverband/utils/result_test.rb +18 -18
- data/test/coverband/utils/results_test.rb +17 -17
- data/test/coverband/utils/source_file_line_test.rb +46 -46
- data/test/coverband/utils/source_file_test.rb +38 -88
- data/test/dog.rb +1 -1
- data/test/fake_app/basic_rack.rb +2 -2
- data/test/fixtures/app/controllers/sample_controller.rb +1 -1
- data/test/fixtures/app/models/user.rb +1 -1
- data/test/fixtures/sample.rb +1 -1
- data/test/fixtures/utf-8.rb +0 -2
- data/test/forked/rails_full_stack_test.rb +24 -27
- data/test/forked/rails_rake_full_stack_test.rb +7 -26
- data/test/integration/full_stack_test.rb +11 -22
- data/test/jruby_check.rb +2 -3
- data/test/rails4_dummy/Rakefile +1 -1
- data/test/rails4_dummy/config.ru +1 -1
- data/test/rails4_dummy/config/application.rb +4 -4
- data/test/rails4_dummy/config/boot.rb +2 -2
- data/test/rails4_dummy/config/coverband.rb +1 -1
- data/test/rails4_dummy/config/coverband_missing_redis.rb +1 -1
- data/test/rails4_dummy/config/environment.rb +1 -1
- data/test/rails4_dummy/config/routes.rb +2 -2
- data/test/rails5_dummy/Rakefile +1 -1
- data/test/rails5_dummy/config.ru +1 -1
- data/test/rails5_dummy/config/application.rb +3 -3
- data/test/rails5_dummy/config/coverband.rb +8 -8
- data/test/rails5_dummy/config/coverband_missing_redis.rb +8 -8
- data/test/rails5_dummy/config/environment.rb +1 -1
- data/test/rails5_dummy/config/routes.rb +2 -2
- data/test/rails6_dummy/Rakefile +1 -1
- data/test/rails6_dummy/config.ru +1 -1
- data/test/rails6_dummy/config/application.rb +4 -4
- data/test/rails6_dummy/config/boot.rb +2 -2
- data/test/rails6_dummy/config/coverband.rb +1 -1
- data/test/rails6_dummy/config/coverband_missing_redis.rb +1 -1
- data/test/rails6_dummy/config/environment.rb +1 -1
- data/test/rails6_dummy/config/routes.rb +2 -2
- data/test/rails_test_helper.rb +11 -11
- data/test/test_helper.rb +41 -34
- data/test/unique_files.rb +10 -10
- data/views/layout.erb +2 -12
- metadata +6 -45
- data/.rubocop.yml +0 -86
- data/lib/coverband/integrations/bundler.rb +0 -8
- data/lib/coverband/utils/file_groups.rb +0 -53
- data/lib/coverband/utils/gem_list.rb +0 -31
- data/lib/coverband/utils/s3_report.rb +0 -105
- data/test/coverband/utils/file_groups_test.rb +0 -61
- data/test/coverband/utils/gem_list_test.rb +0 -48
- data/test/coverband/utils/s3_report_test.rb +0 -44
- data/views/gem_list.erb +0 -63
@@ -25,9 +25,9 @@ module Coverband
|
|
25
25
|
relative_filename = relative_path
|
26
26
|
local_filename = relative_filename
|
27
27
|
@roots.each do |root|
|
28
|
-
relative_filename = relative_filename.sub(/^#{root}/,
|
28
|
+
relative_filename = relative_filename.sub(/^#{root}/, "./")
|
29
29
|
# once we have a relative path break out of the loop
|
30
|
-
break if relative_filename.start_with?
|
30
|
+
break if relative_filename.start_with? "./"
|
31
31
|
end
|
32
32
|
# the filename for our reports is expected to be a full path.
|
33
33
|
# roots.last should be roots << current_root}/
|
@@ -36,10 +36,10 @@ module Coverband
|
|
36
36
|
# above only works for app files
|
37
37
|
# we need to rethink some of this logic
|
38
38
|
# gems aren't at project root and can have multiple locations
|
39
|
-
local_root = @roots.find
|
40
|
-
File.exist?(relative_filename.gsub(
|
41
|
-
|
42
|
-
local_root ? relative_filename.gsub(
|
39
|
+
local_root = @roots.find { |root|
|
40
|
+
File.exist?(relative_filename.gsub("./", root))
|
41
|
+
}
|
42
|
+
local_root ? relative_filename.gsub("./", local_root) : local_filename
|
43
43
|
end
|
44
44
|
end
|
45
45
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
3
|
+
require "erb"
|
4
|
+
require "cgi"
|
5
|
+
require "fileutils"
|
6
|
+
require "digest/sha1"
|
7
|
+
require "time"
|
8
8
|
|
9
9
|
####
|
10
10
|
# Thanks for all the help SimpleCov https://github.com/colszowka/simplecov-html
|
@@ -17,14 +17,10 @@ module Coverband
|
|
17
17
|
|
18
18
|
def initialize(report, options = {})
|
19
19
|
@notice = options.fetch(:notice) { nil }
|
20
|
-
@base_path = options.fetch(:base_path) {
|
20
|
+
@base_path = options.fetch(:base_path) { "./" }
|
21
21
|
@coverage_result = Coverband::Utils::Results.new(report) if report
|
22
22
|
end
|
23
23
|
|
24
|
-
def format_static_html!
|
25
|
-
format(@coverage_result)
|
26
|
-
end
|
27
|
-
|
28
24
|
def format_dynamic_html!
|
29
25
|
format_html(@coverage_result)
|
30
26
|
end
|
@@ -47,41 +43,41 @@ module Coverband
|
|
47
43
|
if source_file
|
48
44
|
formatted_source_file(@coverage_result, source_file)
|
49
45
|
else
|
50
|
-
|
46
|
+
"File No Longer Available"
|
51
47
|
end
|
52
48
|
end
|
53
49
|
|
54
50
|
private
|
55
51
|
|
56
52
|
def format_settings
|
57
|
-
template(
|
53
|
+
template("settings").result(binding)
|
58
54
|
end
|
59
55
|
|
60
56
|
def format_view_tracker
|
61
|
-
template(
|
57
|
+
template("view_tracker").result(binding)
|
62
58
|
end
|
63
59
|
|
64
60
|
def format(result)
|
65
|
-
Dir[File.join(File.dirname(__FILE__),
|
61
|
+
Dir[File.join(File.dirname(__FILE__), "../../../public/*")].each do |path|
|
66
62
|
FileUtils.cp_r(path, asset_output_path)
|
67
63
|
end
|
68
64
|
|
69
|
-
File.open(File.join(output_path,
|
70
|
-
file.puts template(
|
65
|
+
File.open(File.join(output_path, "index.html"), "wb") do |file|
|
66
|
+
file.puts template("layout").result(binding)
|
71
67
|
end
|
72
68
|
end
|
73
69
|
|
74
70
|
def format_html(result)
|
75
|
-
template(
|
71
|
+
template("layout").result(binding)
|
76
72
|
end
|
77
73
|
|
78
74
|
def format_data(result)
|
79
|
-
template(
|
75
|
+
template("data").result(binding)
|
80
76
|
end
|
81
77
|
|
82
78
|
# Returns the an erb instance for the template of given name
|
83
79
|
def template(name)
|
84
|
-
ERB.new(File.read(File.join(File.dirname(__FILE__),
|
80
|
+
ERB.new(File.read(File.join(File.dirname(__FILE__), "../../../views/", "#{name}.erb")))
|
85
81
|
end
|
86
82
|
|
87
83
|
def output_path
|
@@ -97,90 +93,70 @@ module Coverband
|
|
97
93
|
end
|
98
94
|
|
99
95
|
def served_html?
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
def static_html?
|
104
|
-
base_path.nil?
|
96
|
+
true
|
105
97
|
end
|
106
98
|
|
107
99
|
def assets_path(name)
|
108
|
-
|
109
|
-
File.join(name)
|
110
|
-
else
|
111
|
-
File.join(base_path, name)
|
112
|
-
end
|
100
|
+
File.join(base_path, name)
|
113
101
|
end
|
114
102
|
|
115
103
|
def button(url, title, opts = {})
|
116
104
|
delete = opts.fetch(:delete) { false }
|
117
|
-
button_css = delete ?
|
105
|
+
button_css = delete ? "coveraband-button del" : "coveraband-button"
|
118
106
|
button = "<form action='#{url}' class='coverband-admin-form' method='post'>"
|
119
107
|
button += "<button class='#{button_css}' type='submit'>#{title}</button>"
|
120
|
-
button +
|
108
|
+
button + "</form>"
|
121
109
|
end
|
122
110
|
|
123
111
|
def display_nav(nav_options = {})
|
124
|
-
template(
|
112
|
+
template("nav").result(binding)
|
125
113
|
end
|
126
114
|
|
127
115
|
# Returns the html for the given source_file
|
128
116
|
def formatted_source_file(result, source_file)
|
129
|
-
template(
|
117
|
+
template("source_file").result(binding)
|
130
118
|
rescue Encoding::CompatibilityError => e
|
131
119
|
puts "Encoding error file:#{source_file.filename} Coverband/ERB error #{e.message}."
|
132
120
|
end
|
133
121
|
|
134
122
|
# Returns the html to ajax load a given source_file
|
135
123
|
def formatted_source_file_loader(result, source_file)
|
136
|
-
template(
|
124
|
+
template("source_file_loader").result(binding)
|
137
125
|
rescue Encoding::CompatibilityError => e
|
138
126
|
puts "Encoding error file:#{source_file.filename} Coverband/ERB error #{e.message}."
|
139
127
|
end
|
140
128
|
|
141
129
|
# Returns a table containing the given source files
|
142
130
|
def formatted_file_list(title, result, source_files, options = {})
|
143
|
-
title_id = title.gsub(/^[^a-zA-Z]+/,
|
131
|
+
title_id = title.gsub(/^[^a-zA-Z]+/, "").gsub(/[^a-zA-Z0-9\-\_]/, "")
|
144
132
|
# Silence a warning by using the following variable to assign to itself:
|
145
133
|
# "warning: possibly useless use of a variable in void context"
|
146
134
|
# The variable is used by ERB via binding.
|
147
135
|
title_id = title_id
|
148
136
|
options = options
|
149
137
|
|
150
|
-
|
151
|
-
template('gem_list').result(binding)
|
152
|
-
else
|
153
|
-
template('file_list').result(binding)
|
154
|
-
end
|
155
|
-
end
|
156
|
-
|
157
|
-
def view_gems?
|
158
|
-
Coverband.configuration.track_gems
|
159
|
-
end
|
160
|
-
|
161
|
-
def gem_details?
|
162
|
-
Coverband.configuration.gem_details
|
138
|
+
template("file_list").result(binding)
|
163
139
|
end
|
164
140
|
|
165
141
|
def coverage_css_class(covered_percent)
|
166
142
|
if covered_percent.nil?
|
167
|
-
|
143
|
+
""
|
168
144
|
elsif covered_percent > 90
|
169
|
-
|
145
|
+
"green"
|
170
146
|
elsif covered_percent > 80
|
171
|
-
|
147
|
+
"yellow"
|
172
148
|
else
|
173
|
-
|
149
|
+
"red"
|
174
150
|
end
|
175
151
|
end
|
176
152
|
|
177
153
|
def strength_css_class(covered_strength)
|
178
154
|
if covered_strength > 1
|
179
|
-
|
155
|
+
"green"
|
180
156
|
elsif covered_strength == 1
|
181
|
-
|
157
|
+
"yellow"
|
182
158
|
else
|
183
|
-
|
159
|
+
"red"
|
184
160
|
end
|
185
161
|
end
|
186
162
|
|
@@ -193,7 +169,7 @@ module Coverband
|
|
193
169
|
if time
|
194
170
|
"<abbr class=\"timeago\" title=\"#{time.iso8601}\">#{time.iso8601}</abbr>"
|
195
171
|
else
|
196
|
-
|
172
|
+
"Not Available"
|
197
173
|
end
|
198
174
|
end
|
199
175
|
|
@@ -201,11 +177,6 @@ module Coverband
|
|
201
177
|
source_file.short_name
|
202
178
|
end
|
203
179
|
|
204
|
-
def link_to_gem_list(gem_name)
|
205
|
-
gem_id = gem_name.gsub(/^[^a-zA-Z]+/, '').gsub(/[^a-zA-Z0-9\-\_]/, '')
|
206
|
-
%(<a href="##{gem_id}" class="gem-link" title="#{gem_name}">#{gem_name}</a>)
|
207
|
-
end
|
208
|
-
|
209
180
|
def link_to_source_file(source_file)
|
210
181
|
%(<a href="##{id source_file}" class="src_link" title="#{shortened_filename source_file}">#{shortened_filename source_file}</a>)
|
211
182
|
end
|
@@ -10,7 +10,7 @@ module Coverband
|
|
10
10
|
Rails::Engine.prepend(RailsEagerLoad)
|
11
11
|
|
12
12
|
class Railtie < Rails::Railtie
|
13
|
-
initializer
|
13
|
+
initializer "coverband.configure" do |app|
|
14
14
|
begin
|
15
15
|
app.middleware.use Coverband::BackgroundMiddleware
|
16
16
|
|
@@ -19,12 +19,12 @@ module Coverband
|
|
19
19
|
Coverband.configuration.view_tracker = CoverbandViewTracker
|
20
20
|
|
21
21
|
ActiveSupport::Notifications.subscribe(/render_partial.action_view|render_template.action_view/) do |name, start, finish, id, payload|
|
22
|
-
CoverbandViewTracker.track_views(name, start, finish, id, payload) unless name.include?(
|
22
|
+
CoverbandViewTracker.track_views(name, start, finish, id, payload) unless name.include?("!")
|
23
23
|
end
|
24
24
|
end
|
25
25
|
rescue Redis::CannotConnectError => error
|
26
26
|
Coverband.configuration.logger.info "Redis is not available (#{error}), Coverband not configured"
|
27
|
-
Coverband.configuration.logger.info
|
27
|
+
Coverband.configuration.logger.info "If this is a setup task like assets:precompile feel free to ignore"
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
@@ -36,8 +36,20 @@ module Coverband
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
config.before_configuration do
|
40
|
+
unless ENV["COVERBAND_DISABLE_AUTO_START"]
|
41
|
+
begin
|
42
|
+
Coverband.configure
|
43
|
+
Coverband.start
|
44
|
+
rescue Redis::CannotConnectError => error
|
45
|
+
Coverband.configuration.logger.info "Redis is not available (#{error}), Coverband not configured"
|
46
|
+
Coverband.configuration.logger.info "If this is a setup task like assets:precompile feel free to ignore"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
39
51
|
rake_tasks do
|
40
|
-
load
|
52
|
+
load "coverband/utils/tasks.rb"
|
41
53
|
end
|
42
54
|
end
|
43
55
|
end
|
@@ -24,8 +24,8 @@ module Coverband
|
|
24
24
|
@cache[file] ||= begin
|
25
25
|
relative_file = file
|
26
26
|
@roots.each do |root|
|
27
|
-
relative_file = file.gsub(/^#{root}/,
|
28
|
-
break relative_file if relative_file.start_with?(
|
27
|
+
relative_file = file.gsub(/^#{root}/, ".")
|
28
|
+
break relative_file if relative_file.start_with?(".")
|
29
29
|
end
|
30
30
|
relative_file
|
31
31
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require "digest/sha1"
|
4
|
+
require "forwardable"
|
5
5
|
|
6
6
|
####
|
7
7
|
# Thanks for all the help SimpleCov https://github.com/colszowka/simplecov
|
@@ -31,9 +31,9 @@ module Coverband
|
|
31
31
|
def initialize(original_result)
|
32
32
|
@original_result = (original_result || {}).freeze
|
33
33
|
|
34
|
-
@files = Coverband::Utils::FileList.new(@original_result.map
|
34
|
+
@files = Coverband::Utils::FileList.new(@original_result.map { |filename, coverage|
|
35
35
|
Coverband::Utils::SourceFile.new(filename, coverage) if File.file?(filename)
|
36
|
-
|
36
|
+
}.compact.sort_by(&:short_name))
|
37
37
|
end
|
38
38
|
|
39
39
|
# Returns all filenames for source files contained in this result
|
@@ -41,11 +41,6 @@ module Coverband
|
|
41
41
|
files.map(&:filename)
|
42
42
|
end
|
43
43
|
|
44
|
-
# Returns a Hash of groups for this result. Define groups using Coverband.add_group 'Models', 'app/models'
|
45
|
-
def groups
|
46
|
-
@groups ||= FileGroups.new(files).grouped_results
|
47
|
-
end
|
48
|
-
|
49
44
|
# Defines when this result has been created. Defaults to Time.now
|
50
45
|
def created_at
|
51
46
|
@created_at ||= Time.now
|
@@ -60,8 +55,8 @@ module Coverband
|
|
60
55
|
Dir[tracked_files].each do |file|
|
61
56
|
absolute = File.expand_path(file)
|
62
57
|
result[absolute] ||= {
|
63
|
-
|
64
|
-
|
58
|
+
"data" => Array.new(File.foreach(absolute).count) { 0 },
|
59
|
+
"never_loaded" => true
|
65
60
|
}
|
66
61
|
end
|
67
62
|
end
|
@@ -45,16 +45,6 @@ module Coverband
|
|
45
45
|
eager_file.relevant_lines - eager_file.covered_lines_count
|
46
46
|
end
|
47
47
|
|
48
|
-
###
|
49
|
-
# TODO: Groups still have some issues, this should be generic for groups, but right now gem_name
|
50
|
-
# is specifically called out, need to revisit all gorups code.
|
51
|
-
###
|
52
|
-
def group_file_list_with_type(group, file_list, results_type)
|
53
|
-
return unless get_results(results_type)
|
54
|
-
|
55
|
-
get_results(results_type).groups[group].find { |gem_files| gem_files.first.gem_name == file_list.first.gem_name }
|
56
|
-
end
|
57
|
-
|
58
48
|
def file_from_path_with_type(full_path, results_type = :merged)
|
59
49
|
return unless get_results(results_type)
|
60
50
|
|
@@ -32,14 +32,14 @@ module Coverband
|
|
32
32
|
alias number line_number
|
33
33
|
|
34
34
|
def initialize(src, line_number, coverage)
|
35
|
-
raise ArgumentError,
|
36
|
-
raise ArgumentError,
|
37
|
-
raise ArgumentError,
|
35
|
+
raise ArgumentError, "Only String accepted for source" unless src.is_a?(String)
|
36
|
+
raise ArgumentError, "Only Integer accepted for line_number" unless line_number.is_a?(Integer)
|
37
|
+
raise ArgumentError, "Only Integer and nil accepted for coverage" unless coverage.is_a?(Integer) || coverage.nil?
|
38
38
|
|
39
|
-
@src
|
39
|
+
@src = src
|
40
40
|
@line_number = line_number
|
41
|
-
@coverage
|
42
|
-
@skipped
|
41
|
+
@coverage = coverage
|
42
|
+
@skipped = false
|
43
43
|
end
|
44
44
|
|
45
45
|
# Returns true if this is a line that should have been covered, but was not
|
@@ -71,10 +71,10 @@ module Coverband
|
|
71
71
|
# The status of this line - either covered, missed, skipped or never. Useful i.e. for direct use
|
72
72
|
# as a css class in report generation
|
73
73
|
def status
|
74
|
-
return
|
75
|
-
return
|
76
|
-
return
|
77
|
-
return
|
74
|
+
return "skipped" if skipped?
|
75
|
+
return "never" if never?
|
76
|
+
return "missed" if missed?
|
77
|
+
return "covered" if covered?
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
@@ -89,17 +89,17 @@ module Coverband
|
|
89
89
|
attr_reader :last_updated_at
|
90
90
|
# meta data that the file was never loaded during boot or runtime
|
91
91
|
attr_reader :never_loaded
|
92
|
-
NOT_AVAILABLE =
|
92
|
+
NOT_AVAILABLE = "not available"
|
93
93
|
|
94
94
|
def initialize(filename, file_data)
|
95
95
|
@filename = filename
|
96
96
|
@runtime_relavant_lines = nil
|
97
97
|
if file_data.is_a?(Hash)
|
98
|
-
@coverage = file_data[
|
98
|
+
@coverage = file_data["data"]
|
99
99
|
@first_updated_at = @last_updated_at = NOT_AVAILABLE
|
100
|
-
@first_updated_at = Time.at(file_data[
|
101
|
-
@last_updated_at =
|
102
|
-
@never_loaded = file_data[
|
100
|
+
@first_updated_at = Time.at(file_data["first_updated_at"]) if file_data["first_updated_at"]
|
101
|
+
@last_updated_at = Time.at(file_data["last_updated_at"]) if file_data["last_updated_at"]
|
102
|
+
@never_loaded = file_data["never_loaded"] || false
|
103
103
|
else
|
104
104
|
# TODO: Deprecate this code path this was backwards compatability from 3-4
|
105
105
|
@coverage = file_data
|
@@ -117,14 +117,14 @@ module Coverband
|
|
117
117
|
|
118
118
|
# The path to this source file relative to the projects directory
|
119
119
|
def project_filename
|
120
|
-
@filename.sub(/^#{Coverband.configuration.root}/,
|
120
|
+
@filename.sub(/^#{Coverband.configuration.root}/, "")
|
121
121
|
end
|
122
122
|
|
123
123
|
# The source code for this file. Aliased as :source
|
124
124
|
def src
|
125
125
|
# We intentionally read source code lazily to
|
126
126
|
# suppress reading unused source code.
|
127
|
-
@src ||= File.open(filename,
|
127
|
+
@src ||= File.open(filename, "rb", &:readlines)
|
128
128
|
end
|
129
129
|
alias source src
|
130
130
|
|
@@ -138,9 +138,9 @@ module Coverband
|
|
138
138
|
def build_lines
|
139
139
|
coverage_exceeding_source_warn if coverage.size > src.size
|
140
140
|
|
141
|
-
lines = src.map.with_index(1)
|
141
|
+
lines = src.map.with_index(1) { |src, i|
|
142
142
|
Coverband::Utils::SourceFile::Line.new(src, i, coverage[i - 1])
|
143
|
-
|
143
|
+
}
|
144
144
|
|
145
145
|
process_skipped_lines(lines)
|
146
146
|
end
|
@@ -241,23 +241,14 @@ module Coverband
|
|
241
241
|
# was at the start of the file name
|
242
242
|
# I had previously patched this in my local Rails app
|
243
243
|
def short_name
|
244
|
-
filename.sub(/^#{Coverband.configuration.root}/,
|
245
|
-
|
246
|
-
.gsub(%r{^\.\/}, '')
|
244
|
+
filename.sub(/^#{Coverband.configuration.root}/, ".")
|
245
|
+
.gsub(%r{^\.\/}, "")
|
247
246
|
end
|
248
247
|
|
249
248
|
def relative_path
|
250
249
|
RelativeFileConverter.convert(filename)
|
251
250
|
end
|
252
251
|
|
253
|
-
def gem?
|
254
|
-
filename =~ %r{^.*\/gems\/}
|
255
|
-
end
|
256
|
-
|
257
|
-
def gem_name
|
258
|
-
gem? ? short_name.split('/').first.gsub(%r{^\.}, '') : nil
|
259
|
-
end
|
260
|
-
|
261
252
|
private
|
262
253
|
|
263
254
|
# ruby 1.9 could use Float#round(places) instead
|