coverband 4.2.0 → 4.2.2
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 -9
- data/.travis.yml +10 -8
- data/CODE_OF_CONDUCT.md +76 -0
- data/Gemfile +3 -1
- data/Gemfile.rails4 +1 -0
- data/README.md +72 -43
- data/Rakefile +14 -3
- data/changes.md +66 -11
- data/coverband.gemspec +2 -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 +182 -0
- data/lib/coverband/adapters/redis_store.rb +33 -11
- data/lib/coverband/at_exit.rb +2 -11
- data/lib/coverband/collectors/coverage.rb +34 -40
- data/lib/coverband/collectors/delta.rb +34 -28
- data/lib/coverband/collectors/view_tracker.rb +124 -0
- data/lib/coverband/configuration.rb +96 -32
- data/lib/coverband/integrations/background.rb +9 -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 +21 -27
- data/lib/coverband/reporters/web.rb +19 -21
- 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 +37 -8
- data/lib/coverband/utils/lines_classifier.rb +5 -0
- data/lib/coverband/utils/railtie.rb +20 -9
- data/lib/coverband/utils/relative_file_converter.rb +41 -0
- data/lib/coverband/utils/result.rb +1 -37
- data/lib/coverband/utils/results.rb +51 -0
- data/lib/coverband/utils/s3_report.rb +2 -2
- data/lib/coverband/utils/source_file.rb +31 -8
- data/lib/coverband/utils/tasks.rb +10 -10
- data/lib/coverband/version.rb +5 -1
- data/lib/coverband.rb +39 -22
- data/public/application.css +6 -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 +190 -0
- data/test/coverband/adapters/redis_store_test.rb +92 -59
- data/test/coverband/at_exit_test.rb +0 -2
- data/test/coverband/collectors/coverage_test.rb +62 -10
- data/test/coverband/collectors/delta_test.rb +36 -6
- data/test/coverband/collectors/view_tracker_test.rb +77 -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 +1 -3
- data/test/coverband/integrations/report_middleware_test.rb +44 -0
- data/test/coverband/integrations/resque_worker_test.rb +6 -6
- data/test/coverband/integrations/test_resque_job.rb +3 -1
- data/test/coverband/reporters/base_test.rb +2 -79
- data/test/coverband/reporters/console_test.rb +2 -6
- data/test/coverband/reporters/html_test.rb +58 -19
- 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 +43 -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 +50 -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 +48 -0
- data/test/integration/full_stack_test.rb +17 -16
- data/test/rails4_dummy/Rakefile +6 -0
- data/test/rails4_dummy/config/application.rb +8 -9
- data/test/rails4_dummy/config/coverband.rb +5 -3
- data/test/rails5_dummy/Rakefile +6 -0
- data/test/rails5_dummy/config/application.rb +6 -10
- data/test/rails5_dummy/config/coverband.rb +4 -2
- data/test/rails_test_helper.rb +22 -5
- data/test/test_helper.rb +45 -8
- data/test/unique_files.rb +17 -9
- data/views/file_list.erb +2 -2
- data/views/gem_list.erb +10 -1
- data/views/layout.erb +6 -18
- data/views/nav.erb +35 -0
- data/views/source_file.erb +13 -4
- data/views/source_file_loader.erb +1 -1
- data/views/view_tracker.erb +37 -0
- metadata +59 -25
- 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
|
@@ -5,31 +5,53 @@ require File.expand_path('../test_helper', File.dirname(__FILE__))
|
|
|
5
5
|
class BaseTest < Minitest::Test
|
|
6
6
|
def setup
|
|
7
7
|
super
|
|
8
|
+
Coverband.configuration.reset
|
|
8
9
|
Coverband.configure do |config|
|
|
9
10
|
config.root = Dir.pwd
|
|
10
11
|
config.s3_bucket = nil
|
|
11
12
|
config.root_paths = ['/app_path/']
|
|
12
|
-
config.ignore = ['
|
|
13
|
-
config.reporting_frequency = 100.0
|
|
13
|
+
config.ignore = ['config/envionments']
|
|
14
14
|
config.reporter = 'std_out'
|
|
15
|
-
config.store = Coverband::Adapters::RedisStore.new(Redis.new)
|
|
15
|
+
config.store = Coverband::Adapters::RedisStore.new(Redis.new, redis_namespace: 'coverband_test')
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
|
|
19
|
-
test '
|
|
19
|
+
test 'ignore works with equal' do
|
|
20
20
|
coverband = Coverband::Collectors::Coverage.instance.reset_instance
|
|
21
|
-
|
|
21
|
+
expected = ["vendor", ".erb$", ".slim$", "/tmp", "internal:prelude", "schema.rb", "config/envionments"]
|
|
22
|
+
assert_equal expected, Coverband.configuration.ignore
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
test 'ignore works with plus equal' do
|
|
26
|
+
Coverband.configure do |config|
|
|
27
|
+
config.ignore += ['config/initializers']
|
|
28
|
+
end
|
|
29
|
+
coverband = Coverband::Collectors::Coverage.instance.reset_instance
|
|
30
|
+
expected = ["vendor",
|
|
31
|
+
".erb$",
|
|
32
|
+
".slim$",
|
|
33
|
+
"/tmp",
|
|
34
|
+
"internal:prelude",
|
|
35
|
+
"schema.rb",
|
|
36
|
+
"config/envionments",
|
|
37
|
+
"config/initializers"]
|
|
38
|
+
assert_equal expected, Coverband.configuration.ignore
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
test 'ignore' do
|
|
42
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
|
43
|
+
assert !Coverband.configuration.gem_paths.first.nil?
|
|
22
44
|
end
|
|
23
45
|
|
|
24
46
|
test 'gem_paths' do
|
|
25
47
|
Coverband::Collectors::Coverage.instance.reset_instance
|
|
26
|
-
assert Coverband.configuration.gem_paths.first
|
|
48
|
+
assert !Coverband.configuration.gem_paths.first.nil?
|
|
27
49
|
end
|
|
28
50
|
|
|
29
51
|
test 'groups' do
|
|
30
52
|
Coverband::Collectors::Coverage.instance.reset_instance
|
|
31
53
|
Coverband.configuration.track_gems = true
|
|
32
|
-
assert_equal %w
|
|
54
|
+
assert_equal %w[App Gems], Coverband.configuration.groups.keys
|
|
33
55
|
end
|
|
34
56
|
|
|
35
57
|
test 'all_root_paths' do
|
|
@@ -64,4 +86,22 @@ class BaseTest < Minitest::Test
|
|
|
64
86
|
end
|
|
65
87
|
end
|
|
66
88
|
end
|
|
89
|
+
|
|
90
|
+
test 'use_oneshot_lines_coverage' do
|
|
91
|
+
refute Coverband.configuration.use_oneshot_lines_coverage
|
|
92
|
+
|
|
93
|
+
Coverband.configuration.stubs(:one_shot_coverage_implemented_in_ruby_version?).returns(true)
|
|
94
|
+
Coverband.configuration.use_oneshot_lines_coverage = true
|
|
95
|
+
assert Coverband.configuration.use_oneshot_lines_coverage
|
|
96
|
+
|
|
97
|
+
Coverband.configuration.use_oneshot_lines_coverage = false
|
|
98
|
+
refute Coverband.configuration.use_oneshot_lines_coverage
|
|
99
|
+
|
|
100
|
+
Coverband.configuration.stubs(:one_shot_coverage_implemented_in_ruby_version?).returns(false)
|
|
101
|
+
exception = assert_raises Exception do
|
|
102
|
+
Coverband.configuration.use_oneshot_lines_coverage = true
|
|
103
|
+
end
|
|
104
|
+
assert_equal 'One shot line coverage is only available in ruby >= 2.6', exception.message
|
|
105
|
+
refute Coverband.configuration.use_oneshot_lines_coverage
|
|
106
|
+
end
|
|
67
107
|
end
|
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
|
4
4
|
|
|
5
5
|
class CoverbandTest < Minitest::Test
|
|
6
|
-
|
|
7
6
|
test 'Coverband#start kicks off background reporting if enabled and not in rack server' do
|
|
8
7
|
Coverband.configuration.stubs(:background_reporting_enabled).returns(:true)
|
|
9
8
|
Coverband::RackServerCheck.expects(:running?).returns(false)
|
|
@@ -24,10 +23,23 @@ class CoverbandTest < Minitest::Test
|
|
|
24
23
|
::Coverband.start
|
|
25
24
|
end
|
|
26
25
|
|
|
26
|
+
test 'Coverband#configured? works' do
|
|
27
|
+
Coverband.configure
|
|
28
|
+
assert Coverband.configured?
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
test 'Eager load coverage block' do
|
|
32
|
+
Coverband.eager_loading_coverage {
|
|
33
|
+
#some code
|
|
34
|
+
1 + 1
|
|
35
|
+
}
|
|
36
|
+
assert_equal :runtime, Coverband.configuration.store.type
|
|
37
|
+
end
|
|
38
|
+
|
|
27
39
|
test 'Eager load coverage' do
|
|
28
40
|
Coverband.eager_loading_coverage!
|
|
29
41
|
assert_equal :eager_loading, Coverband.configuration.store.type
|
|
30
42
|
Coverband.runtime_coverage!
|
|
31
|
-
|
|
43
|
+
assert_equal :runtime, Coverband.configuration.store.type
|
|
32
44
|
end
|
|
33
45
|
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
4
|
+
require 'rack'
|
|
5
|
+
|
|
6
|
+
class BackgroundMiddlewareTest < Minitest::Test
|
|
7
|
+
def setup
|
|
8
|
+
super
|
|
9
|
+
Coverband.configure do |config|
|
|
10
|
+
config.background_reporting_enabled = false
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test 'call app' do
|
|
15
|
+
request = Rack::MockRequest.env_for('/anything.json')
|
|
16
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
|
17
|
+
middleware = Coverband::BackgroundMiddleware.new(fake_app)
|
|
18
|
+
results = middleware.call(request)
|
|
19
|
+
assert_equal '/anything.json', results.last
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
test 'pass all rack lint checks' do
|
|
23
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
|
24
|
+
app = Rack::Lint.new(Coverband::BackgroundMiddleware.new(fake_app))
|
|
25
|
+
env = Rack::MockRequest.env_for('/hello')
|
|
26
|
+
app.call(env)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
test 'starts background reporter when configured' do
|
|
30
|
+
request = Rack::MockRequest.env_for('/anything.json')
|
|
31
|
+
Coverband.configuration.stubs(:background_reporting_enabled).returns(true)
|
|
32
|
+
Coverband::Background.expects(:start)
|
|
33
|
+
middleware = Coverband::BackgroundMiddleware.new(fake_app)
|
|
34
|
+
middleware.call(request)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def fake_app
|
|
40
|
+
@fake_app ||= lambda do |env|
|
|
41
|
+
[200, { 'Content-Type' => 'text/plain' }, env['PATH_INFO']]
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -4,8 +4,7 @@ require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
|
4
4
|
|
|
5
5
|
class BackgroundTest < Minitest::Test
|
|
6
6
|
class ThreadDouble < Struct.new(:alive)
|
|
7
|
-
def exit
|
|
8
|
-
end
|
|
7
|
+
def exit; end
|
|
9
8
|
|
|
10
9
|
def alive?
|
|
11
10
|
alive
|
|
@@ -27,5 +26,4 @@ class BackgroundTest < Minitest::Test
|
|
|
27
26
|
Coverband::Collectors::Coverage.instance.expects(:report_coverage).twice
|
|
28
27
|
2.times { Coverband::Background.start }
|
|
29
28
|
end
|
|
30
|
-
|
|
31
29
|
end
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
4
|
+
require 'coverband/integrations/report_middleware'
|
|
5
|
+
|
|
6
|
+
class ReportMiddlewareTest < Minitest::Test
|
|
7
|
+
def setup
|
|
8
|
+
super
|
|
9
|
+
Coverband.configure do |config|
|
|
10
|
+
config.background_reporting_enabled = false
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
test 'reports coverage' do
|
|
15
|
+
request = Rack::MockRequest.env_for('/anything.json')
|
|
16
|
+
Coverband::Collectors::Coverage.instance.expects(:report_coverage)
|
|
17
|
+
middleware = Coverband::ReportMiddleware.new(fake_app)
|
|
18
|
+
middleware.call(request)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
test 'reports coverage when an error is raised' do
|
|
22
|
+
request = Rack::MockRequest.env_for('/anything.json')
|
|
23
|
+
Coverband::Collectors::Coverage.instance.reset_instance
|
|
24
|
+
Coverband::Collectors::Coverage.instance.expects(:report_coverage).once
|
|
25
|
+
middleware = Coverband::ReportMiddleware.new(fake_app_raise_error)
|
|
26
|
+
begin
|
|
27
|
+
middleware.call(request)
|
|
28
|
+
rescue StandardError
|
|
29
|
+
nil
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def fake_app
|
|
36
|
+
@fake_app ||= lambda do |env|
|
|
37
|
+
[200, { 'Content-Type' => 'text/plain' }, env['PATH_INFO']]
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def fake_app_raise_error
|
|
42
|
+
@fake_app_raise_error ||= -> { raise 'hell' }
|
|
43
|
+
end
|
|
44
|
+
end
|
|
@@ -5,7 +5,7 @@ require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
|
5
5
|
class ResqueWorkerTest < Minitest::Test
|
|
6
6
|
def enqueue_and_run_job
|
|
7
7
|
Resque.enqueue(TestResqueJob)
|
|
8
|
-
queue = ENV['QUEUE'] ='resque_coverband'
|
|
8
|
+
queue = ENV['QUEUE'] = 'resque_coverband'
|
|
9
9
|
worker = Resque::Worker.new
|
|
10
10
|
worker.startup
|
|
11
11
|
worker.work_one_job
|
|
@@ -15,15 +15,15 @@ class ResqueWorkerTest < Minitest::Test
|
|
|
15
15
|
super
|
|
16
16
|
Coverband.configure do |config|
|
|
17
17
|
config.background_reporting_enabled = false
|
|
18
|
-
config.root_paths = ["#{File.expand_path('../', File.dirname(__FILE__))}/"]
|
|
19
18
|
end
|
|
19
|
+
Coverband.configuration.store.instance_variable_set(:@redis_namespace, 'coverband_test')
|
|
20
20
|
Coverband.start
|
|
21
|
-
redis = Coverband.configuration.store.
|
|
21
|
+
redis = Coverband.configuration.store.instance_eval { @redis }
|
|
22
22
|
Resque.redis = redis
|
|
23
23
|
end
|
|
24
24
|
|
|
25
25
|
test 'resque job coverage' do
|
|
26
|
-
relative_job_file = './integrations/test_resque_job.rb'
|
|
26
|
+
relative_job_file = './test/coverband/integrations/test_resque_job.rb'
|
|
27
27
|
resque_job_file = File.expand_path('./test_resque_job.rb', File.dirname(__FILE__))
|
|
28
28
|
require resque_job_file
|
|
29
29
|
|
|
@@ -36,7 +36,7 @@ class ResqueWorkerTest < Minitest::Test
|
|
|
36
36
|
Coverband.runtime_coverage!
|
|
37
37
|
report = Coverband.configuration.store.get_coverage_report
|
|
38
38
|
|
|
39
|
-
assert_equal 0, report[Coverband::EAGER_TYPE][relative_job_file]['data'][
|
|
40
|
-
assert_equal 1, report[Coverband::RUNTIME_TYPE][relative_job_file]['data'][
|
|
39
|
+
assert_equal 0, report[Coverband::EAGER_TYPE][relative_job_file]['data'][6]
|
|
40
|
+
assert_equal 1, report[Coverband::RUNTIME_TYPE][relative_job_file]['data'][6]
|
|
41
41
|
end
|
|
42
42
|
end
|
|
@@ -3,74 +3,6 @@
|
|
|
3
3
|
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
|
4
4
|
|
|
5
5
|
class ReportsBaseTest < Minitest::Test
|
|
6
|
-
test 'relative_path_to_full fix filename from a key with a swappable path' do
|
|
7
|
-
Coverband.configure do |config|
|
|
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)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
6
|
test '#merge_arrays basic merge preserves order and counts' do
|
|
75
7
|
first = [0, 0, 1, 0, 1]
|
|
76
8
|
second = [nil, 0, 1, 0, 0]
|
|
@@ -97,7 +29,7 @@ class ReportsBaseTest < Minitest::Test
|
|
|
97
29
|
|
|
98
30
|
test "#get_current_scov_data_imp doesn't ignore folders with default ignore keys" do
|
|
99
31
|
@redis = Redis.new
|
|
100
|
-
store = Coverband::Adapters::RedisStore.new(@redis)
|
|
32
|
+
store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
|
|
101
33
|
store.clear!
|
|
102
34
|
|
|
103
35
|
Coverband.configure do |config|
|
|
@@ -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
|
|
@@ -8,7 +8,7 @@ class HTMLReportTest < Minitest::Test
|
|
|
8
8
|
def setup
|
|
9
9
|
super
|
|
10
10
|
@redis = Redis.new
|
|
11
|
-
@store = Coverband::Adapters::RedisStore.new(@redis)
|
|
11
|
+
@store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
|
|
12
12
|
@store.clear!
|
|
13
13
|
end
|
|
14
14
|
|
|
@@ -16,14 +16,10 @@ class HTMLReportTest < Minitest::Test
|
|
|
16
16
|
Coverband.configure do |config|
|
|
17
17
|
config.reporter = 'std_out'
|
|
18
18
|
config.store = @store
|
|
19
|
-
config.reporting_frequency = 100.0
|
|
20
19
|
end
|
|
21
20
|
Coverband.configuration.logger.stubs('info')
|
|
22
21
|
mock_file_hash
|
|
23
|
-
Coverband.
|
|
24
|
-
.expects(:current_root)
|
|
25
|
-
.at_least_once
|
|
26
|
-
.returns('app_path')
|
|
22
|
+
Coverband::Utils::RelativeFileConverter.expects(:convert).with('app_path/dog.rb').returns('./dog.rb')
|
|
27
23
|
@store.send(:save_report, basic_coverage)
|
|
28
24
|
|
|
29
25
|
report = Coverband::Reporters::ConsoleReport.report(@store)[:merged]
|
|
@@ -6,40 +6,79 @@ class ReportHTMLTest < Minitest::Test
|
|
|
6
6
|
def setup
|
|
7
7
|
super
|
|
8
8
|
@redis = Redis.new
|
|
9
|
-
@store = Coverband::Adapters::RedisStore.new(@redis)
|
|
9
|
+
@store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
|
|
10
10
|
@store.clear!
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
test 'generate scov html report' do
|
|
14
11
|
Coverband.configure do |config|
|
|
15
|
-
config.reporter = 'scov'
|
|
16
12
|
config.store = @store
|
|
17
|
-
config.
|
|
18
|
-
config.ignore = ['notsomething.rb']
|
|
13
|
+
config.root = fixtures_root
|
|
14
|
+
config.ignore = ['notsomething.rb', 'lib/*']
|
|
19
15
|
end
|
|
20
16
|
mock_file_hash
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
test 'generate dynamic content hosted html report' do
|
|
21
20
|
@store.send(:save_report, basic_coverage)
|
|
22
21
|
|
|
23
22
|
html = Coverband::Reporters::HTMLReport.new(@store,
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
static: false,
|
|
24
|
+
open_report: false).report
|
|
26
25
|
assert_match 'Generated by', html
|
|
27
26
|
end
|
|
28
27
|
|
|
29
|
-
test '
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
test 'files with no Coverage but in project are shown in reports' do
|
|
29
|
+
@store.send(:save_report, basic_source_fixture_coverage)
|
|
30
|
+
|
|
31
|
+
html = Coverband::Reporters::HTMLReport.new(@store,
|
|
32
|
+
static: false,
|
|
33
|
+
open_report: false).report
|
|
34
|
+
assert_match 'sample.rb', html
|
|
35
|
+
# in project, but not in coverage data
|
|
36
|
+
assert_match 'app/models/user.rb', html
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
test 'generate static HTML report file' do
|
|
37
40
|
@store.send(:save_report, basic_coverage)
|
|
38
41
|
|
|
39
42
|
reporter = Coverband::Reporters::HTMLReport.new(@store,
|
|
40
|
-
|
|
43
|
+
static: true,
|
|
41
44
|
open_report: false)
|
|
42
|
-
Coverband::Utils::HTMLFormatter.any_instance.expects(:
|
|
45
|
+
Coverband::Utils::HTMLFormatter.any_instance.expects(:format_static_html!).once
|
|
43
46
|
reporter.report
|
|
44
47
|
end
|
|
48
|
+
|
|
49
|
+
test 'generate dynamic content detailed file report' do
|
|
50
|
+
@store.send(:save_report, basic_coverage_full_path)
|
|
51
|
+
|
|
52
|
+
filename = basic_coverage_file_full_path
|
|
53
|
+
base_path = '/coverage'
|
|
54
|
+
html = Coverband::Reporters::HTMLReport.new(Coverband.configuration.store,
|
|
55
|
+
filename: filename,
|
|
56
|
+
base_path: base_path,
|
|
57
|
+
open_report: false).file_details
|
|
58
|
+
assert_match 'Coverage first seen', html
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
test 'generate dynamic content detailed file report handles missing file' do
|
|
62
|
+
@store.send(:save_report, basic_coverage_full_path)
|
|
63
|
+
|
|
64
|
+
filename = 'missing_path'
|
|
65
|
+
base_path = '/coverage'
|
|
66
|
+
html = Coverband::Reporters::HTMLReport.new(Coverband.configuration.store,
|
|
67
|
+
filename: filename,
|
|
68
|
+
base_path: base_path,
|
|
69
|
+
open_report: false).file_details
|
|
70
|
+
assert_match 'File No Longer Available', html
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
test 'generate dynamic content detailed file report does not allow loading real non project files' do
|
|
74
|
+
@store.send(:save_report, basic_coverage_full_path)
|
|
75
|
+
|
|
76
|
+
filename = "#{test_root}/test_helper.rb"
|
|
77
|
+
base_path = '/coverage'
|
|
78
|
+
html = Coverband::Reporters::HTMLReport.new(Coverband.configuration.store,
|
|
79
|
+
filename: filename,
|
|
80
|
+
base_path: base_path,
|
|
81
|
+
open_report: false).file_details
|
|
82
|
+
assert_match 'File No Longer Available', html
|
|
83
|
+
end
|
|
45
84
|
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
|