coverband 4.2.0 → 4.2.1
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 -1
- data/Gemfile +3 -1
- data/Gemfile.rails4 +1 -0
- data/README.md +40 -15
- data/Rakefile +14 -3
- data/changes.md +47 -12
- data/coverband.gemspec +3 -1
- data/lib/coverband/adapters/base.rb +60 -36
- data/lib/coverband/adapters/file_store.rb +8 -8
- data/lib/coverband/adapters/redis_store.rb +18 -10
- data/lib/coverband/at_exit.rb +2 -11
- data/lib/coverband/collectors/coverage.rb +32 -36
- data/lib/coverband/collectors/delta.rb +34 -28
- data/lib/coverband/configuration.rb +76 -32
- data/lib/coverband/integrations/background.rb +8 -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 +39 -14
- data/lib/coverband/reporters/html_report.rb +21 -27
- data/lib/coverband/reporters/web.rb +13 -21
- data/lib/coverband/utils/file_list.rb +16 -5
- data/lib/coverband/utils/file_path_helper.rb +14 -3
- data/lib/coverband/utils/html_formatter.rb +25 -8
- data/lib/coverband/utils/lines_classifier.rb +5 -0
- data/lib/coverband/utils/railtie.rb +11 -12
- data/lib/coverband/utils/result.rb +1 -37
- data/lib/coverband/utils/results.rb +51 -0
- data/lib/coverband/utils/source_file.rb +31 -6
- data/lib/coverband/utils/tasks.rb +9 -10
- data/lib/coverband/version.rb +1 -1
- data/lib/coverband.rb +32 -21
- data/public/application.js +27 -0
- data/test/benchmarks/benchmark.rake +144 -26
- data/test/coverband/adapters/base_test.rb +73 -42
- data/test/coverband/adapters/file_store_test.rb +48 -37
- data/test/coverband/adapters/redis_store_test.rb +41 -10
- data/test/coverband/at_exit_test.rb +0 -2
- data/test/coverband/collectors/coverage_test.rb +57 -9
- data/test/coverband/collectors/delta_test.rb +36 -6
- 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 +4 -3
- data/test/coverband/integrations/test_resque_job.rb +3 -1
- data/test/coverband/reporters/base_test.rb +4 -4
- data/test/coverband/reporters/console_test.rb +1 -2
- data/test/coverband/reporters/html_test.rb +58 -19
- data/test/coverband/reporters/web_test.rb +0 -10
- data/test/coverband/utils/file_groups_test.rb +11 -5
- data/test/coverband/utils/file_list_test.rb +5 -5
- data/test/coverband/utils/html_formatter_test.rb +43 -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 +40 -0
- data/test/integration/full_stack_test.rb +17 -15
- 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 +42 -4
- 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 +10 -3
- data/views/source_file.erb +13 -4
- data/views/source_file_loader.erb +1 -1
- metadata +52 -9
- data/test/coverband/integrations/middleware_test.rb +0 -96
- data/test/integration/rails_full_stack_test.rb +0 -95
|
@@ -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
|
|
@@ -17,6 +17,7 @@ class ResqueWorkerTest < Minitest::Test
|
|
|
17
17
|
config.background_reporting_enabled = false
|
|
18
18
|
config.root_paths = ["#{File.expand_path('../', File.dirname(__FILE__))}/"]
|
|
19
19
|
end
|
|
20
|
+
Coverband.configuration.store.instance_variable_set(:@redis_namespace, 'coverband_test')
|
|
20
21
|
Coverband.start
|
|
21
22
|
redis = Coverband.configuration.store.send(:redis)
|
|
22
23
|
Resque.redis = redis
|
|
@@ -36,7 +37,7 @@ class ResqueWorkerTest < Minitest::Test
|
|
|
36
37
|
Coverband.runtime_coverage!
|
|
37
38
|
report = Coverband.configuration.store.get_coverage_report
|
|
38
39
|
|
|
39
|
-
assert_equal 0, report[Coverband::EAGER_TYPE][relative_job_file]['data'][
|
|
40
|
-
assert_equal 1, report[Coverband::RUNTIME_TYPE][relative_job_file]['data'][
|
|
40
|
+
assert_equal 0, report[Coverband::EAGER_TYPE][relative_job_file]['data'][6]
|
|
41
|
+
assert_equal 1, report[Coverband::RUNTIME_TYPE][relative_job_file]['data'][6]
|
|
41
42
|
end
|
|
42
43
|
end
|
|
@@ -27,7 +27,7 @@ class ReportsBaseTest < Minitest::Test
|
|
|
27
27
|
|
|
28
28
|
expected_path = '/full/remote_app/path/app/models/user.rb'
|
|
29
29
|
key = '/box/apps/app_name/releases/20140725203539/app/models/user.rb'
|
|
30
|
-
roots = [
|
|
30
|
+
roots = ['/box/apps/app_name/releases/\\d+/', '/full/remote_app/path/']
|
|
31
31
|
File.expects(:exist?).with('/box/apps/app_name/releases/\\d+/app/models/user.rb').returns(false)
|
|
32
32
|
File.expects(:exist?).with(expected_path).returns(true)
|
|
33
33
|
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
|
@@ -53,7 +53,7 @@ class ReportsBaseTest < Minitest::Test
|
|
|
53
53
|
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
|
54
54
|
File.expects(:exist?).with('/var/local/company/company.d/[0-9]*/app/controllers/dashboard_controller.rb').returns(false)
|
|
55
55
|
File.expects(:exist?).with(expected_path).returns(true)
|
|
56
|
-
roots = [
|
|
56
|
+
roots = ['/var/local/company/company.d/[0-9]*/', "#{current_app_root}/"]
|
|
57
57
|
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
|
58
58
|
end
|
|
59
59
|
|
|
@@ -97,7 +97,7 @@ class ReportsBaseTest < Minitest::Test
|
|
|
97
97
|
|
|
98
98
|
test "#get_current_scov_data_imp doesn't ignore folders with default ignore keys" do
|
|
99
99
|
@redis = Redis.new
|
|
100
|
-
store = Coverband::Adapters::RedisStore.new(@redis)
|
|
100
|
+
store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
|
|
101
101
|
store.clear!
|
|
102
102
|
|
|
103
103
|
Coverband.configure do |config|
|
|
@@ -140,7 +140,7 @@ class ReportsBaseTest < Minitest::Test
|
|
|
140
140
|
"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
141
|
}
|
|
142
142
|
@redis = Redis.new
|
|
143
|
-
store = Coverband::Adapters::RedisStore.new(@redis)
|
|
143
|
+
store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
|
|
144
144
|
store.clear!
|
|
145
145
|
|
|
146
146
|
Coverband.configure do |config|
|
|
@@ -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,7 +16,6 @@ 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
|
|
@@ -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
|
|
@@ -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
|
|
@@ -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,43 @@
|
|
|
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
|
+
@redis = Redis.new
|
|
9
|
+
@store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
|
|
10
|
+
@store.clear!
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
test 'generate dynamic content hosted html report' do
|
|
14
|
+
Coverband.configure do |config|
|
|
15
|
+
config.store = @store
|
|
16
|
+
config.ignore = ['notsomething.rb']
|
|
17
|
+
end
|
|
18
|
+
mock_file_hash
|
|
19
|
+
@store.send(:save_report, basic_coverage_full_path)
|
|
20
|
+
|
|
21
|
+
notice = nil
|
|
22
|
+
base_path = '/coverage'
|
|
23
|
+
filtered_report_files = Coverband::Reporters::Base.report(@store, {})
|
|
24
|
+
html = Coverband::Utils::HTMLFormatter.new(filtered_report_files,
|
|
25
|
+
base_path: base_path,
|
|
26
|
+
notice: notice).format_dynamic_html!
|
|
27
|
+
assert_match 'loading source data', html
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
test 'generate static HTML report file' do
|
|
31
|
+
Coverband.configure do |config|
|
|
32
|
+
config.store = @store
|
|
33
|
+
config.ignore = ['notsomething.rb']
|
|
34
|
+
end
|
|
35
|
+
mock_file_hash
|
|
36
|
+
@store.send(:save_report, basic_coverage_full_path)
|
|
37
|
+
|
|
38
|
+
filtered_report_files = Coverband::Reporters::Base.report(@store, {})
|
|
39
|
+
Coverband::Utils::HTMLFormatter.new(filtered_report_files).format_static_html!
|
|
40
|
+
html = File.read("#{Coverband.configuration.root}/coverage/index.html")
|
|
41
|
+
assert_match 'Coverage first seen', html
|
|
42
|
+
end
|
|
43
|
+
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
|
|
@@ -146,4 +146,54 @@ describe Coverband::Utils::SourceFile do
|
|
|
146
146
|
assert_equal 0.0, subject.covered_percent
|
|
147
147
|
end
|
|
148
148
|
end
|
|
149
|
+
|
|
150
|
+
describe 'correctly identifies gems' do
|
|
151
|
+
COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB = [nil, nil, 1, 1, 0, 1, 1, nil].freeze
|
|
152
|
+
|
|
153
|
+
describe 'the word gem in a path' do
|
|
154
|
+
subject do
|
|
155
|
+
Coverband::Utils::SourceFile.new('lib/rubocop/cop/gemspec/required_ruby_version.rb', COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
it 'allows the word gem in path' do
|
|
159
|
+
assert_equal nil, subject.gem?
|
|
160
|
+
end
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
describe 'a folder gem in the path' do
|
|
164
|
+
subject do
|
|
165
|
+
Coverband::Utils::SourceFile.new('/var/gems/rubocop-0.67.0/lib/rubocop/cop/gemspec/required_ruby_version.rb', COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
it 'allows the word gem in path' do
|
|
169
|
+
assert subject.gem?
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
describe 'correctly reports gem name' do
|
|
175
|
+
COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB = [nil, nil, 1, 1, 0, 1, 1, nil].freeze
|
|
176
|
+
|
|
177
|
+
describe 'the word gem in a path' do
|
|
178
|
+
subject do
|
|
179
|
+
Coverband::Utils::SourceFile.new('lib/rubocop/cop/gemspec/required_ruby_version.rb', COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB)
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
it 'allows the word gem in path' do
|
|
183
|
+
assert_equal nil, subject.gem_name
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
describe 'a folder gem in the path' do
|
|
188
|
+
subject do
|
|
189
|
+
Coverband::Utils::SourceFile.new('/var/gems/rubocop-0.67.0/lib/rubocop/cop/gemspec/required_ruby_version.rb', COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
it 'allows the word gem in path' do
|
|
193
|
+
assert_equal 'rubocop-0.67.0', subject.gem_name
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
|
|
149
199
|
end
|