coverband 4.2.0 → 4.2.1.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +29 -9
- data/.travis.yml +9 -1
- data/Gemfile +2 -1
- data/Gemfile.rails4 +1 -0
- data/README.md +34 -13
- data/Rakefile +10 -2
- data/changes.md +25 -10
- data/coverband.gemspec +5 -1
- data/lib/coverband.rb +30 -18
- data/lib/coverband/adapters/base.rb +2 -7
- data/lib/coverband/adapters/file_store.rb +1 -1
- data/lib/coverband/at_exit.rb +2 -11
- data/lib/coverband/collectors/coverage.rb +29 -32
- data/lib/coverband/collectors/delta.rb +20 -24
- data/lib/coverband/configuration.rb +49 -19
- data/lib/coverband/integrations/background.rb +6 -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 -13
- data/lib/coverband/reporters/html_report.rb +21 -27
- data/lib/coverband/reporters/web.rb +2 -21
- data/lib/coverband/utils/file_list.rb +16 -5
- data/lib/coverband/utils/file_path_helper.rb +2 -0
- 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 +5 -44
- data/lib/coverband/utils/results.rb +51 -0
- data/lib/coverband/utils/source_file.rb +29 -5
- data/lib/coverband/utils/tasks.rb +11 -2
- data/lib/coverband/version.rb +1 -1
- data/public/application.js +27 -0
- data/test/benchmarks/benchmark.rake +10 -20
- data/test/coverband/adapters/file_store_test.rb +5 -5
- data/test/coverband/adapters/redis_store_test.rb +8 -7
- 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 +27 -6
- data/test/coverband/configuration_test.rb +47 -7
- data/test/coverband/coverband_test.rb +0 -1
- 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 +79 -16
- data/test/coverband/reporters/web_test.rb +0 -10
- data/test/coverband/utils/file_groups_test.rb +1 -1
- data/test/coverband/utils/file_list_test.rb +5 -5
- data/test/coverband/utils/html_formatter_test.rb +45 -0
- data/test/coverband/utils/result_test.rb +27 -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/forked/rails_full_stack_test.rb +101 -0
- data/test/forked/rails_rake_full_stack_test.rb +32 -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 +3 -3
- data/test/rails5_dummy/Rakefile +6 -0
- data/test/rails5_dummy/config/application.rb +6 -10
- data/test/rails5_dummy/config/coverband.rb +2 -2
- data/test/rails_test_helper.rb +23 -4
- data/test/test_helper.rb +26 -1
- data/test/unique_files.rb +6 -5
- 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 +79 -9
- data/test/coverband/integrations/middleware_test.rb +0 -96
- data/test/integration/rails_full_stack_test.rb +0 -95
@@ -1,96 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
4
|
-
require 'rack'
|
5
|
-
|
6
|
-
class MiddlewareTest < Minitest::Test
|
7
|
-
REDIS_STORAGE_FORMAT_VERSION = Coverband::Adapters::RedisStore::REDIS_STORAGE_FORMAT_VERSION
|
8
|
-
|
9
|
-
def setup
|
10
|
-
super
|
11
|
-
Coverband.configure do |config|
|
12
|
-
config.store = Coverband::Adapters::RedisStore.new(Redis.new)
|
13
|
-
config.background_reporting_enabled = false
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
test 'call app' do
|
18
|
-
request = Rack::MockRequest.env_for('/anything.json')
|
19
|
-
Coverband::Collectors::Coverage.instance.reset_instance
|
20
|
-
middleware = Coverband::Middleware.new(fake_app)
|
21
|
-
results = middleware.call(request)
|
22
|
-
assert_equal '/anything.json', results.last
|
23
|
-
end
|
24
|
-
|
25
|
-
test 'pass all rack lint checks' do
|
26
|
-
Coverband::Collectors::Coverage.instance.reset_instance
|
27
|
-
app = Rack::Lint.new(Coverband::Middleware.new(fake_app))
|
28
|
-
env = Rack::MockRequest.env_for('/hello')
|
29
|
-
app.call(env)
|
30
|
-
end
|
31
|
-
|
32
|
-
test 'starts background reporter when configured' do
|
33
|
-
request = Rack::MockRequest.env_for('/anything.json')
|
34
|
-
Coverband.configuration.stubs(:background_reporting_enabled).returns(true)
|
35
|
-
Coverband::Collectors::Coverage.instance.expects(:report_coverage).never
|
36
|
-
Coverband::Background.expects(:start)
|
37
|
-
middleware = Coverband::Middleware.new(fake_app)
|
38
|
-
middleware.call(request)
|
39
|
-
end
|
40
|
-
|
41
|
-
test 'reports coverage when not set to background mode' do
|
42
|
-
request = Rack::MockRequest.env_for('/anything.json')
|
43
|
-
Coverband.configuration.stubs(:background_reporting_enabled).returns(false)
|
44
|
-
Coverband::Collectors::Coverage.instance.expects(:report_coverage)
|
45
|
-
Coverband::Background.expects(:start).never
|
46
|
-
middleware = Coverband::Middleware.new(fake_app)
|
47
|
-
middleware.call(request)
|
48
|
-
end
|
49
|
-
|
50
|
-
test 'never be report coverage with reporting_frequency of 0' do
|
51
|
-
request = Rack::MockRequest.env_for('/anything.json')
|
52
|
-
Coverband::Collectors::Coverage.instance.reset_instance
|
53
|
-
collector = Coverband::Collectors::Coverage.instance
|
54
|
-
collector.instance_variable_set('@reporting_frequency', 0.0)
|
55
|
-
middleware = Coverband::Middleware.new(fake_app)
|
56
|
-
store = Coverband::Collectors::Coverage.instance.instance_variable_get('@store')
|
57
|
-
store.expects(:save_report).never
|
58
|
-
middleware.call(request)
|
59
|
-
end
|
60
|
-
|
61
|
-
test 'always be enabled with sample percentage of 100' do
|
62
|
-
request = Rack::MockRequest.env_for('/anything.json')
|
63
|
-
Coverband::Collectors::Coverage.instance.reset_instance
|
64
|
-
collector = Coverband::Collectors::Coverage.instance
|
65
|
-
collector.report_coverage(true)
|
66
|
-
collector.instance_variable_set('@reporting_frequency', 100.0)
|
67
|
-
middleware = Coverband::Middleware.new(fake_app)
|
68
|
-
store = Coverband::Collectors::Coverage.instance.instance_variable_get('@store')
|
69
|
-
store.expects(:save_report).once
|
70
|
-
middleware.call(request)
|
71
|
-
end
|
72
|
-
|
73
|
-
test 'reports coverage when an error is raised' do
|
74
|
-
request = Rack::MockRequest.env_for('/anything.json')
|
75
|
-
Coverband::Collectors::Coverage.instance.reset_instance
|
76
|
-
Coverband::Collectors::Coverage.instance.expects(:report_coverage).once
|
77
|
-
middleware = Coverband::Middleware.new(fake_app_raise_error)
|
78
|
-
begin
|
79
|
-
middleware.call(request)
|
80
|
-
rescue StandardError
|
81
|
-
nil
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
def fake_app
|
88
|
-
@fake_app ||= lambda do |env|
|
89
|
-
[200, { 'Content-Type' => 'text/plain' }, env['PATH_INFO']]
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
def fake_app_raise_error
|
94
|
-
@fake_app_raise_error ||= -> { raise 'hell' }
|
95
|
-
end
|
96
|
-
end
|
@@ -1,95 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require File.expand_path('../rails_test_helper', File.dirname(__FILE__))
|
4
|
-
|
5
|
-
class RailsFullStackTest < Minitest::Test
|
6
|
-
include Capybara::DSL
|
7
|
-
include Capybara::Minitest::Assertions
|
8
|
-
|
9
|
-
def setup
|
10
|
-
super
|
11
|
-
rails_setup
|
12
|
-
# preload first coverage hit
|
13
|
-
Coverband::Collectors::Coverage.instance.report_coverage(true)
|
14
|
-
require 'rainbow'
|
15
|
-
Rainbow('this text is red').red
|
16
|
-
end
|
17
|
-
|
18
|
-
def teardown
|
19
|
-
super
|
20
|
-
Capybara.reset_sessions!
|
21
|
-
Capybara.use_default_driver
|
22
|
-
end
|
23
|
-
|
24
|
-
# We have to combine everything in one test
|
25
|
-
# because we can only initialize rails once per test
|
26
|
-
# run. Possibly fork test runs to avoid this problem in future?
|
27
|
-
test 'this is how we do it' do
|
28
|
-
visit '/dummy/show'
|
29
|
-
Coverband.report_coverage(true)
|
30
|
-
assert_content('I am no dummy')
|
31
|
-
visit '/coverage'
|
32
|
-
within page.find('a', text: /dummy_controller.rb/).find(:xpath, '../..') do
|
33
|
-
assert_selector('td', text: '100.0 %')
|
34
|
-
end
|
35
|
-
|
36
|
-
#Test gems are reporting coverage
|
37
|
-
assert_content('Gems')
|
38
|
-
assert page.html.match('rainbow/wrapper.rb')
|
39
|
-
|
40
|
-
#Test eager load data stored separately
|
41
|
-
dummy_controller = "./test/rails#{Rails::VERSION::MAJOR}_dummy/app/controllers/dummy_controller.rb"
|
42
|
-
store.type = :eager_loading
|
43
|
-
eager_expected = [1, 1, 0, nil, nil]
|
44
|
-
results = store.coverage[dummy_controller]['data']
|
45
|
-
assert_equal(eager_expected, results)
|
46
|
-
|
47
|
-
store.type = nil
|
48
|
-
runtime_expected = [0, 0, 1, nil, nil]
|
49
|
-
results = store.coverage[dummy_controller]['data']
|
50
|
-
end
|
51
|
-
|
52
|
-
###
|
53
|
-
# Please keep this test starting on line 22
|
54
|
-
# as we run it in single test mode via the benchmarks.
|
55
|
-
# Add new tests below this test
|
56
|
-
###
|
57
|
-
test 'memory usage' do
|
58
|
-
return unless ENV['COVERBAND_MEMORY_TEST']
|
59
|
-
# we don't want this to run during our standard test suite
|
60
|
-
# as the below profiler changes the runtime
|
61
|
-
# and shold only be included for isolated processes
|
62
|
-
begin
|
63
|
-
require 'memory_profiler'
|
64
|
-
|
65
|
-
# warmup
|
66
|
-
3.times do
|
67
|
-
visit '/dummy/show'
|
68
|
-
assert_content('I am no dummy')
|
69
|
-
Coverband.report_coverage(true)
|
70
|
-
end
|
71
|
-
|
72
|
-
previous_out = $stdout
|
73
|
-
capture = StringIO.new
|
74
|
-
$stdout = capture
|
75
|
-
|
76
|
-
MemoryProfiler.report do
|
77
|
-
15.times do
|
78
|
-
visit '/dummy/show'
|
79
|
-
assert_content('I am no dummy')
|
80
|
-
Coverband.report_coverage(true)
|
81
|
-
# this is expected to retain memory across requests
|
82
|
-
# clear it to remove the false positive from test
|
83
|
-
Coverband::Collectors::Coverage.instance.send(:add_previous_results, nil)
|
84
|
-
end
|
85
|
-
end.pretty_print
|
86
|
-
data = $stdout.string
|
87
|
-
$stdout = previous_out
|
88
|
-
if data.match(/retained objects by gem(.*)retained objects by file/m)[0]&.match(/coverband/)
|
89
|
-
raise 'leaking memory!!!'
|
90
|
-
end
|
91
|
-
ensure
|
92
|
-
$stdout = previous_out
|
93
|
-
end
|
94
|
-
end
|
95
|
-
end
|