coverband 4.2.0 → 4.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +29 -10
- data/.travis.yml +16 -8
- data/CODE_OF_CONDUCT.md +76 -0
- data/Gemfile +3 -1
- data/Gemfile.rails4 +1 -0
- data/README.md +108 -59
- data/Rakefile +19 -3
- data/changes.md +85 -10
- data/coverband.gemspec +3 -5
- data/lib/coverband/adapters/base.rb +64 -45
- data/lib/coverband/adapters/file_store.rb +15 -9
- data/lib/coverband/adapters/hash_redis_store.rb +190 -0
- data/lib/coverband/adapters/redis_store.rb +35 -11
- data/lib/coverband/at_exit.rb +2 -11
- data/lib/coverband/collectors/coverage.rb +35 -41
- data/lib/coverband/collectors/delta.rb +34 -28
- data/lib/coverband/collectors/view_tracker.rb +157 -0
- data/lib/coverband/configuration.rb +115 -33
- data/lib/coverband/integrations/background.rb +12 -4
- data/lib/coverband/integrations/{middleware.rb → background_middleware.rb} +2 -6
- data/lib/coverband/integrations/bundler.rb +8 -0
- data/lib/coverband/integrations/report_middleware.rb +15 -0
- data/lib/coverband/integrations/resque.rb +3 -5
- data/lib/coverband/reporters/base.rb +40 -16
- data/lib/coverband/reporters/console_report.rb +1 -0
- data/lib/coverband/reporters/html_report.rb +31 -27
- data/lib/coverband/reporters/web.rb +63 -18
- data/lib/coverband/utils/absolute_file_converter.rb +47 -0
- data/lib/coverband/utils/file_hasher.rb +16 -0
- data/lib/coverband/utils/file_list.rb +16 -5
- data/lib/coverband/utils/html_formatter.rb +45 -8
- data/lib/coverband/utils/lines_classifier.rb +5 -0
- data/lib/coverband/utils/railtie.rb +28 -10
- data/lib/coverband/utils/relative_file_converter.rb +41 -0
- data/lib/coverband/utils/result.rb +6 -39
- data/lib/coverband/utils/results.rb +51 -0
- data/lib/coverband/utils/s3_report.rb +2 -3
- data/lib/coverband/utils/source_file.rb +34 -8
- data/lib/coverband/utils/tasks.rb +10 -10
- data/lib/coverband/version.rb +5 -1
- data/lib/coverband.rb +49 -27
- data/lua/install.sh +15 -0
- data/lua/lib/persist-coverage.lua +28 -0
- data/lua/test/bootstrap.lua +5 -0
- data/lua/test/harness.lua +19 -0
- data/lua/test/redis-call.lua +55 -0
- data/lua/test/test-persist-coverage.lua +132 -0
- data/public/application.css +14 -6
- data/public/application.js +27 -0
- data/test/benchmarks/benchmark.rake +167 -73
- data/test/benchmarks/init_rails.rake +10 -0
- data/test/coverband/adapters/base_test.rb +73 -42
- data/test/coverband/adapters/file_store_test.rb +48 -37
- data/test/coverband/adapters/hash_redis_store_test.rb +195 -0
- data/test/coverband/adapters/redis_store_test.rb +102 -59
- data/test/coverband/at_exit_test.rb +0 -2
- data/test/coverband/collectors/coverage_test.rb +71 -13
- data/test/coverband/collectors/delta_test.rb +36 -6
- data/test/coverband/collectors/view_tracker_test.rb +113 -0
- data/test/coverband/configuration_test.rb +47 -7
- data/test/coverband/coverband_test.rb +14 -2
- data/test/coverband/integrations/background_middleware_test.rb +44 -0
- data/test/coverband/integrations/background_test.rb +11 -3
- data/test/coverband/integrations/report_middleware_test.rb +44 -0
- data/test/coverband/integrations/resque_worker_test.rb +5 -6
- data/test/coverband/integrations/test_resque_job.rb +3 -1
- data/test/coverband/reporters/base_test.rb +5 -81
- data/test/coverband/reporters/console_test.rb +3 -10
- data/test/coverband/reporters/html_test.rb +71 -21
- data/test/coverband/reporters/web_test.rb +0 -10
- data/test/coverband/utils/absolute_file_converter_test.rb +56 -0
- data/test/coverband/utils/file_groups_test.rb +11 -5
- data/test/coverband/utils/file_hasher_test.rb +29 -0
- data/test/coverband/utils/file_list_test.rb +5 -5
- data/test/coverband/utils/html_formatter_test.rb +41 -0
- data/test/coverband/utils/relative_file_converter_test.rb +39 -0
- data/test/coverband/utils/result_test.rb +6 -47
- data/test/coverband/utils/results_test.rb +54 -0
- data/test/coverband/utils/s3_report_test.rb +2 -0
- data/test/coverband/utils/source_file_test.rb +54 -0
- data/test/dog.rb.erb +12 -0
- data/test/forked/rails_full_stack_test.rb +106 -0
- data/test/forked/rails_rake_full_stack_test.rb +58 -0
- data/test/integration/full_stack_test.rb +15 -16
- data/test/rails4_dummy/Rakefile +6 -0
- data/test/rails4_dummy/config/application.rb +8 -9
- data/test/rails4_dummy/config/coverband.rb +3 -11
- data/test/rails4_dummy/config/coverband_missing_redis.rb +3 -0
- data/test/rails5_dummy/Rakefile +6 -0
- data/test/rails5_dummy/config/application.rb +6 -10
- data/test/rails5_dummy/config/coverband.rb +7 -3
- data/test/rails5_dummy/config/coverband_missing_redis.rb +15 -0
- data/test/rails_test_helper.rb +22 -5
- data/test/test_helper.rb +52 -11
- data/test/unique_files.rb +17 -9
- data/views/data.erb +1 -0
- data/views/file_list.erb +13 -12
- data/views/gem_list.erb +10 -1
- data/views/layout.erb +6 -18
- data/views/nav.erb +36 -0
- data/views/source_file.erb +20 -4
- data/views/source_file_loader.erb +1 -1
- data/views/view_tracker.erb +52 -0
- metadata +71 -12
- data/lib/coverband/utils/file_path_helper.rb +0 -57
- data/test/coverband/integrations/middleware_test.rb +0 -96
- data/test/integration/rails_full_stack_test.rb +0 -95
|
@@ -3,72 +3,8 @@
|
|
|
3
3
|
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
4
4
|
|
|
5
5
|
class ReportsBaseTest < Minitest::Test
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
config.reporter = 'std_out'
|
|
9
|
-
config.root = '/full/remote_app/path'
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
key = '/app/is/a/path.rb'
|
|
13
|
-
# the code takes config.root expands and adds a '/' for the final path in roots
|
|
14
|
-
roots = ['/app/', '/full/remote_app/path/']
|
|
15
|
-
|
|
16
|
-
expected_path = '/full/remote_app/path/is/a/path.rb'
|
|
17
|
-
File.expects(:exist?).with(key).returns(false)
|
|
18
|
-
File.expects(:exist?).with(expected_path).returns(true)
|
|
19
|
-
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
test 'relative_path_to_full fix filename a changing deploy path with quotes' do
|
|
23
|
-
Coverband.configure do |config|
|
|
24
|
-
config.reporter = 'std_out'
|
|
25
|
-
config.root = '/full/remote_app/path'
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
expected_path = '/full/remote_app/path/app/models/user.rb'
|
|
29
|
-
key = '/box/apps/app_name/releases/20140725203539/app/models/user.rb'
|
|
30
|
-
roots = ["/box/apps/app_name/releases/\\d+/", '/full/remote_app/path/']
|
|
31
|
-
File.expects(:exist?).with('/box/apps/app_name/releases/\\d+/app/models/user.rb').returns(false)
|
|
32
|
-
File.expects(:exist?).with(expected_path).returns(true)
|
|
33
|
-
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
|
34
|
-
File.expects(:exist?).with('/box/apps/app_name/releases/\\d+/app/models/user.rb').returns(false)
|
|
35
|
-
File.expects(:exist?).with(expected_path).returns(true)
|
|
36
|
-
roots = ['/box/apps/app_name/releases/\d+/', '/full/remote_app/path/']
|
|
37
|
-
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
test 'relative_path_to_full fix filename a changing deploy path real world examples' do
|
|
41
|
-
current_app_root = '/var/local/company/company.d/79'
|
|
42
|
-
Coverband.configure do |config|
|
|
43
|
-
config.reporter = 'std_out'
|
|
44
|
-
config.root = current_app_root
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
expected_path = '/var/local/company/company.d/79/app/controllers/dashboard_controller.rb'
|
|
48
|
-
key = '/var/local/company/company.d/78/app/controllers/dashboard_controller.rb'
|
|
49
|
-
|
|
50
|
-
File.expects(:exist?).with('/var/local/company/company.d/[0-9]*/app/controllers/dashboard_controller.rb').returns(false)
|
|
51
|
-
File.expects(:exist?).with(expected_path).returns(true)
|
|
52
|
-
roots = ['/var/local/company/company.d/[0-9]*/', "#{current_app_root}/"]
|
|
53
|
-
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
|
54
|
-
File.expects(:exist?).with('/var/local/company/company.d/[0-9]*/app/controllers/dashboard_controller.rb').returns(false)
|
|
55
|
-
File.expects(:exist?).with(expected_path).returns(true)
|
|
56
|
-
roots = ["/var/local/company/company.d/[0-9]*/", "#{current_app_root}/"]
|
|
57
|
-
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
test 'relative_path_to_full leave filename from a key with a local path' do
|
|
61
|
-
Coverband.configure do |config|
|
|
62
|
-
config.reporter = 'std_out'
|
|
63
|
-
config.root = '/full/remote_app/path'
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
key = '/full/remote_app/path/is/a/path.rb'
|
|
67
|
-
# the code takes config.root expands and adds a '/' for the final path in roots
|
|
68
|
-
roots = ['/app/', '/full/remote_app/path/']
|
|
69
|
-
|
|
70
|
-
expected_path = '/full/remote_app/path/is/a/path.rb'
|
|
71
|
-
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
|
6
|
+
def setup
|
|
7
|
+
super
|
|
72
8
|
end
|
|
73
9
|
|
|
74
10
|
test '#merge_arrays basic merge preserves order and counts' do
|
|
@@ -96,14 +32,9 @@ class ReportsBaseTest < Minitest::Test
|
|
|
96
32
|
end
|
|
97
33
|
|
|
98
34
|
test "#get_current_scov_data_imp doesn't ignore folders with default ignore keys" do
|
|
99
|
-
@redis = Redis.new
|
|
100
|
-
store = Coverband::Adapters::RedisStore.new(@redis)
|
|
101
|
-
store.clear!
|
|
102
|
-
|
|
103
35
|
Coverband.configure do |config|
|
|
104
36
|
config.reporter = 'std_out'
|
|
105
37
|
config.root = '/full/remote_app/path'
|
|
106
|
-
config.store = store
|
|
107
38
|
end
|
|
108
39
|
|
|
109
40
|
key = '/a_path/that_has_erb_in/thepath.rb'
|
|
@@ -123,6 +54,7 @@ class ReportsBaseTest < Minitest::Test
|
|
|
123
54
|
# rubocop:disable all
|
|
124
55
|
###
|
|
125
56
|
test '#get_current_scov_data_imp merges multiples of file data' do
|
|
57
|
+
skip "@danmayer to take a closer look at this one"
|
|
126
58
|
coverage = {'/base/66/app/controllers/dashboard_controller.rb' =>
|
|
127
59
|
{"first_updated_at"=>1549610119,
|
|
128
60
|
"last_updated_at"=>1549610200,
|
|
@@ -139,19 +71,10 @@ class ReportsBaseTest < Minitest::Test
|
|
|
139
71
|
"file_hash"=>"14dc84e940e26cbfb9ac79b43862e762",
|
|
140
72
|
"data"=>[16, 16, 16, nil, 16, 16, nil, nil, 16, nil, 16, 32, 32, nil, 32, 32, 32, 32, 32, 32, 32, nil, nil, 16, nil, 16, 32, 23, 0, 0, 0, 0, nil, nil, nil, nil, 0, 0, nil, nil, 16, 32, 32, 32, nil, nil, nil, nil, nil, 16, 32, nil, nil, 16, 32, nil, nil]}
|
|
141
73
|
}
|
|
142
|
-
@redis = Redis.new
|
|
143
|
-
store = Coverband::Adapters::RedisStore.new(@redis)
|
|
144
|
-
store.clear!
|
|
145
|
-
|
|
146
|
-
Coverband.configure do |config|
|
|
147
|
-
config.reporter = 'std_out'
|
|
148
|
-
config.root = '/base/78/app/'
|
|
149
|
-
config.store = store
|
|
150
|
-
end
|
|
151
|
-
|
|
152
74
|
key = '/base/78/app/app/controllers/dashboard_controller.rb'
|
|
153
75
|
roots = ['/base/[0-9]*/', '/base/78/app/']
|
|
154
76
|
|
|
77
|
+
Coverband.configuration.stubs(:all_root_paths).returns(roots)
|
|
155
78
|
lines_hit = [1, 3, 6]
|
|
156
79
|
store.stubs(:merged_coverage).returns(coverage)
|
|
157
80
|
File.expects(:exist?).at_least_once
|
|
@@ -165,4 +88,5 @@ class ReportsBaseTest < Minitest::Test
|
|
|
165
88
|
"data"=>[38, 38, 38, nil, 38, 38, nil, nil, 38, nil, 38, 80, 80, nil, 80, 80, 80, 80, 80, 80, 80, nil, nil, 38, nil, 38, 80, 55, 0, 0, 0, 0, nil, nil, nil, nil, 0, 0, nil, nil, 38, 80, 80, 80, nil, nil, nil, nil, nil, 38, 80, nil, nil, 38, 80, nil, nil]}
|
|
166
89
|
assert_equal expected, Coverband::Reporters::Base.send(:get_current_scov_data_imp, store, roots)[:merged][key]
|
|
167
90
|
end
|
|
91
|
+
|
|
168
92
|
end
|
|
@@ -7,23 +7,16 @@ class HTMLReportTest < Minitest::Test
|
|
|
7
7
|
|
|
8
8
|
def setup
|
|
9
9
|
super
|
|
10
|
-
@
|
|
11
|
-
@store = Coverband::Adapters::RedisStore.new(@redis)
|
|
12
|
-
@store.clear!
|
|
10
|
+
@store = Coverband.configuration.store
|
|
13
11
|
end
|
|
14
12
|
|
|
15
13
|
test 'report data' do
|
|
16
14
|
Coverband.configure do |config|
|
|
17
|
-
config.reporter
|
|
18
|
-
config.store = @store
|
|
19
|
-
config.reporting_frequency = 100.0
|
|
15
|
+
config.reporter = 'std_out'
|
|
20
16
|
end
|
|
21
17
|
Coverband.configuration.logger.stubs('info')
|
|
22
18
|
mock_file_hash
|
|
23
|
-
Coverband.
|
|
24
|
-
.expects(:current_root)
|
|
25
|
-
.at_least_once
|
|
26
|
-
.returns('app_path')
|
|
19
|
+
Coverband::Utils::RelativeFileConverter.expects(:convert).with('app_path/dog.rb').returns('./dog.rb')
|
|
27
20
|
@store.send(:save_report, basic_coverage)
|
|
28
21
|
|
|
29
22
|
report = Coverband::Reporters::ConsoleReport.report(@store)[:merged]
|
|
@@ -5,41 +5,91 @@ require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
|
5
5
|
class ReportHTMLTest < Minitest::Test
|
|
6
6
|
def setup
|
|
7
7
|
super
|
|
8
|
-
@
|
|
9
|
-
@store = Coverband::Adapters::RedisStore.new(@redis)
|
|
10
|
-
@store.clear!
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
test 'generate scov html report' do
|
|
8
|
+
@store = Coverband.configuration.store
|
|
14
9
|
Coverband.configure do |config|
|
|
15
|
-
config.reporter = 'scov'
|
|
16
10
|
config.store = @store
|
|
17
|
-
config.
|
|
18
|
-
config.ignore = ['notsomething.rb']
|
|
11
|
+
config.root = fixtures_root
|
|
12
|
+
config.ignore = ['notsomething.rb', 'lib/*']
|
|
19
13
|
end
|
|
20
14
|
mock_file_hash
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
test 'generate dynamic content hosted html report' do
|
|
21
18
|
@store.send(:save_report, basic_coverage)
|
|
22
19
|
|
|
23
20
|
html = Coverband::Reporters::HTMLReport.new(@store,
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
static: false,
|
|
22
|
+
open_report: false).report
|
|
26
23
|
assert_match 'Generated by', html
|
|
27
24
|
end
|
|
28
25
|
|
|
29
|
-
test '
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
test 'files with no Coverage but in project are shown in reports' do
|
|
27
|
+
@store.send(:save_report, basic_source_fixture_coverage)
|
|
28
|
+
|
|
29
|
+
html = Coverband::Reporters::HTMLReport.new(@store,
|
|
30
|
+
static: false,
|
|
31
|
+
open_report: false).report
|
|
32
|
+
assert_match 'sample.rb', html
|
|
33
|
+
# in project, but not in coverage data
|
|
34
|
+
assert_match 'app/models/user.rb', html
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
test 'files with no Coverage but in project details page list warning' do
|
|
38
|
+
@store.send(:save_report, basic_coverage_full_path)
|
|
39
|
+
|
|
40
|
+
filename = basic_coverage_file_full_path
|
|
41
|
+
base_path = Dir.pwd
|
|
42
|
+
# in project, but not in coverage data
|
|
43
|
+
html = Coverband::Reporters::HTMLReport.new(Coverband.configuration.store,
|
|
44
|
+
filename: "#{Dir.pwd}/test/fixtures/app/models/user.rb",
|
|
45
|
+
base_path: base_path,
|
|
46
|
+
open_report: false).file_details
|
|
47
|
+
assert_match 'This file was never loaded', html
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
test 'generate static HTML report file' do
|
|
37
51
|
@store.send(:save_report, basic_coverage)
|
|
38
52
|
|
|
39
53
|
reporter = Coverband::Reporters::HTMLReport.new(@store,
|
|
40
|
-
|
|
54
|
+
static: true,
|
|
41
55
|
open_report: false)
|
|
42
|
-
Coverband::Utils::HTMLFormatter.any_instance.expects(:
|
|
56
|
+
Coverband::Utils::HTMLFormatter.any_instance.expects(:format_static_html!).once
|
|
43
57
|
reporter.report
|
|
44
58
|
end
|
|
59
|
+
|
|
60
|
+
test 'generate dynamic content detailed file report' do
|
|
61
|
+
@store.send(:save_report, basic_coverage_full_path)
|
|
62
|
+
|
|
63
|
+
filename = basic_coverage_file_full_path
|
|
64
|
+
base_path = '/coverage'
|
|
65
|
+
html = Coverband::Reporters::HTMLReport.new(Coverband.configuration.store,
|
|
66
|
+
filename: filename,
|
|
67
|
+
base_path: base_path,
|
|
68
|
+
open_report: false).file_details
|
|
69
|
+
assert_match 'Coverage first seen', html
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
test 'generate dynamic content detailed file report handles missing file' do
|
|
73
|
+
@store.send(:save_report, basic_coverage_full_path)
|
|
74
|
+
|
|
75
|
+
filename = 'missing_path'
|
|
76
|
+
base_path = '/coverage'
|
|
77
|
+
html = Coverband::Reporters::HTMLReport.new(Coverband.configuration.store,
|
|
78
|
+
filename: filename,
|
|
79
|
+
base_path: base_path,
|
|
80
|
+
open_report: false).file_details
|
|
81
|
+
assert_match 'File No Longer Available', html
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
test 'generate dynamic content detailed file report does not allow loading real non project files' do
|
|
85
|
+
@store.send(:save_report, basic_coverage_full_path)
|
|
86
|
+
|
|
87
|
+
filename = "#{test_root}/test_helper.rb"
|
|
88
|
+
base_path = '/coverage'
|
|
89
|
+
html = Coverband::Reporters::HTMLReport.new(Coverband.configuration.store,
|
|
90
|
+
filename: filename,
|
|
91
|
+
base_path: base_path,
|
|
92
|
+
open_report: false).file_details
|
|
93
|
+
assert_match 'File No Longer Available', html
|
|
94
|
+
end
|
|
45
95
|
end
|
|
@@ -37,16 +37,6 @@ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.2.0')
|
|
|
37
37
|
post '/clear'
|
|
38
38
|
assert_equal 301, last_response.status
|
|
39
39
|
end
|
|
40
|
-
|
|
41
|
-
test 'collect_coverage' do
|
|
42
|
-
post '/collect_coverage'
|
|
43
|
-
assert_equal 301, last_response.status
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
test 'reload_files' do
|
|
47
|
-
post '/reload_files'
|
|
48
|
-
assert_equal 301, last_response.status
|
|
49
|
-
end
|
|
50
40
|
end
|
|
51
41
|
end
|
|
52
42
|
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
4
|
+
|
|
5
|
+
module Coverband
|
|
6
|
+
module Utils
|
|
7
|
+
class AbsoluteFileConverterTest < ::Minitest::Test
|
|
8
|
+
def test_convert
|
|
9
|
+
converter = AbsoluteFileConverter.new([FileUtils.pwd])
|
|
10
|
+
assert_equal("#{FileUtils.pwd}/lib/coverband.rb", converter.convert('./lib/coverband.rb'))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_convert_multiple_roots
|
|
14
|
+
converter = AbsoluteFileConverter.new(['/foo/bar', FileUtils.pwd])
|
|
15
|
+
assert_equal("#{FileUtils.pwd}/Rakefile", converter.convert('./Rakefile'))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
test 'relative_path_to_full leave filename from a key with a local path' do
|
|
19
|
+
converter = AbsoluteFileConverter.new(['/app/', '/full/remote_app/path/'])
|
|
20
|
+
assert_equal '/full/remote_app/path/is/a/path.rb', converter.convert('/full/remote_app/path/is/a/path.rb')
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
test 'relative_path_to_full fix filename from a key with a swappable path' do
|
|
24
|
+
key = '/app/is/a/path.rb'
|
|
25
|
+
converter = AbsoluteFileConverter.new(['/app/', '/full/remote_app/path/'])
|
|
26
|
+
expected_path = '/full/remote_app/path/is/a/path.rb'
|
|
27
|
+
File.expects(:exist?).with(key).returns(false)
|
|
28
|
+
File.expects(:exist?).with(expected_path).returns(true)
|
|
29
|
+
assert_equal expected_path, converter.convert(key)
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
test 'relative_path_to_full fix filename a changing deploy path with quotes' do
|
|
33
|
+
converter = AbsoluteFileConverter.new(['/box/apps/app_name/releases/\\d+/', '/full/remote_app/path/'])
|
|
34
|
+
expected_path = '/full/remote_app/path/app/models/user.rb'
|
|
35
|
+
key = '/box/apps/app_name/releases/20140725203539/app/models/user.rb'
|
|
36
|
+
File.expects(:exist?).with('/box/apps/app_name/releases/\\d+/app/models/user.rb').returns(false)
|
|
37
|
+
File.expects(:exist?).with(expected_path).returns(true)
|
|
38
|
+
assert_equal expected_path, converter.convert(key)
|
|
39
|
+
assert_equal expected_path, converter.convert(key)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
test 'relative_path_to_full fix filename a changing deploy path real world examples' do
|
|
43
|
+
current_app_root = '/var/local/company/company.d/79'
|
|
44
|
+
converter = AbsoluteFileConverter.new(['/var/local/company/company.d/[0-9]*/', "#{current_app_root}/"])
|
|
45
|
+
|
|
46
|
+
expected_path = '/var/local/company/company.d/79/app/controllers/dashboard_controller.rb'
|
|
47
|
+
key = '/var/local/company/company.d/78/app/controllers/dashboard_controller.rb'
|
|
48
|
+
File.expects(:exist?).with('/var/local/company/company.d/[0-9]*/app/controllers/dashboard_controller.rb').returns(false)
|
|
49
|
+
File.expects(:exist?).with(expected_path).returns(true)
|
|
50
|
+
roots = ['/var/local/company/company.d/[0-9]*/', "#{current_app_root}/"]
|
|
51
|
+
assert_equal expected_path, converter.convert(key)
|
|
52
|
+
assert_equal expected_path, converter.convert(key)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -3,16 +3,18 @@
|
|
|
3
3
|
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
4
4
|
|
|
5
5
|
describe Coverband::Utils::FileGroups do
|
|
6
|
-
FAKE_GEM_PATH = '
|
|
6
|
+
FAKE_GEM_PATH = '/Users/danmayer/.rvm/gems/ruby-2.6.2/gems'
|
|
7
|
+
SECONDAY_GEM_PATH = '/Users/danmayer/.rvm/rubies/ruby-2.6.2/lib/ruby/gems/2.6.0/gems'
|
|
7
8
|
subject do
|
|
8
9
|
controller_lines = [nil, 2, 2, 0, nil, nil, 0, nil, nil, nil]
|
|
9
10
|
files = [
|
|
10
11
|
Coverband::Utils::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil]),
|
|
11
12
|
Coverband::Utils::SourceFile.new(source_fixture('app/models/user.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]),
|
|
12
13
|
Coverband::Utils::SourceFile.new(source_fixture('app/controllers/sample_controller.rb'), controller_lines),
|
|
13
|
-
Coverband::Utils::SourceFile.new("#{FAKE_GEM_PATH}/gem_name.rb", controller_lines)
|
|
14
|
+
Coverband::Utils::SourceFile.new("#{FAKE_GEM_PATH}/gem_name-1.0.0/gem_name.rb", controller_lines),
|
|
15
|
+
Coverband::Utils::SourceFile.new("#{SECONDAY_GEM_PATH}/gem_two_name-1.1.1/gem_two.rb", controller_lines)
|
|
14
16
|
]
|
|
15
|
-
Coverband.configuration.expects(:gem_paths).at_least_once.returns([FAKE_GEM_PATH])
|
|
17
|
+
Coverband.configuration.expects(:gem_paths).at_least_once.returns([FAKE_GEM_PATH, SECONDAY_GEM_PATH])
|
|
16
18
|
Coverband.configuration.track_gems = true
|
|
17
19
|
Coverband::Utils::FileGroups.new(files)
|
|
18
20
|
end
|
|
@@ -22,7 +24,11 @@ describe Coverband::Utils::FileGroups do
|
|
|
22
24
|
end
|
|
23
25
|
|
|
24
26
|
it 'has gem files' do
|
|
25
|
-
assert_equal "
|
|
27
|
+
assert_equal "gem_name-1.0.0", subject.grouped_results['Gems'].first.first.gem_name
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
it 'has gem files from secondary gem paths' do
|
|
31
|
+
assert_equal "gem_two_name-1.1.1", subject.grouped_results['Gems'][1].first.gem_name
|
|
26
32
|
end
|
|
27
33
|
end
|
|
28
34
|
|
|
@@ -50,6 +56,6 @@ describe Coverband::Utils::FileGroups, :vendored_gems do
|
|
|
50
56
|
end
|
|
51
57
|
|
|
52
58
|
it 'does has gem files' do
|
|
53
|
-
assert_equal 'gem_name.rb', subject.grouped_results['Gems'].first.first.short_name
|
|
59
|
+
assert_equal '.gem_name.rb', subject.grouped_results['Gems'].first.first.short_name
|
|
54
60
|
end
|
|
55
61
|
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
4
|
+
|
|
5
|
+
module Coverband
|
|
6
|
+
module Utils
|
|
7
|
+
class FileHasherTest < Minitest::Test
|
|
8
|
+
def test_hash_same_file
|
|
9
|
+
refute_nil FileHasher.hash('./test/dog.rb')
|
|
10
|
+
assert_equal(FileHasher.hash('./test/dog.rb'), FileHasher.hash('./test/dog.rb'))
|
|
11
|
+
assert_equal(FileHasher.hash(File.expand_path('./test/dog.rb')), FileHasher.hash('./test/dog.rb'))
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def test_hash_different_files
|
|
15
|
+
refute_equal(FileHasher.hash('./test/dog.rb'), FileHasher.hash('./lib/coverband.rb'))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_hash_file_not_exists
|
|
19
|
+
assert_nil(FileHasher.hash('./made_up_file.py'))
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def test_hash_gem_file
|
|
23
|
+
spec = Gem::Specification.find_by_name('rainbow')
|
|
24
|
+
assert FileHasher.hash("./gems/rainbow-#{spec.version}/lib/rainbow.rb",
|
|
25
|
+
path_converter: AbsoluteFileConverter.new(Coverband.configuration.gem_paths))
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -9,7 +9,7 @@ require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
|
9
9
|
describe Coverband::Utils::FileList do
|
|
10
10
|
subject do
|
|
11
11
|
original_result = {
|
|
12
|
-
source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
|
|
12
|
+
source_fixture('sample.rb') => {'first_updated_at' => Time.at(0), 'data' => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil]},
|
|
13
13
|
source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
|
14
14
|
source_fixture('app/controllers/sample_controller.rb') => [nil, 2, 2, 0, nil, nil, 0, nil, nil, nil]
|
|
15
15
|
}
|
|
@@ -44,11 +44,11 @@ describe Coverband::Utils::FileList do
|
|
|
44
44
|
assert_equal [50.0, 80.0, 100.0], subject.covered_percentages
|
|
45
45
|
end
|
|
46
46
|
|
|
47
|
-
it 'has the correct least covered file' do
|
|
48
|
-
assert subject.least_covered_file.match(/sample_controller.rb/)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
47
|
it 'has the correct covered strength' do
|
|
52
48
|
assert_equal 0.9285714285714286, subject.covered_strength
|
|
53
49
|
end
|
|
50
|
+
|
|
51
|
+
it 'has correct first_seen_at' do
|
|
52
|
+
assert_equal Time.at(0), subject.first_seen_at
|
|
53
|
+
end
|
|
54
54
|
end
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
4
|
+
|
|
5
|
+
class HTMLFormatterTest < Minitest::Test
|
|
6
|
+
def setup
|
|
7
|
+
super
|
|
8
|
+
@store = Coverband::Adapters::RedisStore.new(Coverband::Test.redis, redis_namespace: 'coverband_test')
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
test 'generate dynamic content hosted html report' do
|
|
12
|
+
Coverband.configure do |config|
|
|
13
|
+
config.store = @store
|
|
14
|
+
config.ignore = ['notsomething.rb']
|
|
15
|
+
end
|
|
16
|
+
mock_file_hash
|
|
17
|
+
@store.send(:save_report, basic_coverage_full_path)
|
|
18
|
+
|
|
19
|
+
notice = nil
|
|
20
|
+
base_path = '/coverage'
|
|
21
|
+
filtered_report_files = Coverband::Reporters::Base.report(@store, {})
|
|
22
|
+
html = Coverband::Utils::HTMLFormatter.new(filtered_report_files,
|
|
23
|
+
base_path: base_path,
|
|
24
|
+
notice: notice).format_dynamic_html!
|
|
25
|
+
assert_match 'loading source data', html
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
test 'generate static HTML report file' do
|
|
29
|
+
Coverband.configure do |config|
|
|
30
|
+
config.store = @store
|
|
31
|
+
config.ignore = ['notsomething.rb']
|
|
32
|
+
end
|
|
33
|
+
mock_file_hash
|
|
34
|
+
@store.send(:save_report, basic_coverage_full_path)
|
|
35
|
+
|
|
36
|
+
filtered_report_files = Coverband::Reporters::Base.report(@store, {})
|
|
37
|
+
Coverband::Utils::HTMLFormatter.new(filtered_report_files).format_static_html!
|
|
38
|
+
html = File.read("#{Coverband.configuration.root}/coverage/index.html")
|
|
39
|
+
assert_match 'Coverage first seen', html
|
|
40
|
+
end
|
|
41
|
+
end
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
4
|
+
|
|
5
|
+
module Coverband
|
|
6
|
+
module Utils
|
|
7
|
+
class RelativeFileConverterTest < ::Minitest::Test
|
|
8
|
+
def test_convert
|
|
9
|
+
converter = RelativeFileConverter.new(['/bar/tmp/'])
|
|
10
|
+
assert_equal('./gracie.rb', converter.convert('/bar/tmp/gracie.rb'))
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def test_convert_without_leading_forward_slash
|
|
14
|
+
converter = RelativeFileConverter.new(['/foo/bar'])
|
|
15
|
+
assert_equal('./file.rb', converter.convert('/foo/bar/file.rb'))
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def test_multiple_roots
|
|
19
|
+
converter = RelativeFileConverter.new(['/bar/tmp/', '/foo/bar/'])
|
|
20
|
+
assert_equal('./josie.rb', converter.convert('/foo/bar/josie.rb'))
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def test_no_match
|
|
24
|
+
converter = RelativeFileConverter.new(['/bar/tmp/', '/foo/bar/'])
|
|
25
|
+
assert_equal('/foo/josie.rb', converter.convert('/foo/josie.rb'))
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def test_middle_path_match
|
|
29
|
+
converter = RelativeFileConverter.new(['/bar/tmp/', '/foo/bar/'])
|
|
30
|
+
assert_equal('/tmp/foo/bar/josie.rb', converter.convert('/tmp/foo/bar/josie.rb'))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def test_already_relative_file
|
|
34
|
+
converter = RelativeFileConverter.new(['/bar/tmp/', '/foo/bar/'])
|
|
35
|
+
assert_equal('./foo/bar/josie.rb', converter.convert('./foo/bar/josie.rb'))
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
@@ -48,57 +48,16 @@ describe 'result' do
|
|
|
48
48
|
assert_equal [80.0, 80.0, 100.0], subject.covered_percentages
|
|
49
49
|
end
|
|
50
50
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
:least_covered_file,
|
|
58
|
-
:covered_strength,
|
|
59
|
-
:covered_lines,
|
|
60
|
-
:missed_lines,
|
|
61
|
-
:total_lines].each do |msg|
|
|
51
|
+
%i[covered_percent
|
|
52
|
+
covered_percentages
|
|
53
|
+
covered_strength
|
|
54
|
+
covered_lines
|
|
55
|
+
missed_lines
|
|
56
|
+
total_lines].each do |msg|
|
|
62
57
|
it "responds to #{msg}" do
|
|
63
58
|
assert(subject.respond_to?(msg))
|
|
64
59
|
end
|
|
65
60
|
end
|
|
66
|
-
|
|
67
|
-
describe 'dumped with to_hash' do
|
|
68
|
-
it 'is a hash' do
|
|
69
|
-
assert subject.to_hash.is_a?(Hash)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
describe 'loaded back with from_hash' do
|
|
73
|
-
let(:dumped_result) do
|
|
74
|
-
Coverband::Utils::Result.from_hash(subject.to_hash)
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
it 'has 3 source files' do
|
|
78
|
-
assert_equal subject.source_files.count, dumped_result.source_files.count
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
it 'has the same covered_percent' do
|
|
82
|
-
assert_equal subject.covered_percent, dumped_result.covered_percent
|
|
83
|
-
end
|
|
84
|
-
|
|
85
|
-
it 'has the same covered_percentages' do
|
|
86
|
-
assert_equal subject.covered_percentages, dumped_result.covered_percentages
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it 'has the same timestamp' do
|
|
90
|
-
assert_equal subject.created_at.to_i, dumped_result.created_at.to_i
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
it 'has the same command_name' do
|
|
94
|
-
assert_equal subject.command_name, dumped_result.command_name
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
it 'has the same original_result' do
|
|
98
|
-
assert_equal subject.original_result, dumped_result.original_result
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
61
|
end
|
|
103
62
|
end
|
|
104
63
|
end
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
4
|
+
|
|
5
|
+
describe 'results' do
|
|
6
|
+
describe 'with a (mocked) Coverage.result' do
|
|
7
|
+
let(:source_file) { Coverband::Utils::SourceFile.new(source_fixture('app/models/user.rb'), run_lines) }
|
|
8
|
+
let(:eager_lines) { [nil, 1, 1, 0, nil, nil, 1, 0, nil, nil] }
|
|
9
|
+
let(:run_lines) { [nil, nil, nil, 1, nil, nil, nil,nil, nil, nil] }
|
|
10
|
+
let(:original_result) do
|
|
11
|
+
orig = {
|
|
12
|
+
Coverband::MERGED_TYPE => {source_fixture('app/models/user.rb') => eager_lines},
|
|
13
|
+
}
|
|
14
|
+
orig.merge!({Coverband::EAGER_TYPE => {source_fixture('app/models/user.rb') => eager_lines}}) if eager_lines
|
|
15
|
+
orig.merge!({Coverband::RUNTIME_TYPE => {source_fixture('app/models/user.rb') => run_lines}}) if run_lines
|
|
16
|
+
orig
|
|
17
|
+
end
|
|
18
|
+
subject { Coverband::Utils::Results.new(original_result) }
|
|
19
|
+
|
|
20
|
+
describe 'runtime relevant lines is supported' do
|
|
21
|
+
it 'has correct runtime relevant coverage' do
|
|
22
|
+
assert_equal 50.0, subject.runtime_relevant_coverage(source_file)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
it 'has correct runtime relevant lines' do
|
|
26
|
+
assert_equal 2, subject.runtime_relavent_lines(source_file)
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
describe 'runtime relevant lines when no runtime coverage exists' do
|
|
31
|
+
let(:run_lines) { nil }
|
|
32
|
+
|
|
33
|
+
it 'has correct runtime relevant lines' do
|
|
34
|
+
assert_equal 0.0, subject.runtime_relevant_coverage(source_file)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it 'has correct runtime relevant lines' do
|
|
38
|
+
assert_equal 2, subject.runtime_relavent_lines(source_file)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
describe 'runtime relevant lines when no eager coverage exists' do
|
|
43
|
+
let(:eager_lines) { nil }
|
|
44
|
+
|
|
45
|
+
it 'has correct runtime relevant lines' do
|
|
46
|
+
assert_equal 100.0, subject.runtime_relevant_coverage(source_file)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it 'has correct runtime relevant lines' do
|
|
50
|
+
assert_equal 1, subject.runtime_relavent_lines(source_file)
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
end
|