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.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +29 -9
  3. data/.travis.yml +9 -1
  4. data/Gemfile +2 -1
  5. data/Gemfile.rails4 +1 -0
  6. data/README.md +34 -13
  7. data/Rakefile +10 -2
  8. data/changes.md +25 -10
  9. data/coverband.gemspec +5 -1
  10. data/lib/coverband.rb +30 -18
  11. data/lib/coverband/adapters/base.rb +2 -7
  12. data/lib/coverband/adapters/file_store.rb +1 -1
  13. data/lib/coverband/at_exit.rb +2 -11
  14. data/lib/coverband/collectors/coverage.rb +29 -32
  15. data/lib/coverband/collectors/delta.rb +20 -24
  16. data/lib/coverband/configuration.rb +49 -19
  17. data/lib/coverband/integrations/background.rb +6 -4
  18. data/lib/coverband/integrations/{middleware.rb → background_middleware.rb} +2 -6
  19. data/lib/coverband/integrations/bundler.rb +8 -0
  20. data/lib/coverband/integrations/report_middleware.rb +15 -0
  21. data/lib/coverband/integrations/resque.rb +3 -5
  22. data/lib/coverband/reporters/base.rb +39 -13
  23. data/lib/coverband/reporters/html_report.rb +21 -27
  24. data/lib/coverband/reporters/web.rb +2 -21
  25. data/lib/coverband/utils/file_list.rb +16 -5
  26. data/lib/coverband/utils/file_path_helper.rb +2 -0
  27. data/lib/coverband/utils/html_formatter.rb +25 -8
  28. data/lib/coverband/utils/lines_classifier.rb +5 -0
  29. data/lib/coverband/utils/railtie.rb +11 -12
  30. data/lib/coverband/utils/result.rb +5 -44
  31. data/lib/coverband/utils/results.rb +51 -0
  32. data/lib/coverband/utils/source_file.rb +29 -5
  33. data/lib/coverband/utils/tasks.rb +11 -2
  34. data/lib/coverband/version.rb +1 -1
  35. data/public/application.js +27 -0
  36. data/test/benchmarks/benchmark.rake +10 -20
  37. data/test/coverband/adapters/file_store_test.rb +5 -5
  38. data/test/coverband/adapters/redis_store_test.rb +8 -7
  39. data/test/coverband/at_exit_test.rb +0 -2
  40. data/test/coverband/collectors/coverage_test.rb +57 -9
  41. data/test/coverband/collectors/delta_test.rb +27 -6
  42. data/test/coverband/configuration_test.rb +47 -7
  43. data/test/coverband/coverband_test.rb +0 -1
  44. data/test/coverband/integrations/background_middleware_test.rb +44 -0
  45. data/test/coverband/integrations/background_test.rb +1 -3
  46. data/test/coverband/integrations/report_middleware_test.rb +44 -0
  47. data/test/coverband/integrations/resque_worker_test.rb +4 -3
  48. data/test/coverband/integrations/test_resque_job.rb +3 -1
  49. data/test/coverband/reporters/base_test.rb +4 -4
  50. data/test/coverband/reporters/console_test.rb +1 -2
  51. data/test/coverband/reporters/html_test.rb +79 -16
  52. data/test/coverband/reporters/web_test.rb +0 -10
  53. data/test/coverband/utils/file_groups_test.rb +1 -1
  54. data/test/coverband/utils/file_list_test.rb +5 -5
  55. data/test/coverband/utils/html_formatter_test.rb +45 -0
  56. data/test/coverband/utils/result_test.rb +27 -47
  57. data/test/coverband/utils/results_test.rb +54 -0
  58. data/test/coverband/utils/s3_report_test.rb +2 -0
  59. data/test/coverband/utils/source_file_test.rb +50 -0
  60. data/test/forked/rails_full_stack_test.rb +101 -0
  61. data/test/forked/rails_rake_full_stack_test.rb +32 -0
  62. data/test/integration/full_stack_test.rb +17 -15
  63. data/test/rails4_dummy/Rakefile +6 -0
  64. data/test/rails4_dummy/config/application.rb +8 -9
  65. data/test/rails4_dummy/config/coverband.rb +3 -3
  66. data/test/rails5_dummy/Rakefile +6 -0
  67. data/test/rails5_dummy/config/application.rb +6 -10
  68. data/test/rails5_dummy/config/coverband.rb +2 -2
  69. data/test/rails_test_helper.rb +23 -4
  70. data/test/test_helper.rb +26 -1
  71. data/test/unique_files.rb +6 -5
  72. data/views/file_list.erb +2 -2
  73. data/views/gem_list.erb +10 -1
  74. data/views/layout.erb +10 -3
  75. data/views/source_file.erb +13 -4
  76. data/views/source_file_loader.erb +1 -1
  77. metadata +79 -9
  78. data/test/coverband/integrations/middleware_test.rb +0 -96
  79. data/test/integration/rails_full_stack_test.rb +0 -95
@@ -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
@@ -50,6 +50,6 @@ describe Coverband::Utils::FileGroups, :vendored_gems do
50
50
  end
51
51
 
52
52
  it 'does has gem files' do
53
- assert_equal 'gem_name.rb', subject.grouped_results['Gems'].first.first.short_name
53
+ assert_equal '.gem_name.rb', subject.grouped_results['Gems'].first.first.short_name
54
54
  end
55
55
  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,45 @@
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.s3_bucket = nil
17
+ config.ignore = ['notsomething.rb']
18
+ end
19
+ mock_file_hash
20
+ @store.send(:save_report, basic_coverage_full_path)
21
+
22
+ notice = nil
23
+ base_path = '/coverage'
24
+ filtered_report_files = Coverband::Reporters::Base.report(@store, {})
25
+ html = Coverband::Utils::HTMLFormatter.new(filtered_report_files,
26
+ base_path: base_path,
27
+ notice: notice).format_dynamic_html!
28
+ assert_match 'loading source data', html
29
+ end
30
+
31
+ test 'generate static HTML report file' do
32
+ Coverband.configure do |config|
33
+ config.store = @store
34
+ config.s3_bucket = nil
35
+ config.ignore = ['notsomething.rb']
36
+ end
37
+ mock_file_hash
38
+ @store.send(:save_report, basic_coverage_full_path)
39
+
40
+ filtered_report_files = Coverband::Reporters::Base.report(@store, {})
41
+ Coverband::Utils::HTMLFormatter.new(filtered_report_files).format_static_html!
42
+ html = File.read("#{Coverband.configuration.root}/coverage/index.html")
43
+ assert_match 'Coverage first seen', html
44
+ end
45
+ end
@@ -16,6 +16,27 @@ describe 'result' do
16
16
  }
17
17
  end
18
18
 
19
+ describe '#add_not_loaded_files' do
20
+ it 'Adds files not yet tracked' do
21
+ results = Coverband::Utils::Result.add_not_loaded_files({}, ['./test/dog.*'])
22
+ dog_file = results.keys.grep(/dog.rb/).first
23
+ assert dog_file
24
+ end
25
+
26
+ it 'Does not overrwrite existing coverage' do
27
+ dog_file = File.expand_path('./test/dog.rb')
28
+ results = Coverband::Utils::Result.add_not_loaded_files({ dog_file => [0, 1] }, ['./test/dog.*'])
29
+ assert_equal({ dog_file => [0, 1] }, results)
30
+ end
31
+
32
+ it 'Adds files not yet tracked from multiple file globs' do
33
+ dog_file = File.expand_path('./test/dog.rb')
34
+ test_helper_file = File.expand_path('./test/test_helper.rb')
35
+ results = Coverband::Utils::Result.add_not_loaded_files({}, ['./test/dog.*', './test/test_helper.rb'])
36
+ assert_equal [dog_file, test_helper_file].to_set, results.keys.to_set
37
+ end
38
+ end
39
+
19
40
  describe 'a simple cov result initialized from that' do
20
41
  subject { Coverband::Utils::Result.new(original_result) }
21
42
 
@@ -48,57 +69,16 @@ describe 'result' do
48
69
  assert_equal [80.0, 80.0, 100.0], subject.covered_percentages
49
70
  end
50
71
 
51
- it 'has accurate least covered file' do
52
- assert subject.least_covered_file.match(/sample_controller.rb/)
53
- end
54
-
55
- [:covered_percent,
56
- :covered_percentages,
57
- :least_covered_file,
58
- :covered_strength,
59
- :covered_lines,
60
- :missed_lines,
61
- :total_lines].each do |msg|
72
+ %i[covered_percent
73
+ covered_percentages
74
+ covered_strength
75
+ covered_lines
76
+ missed_lines
77
+ total_lines].each do |msg|
62
78
  it "responds to #{msg}" do
63
79
  assert(subject.respond_to?(msg))
64
80
  end
65
81
  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
82
  end
103
83
  end
104
84
  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
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.expand_path('../../test_helper', File.dirname(__FILE__))
2
4
 
3
5
  module Coverband
@@ -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
@@ -0,0 +1,101 @@
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.report_coverage
14
+ end
15
+
16
+ def teardown
17
+ super
18
+ Capybara.reset_sessions!
19
+ Capybara.use_default_driver
20
+ end
21
+
22
+ test 'list all gems even if no coverage' do
23
+ Capybara.current_driver = :selenium_chrome_headless
24
+ visit '/coverage'
25
+ find('a.Gems').click
26
+ assert_selector('a.gem-link', text: /pundit/)
27
+ assert_selector('a.gem-link', text: /rainbow/)
28
+ end
29
+
30
+ test 'this is how we do it' do
31
+ require 'rainbow'
32
+ Rainbow('this text is red').red
33
+ visit '/dummy/show'
34
+ Coverband.report_coverage
35
+ assert_content('I am no dummy')
36
+ visit '/coverage'
37
+ within page.find('a', text: /dummy_controller.rb/).find(:xpath, '../..') do
38
+ assert_selector('td', text: '100.0 %')
39
+ end
40
+
41
+ # Test gems are reporting coverage
42
+ assert_content('Gems')
43
+ assert page.html.match('rainbow/wrapper.rb')
44
+
45
+ # Test eager load data stored separately
46
+ dummy_controller = "./test/rails#{Rails::VERSION::MAJOR}_dummy/app/controllers/dummy_controller.rb"
47
+ store.type = :eager_loading
48
+ eager_expected = [1, 1, 0, nil, nil]
49
+ results = store.coverage[dummy_controller]['data']
50
+ assert_equal(eager_expected, results)
51
+
52
+ store.type = nil
53
+ runtime_expected = [0, 0, 1, nil, nil]
54
+ results = store.coverage[dummy_controller]['data']
55
+ end
56
+
57
+ ###
58
+ # Please keep this test starting on line 22
59
+ # as we run it in single test mode via the benchmarks.
60
+ # Add new tests below this test
61
+ ###
62
+ if ENV['COVERBAND_MEMORY_TEST']
63
+ test 'memory usage' do
64
+ return unless ENV['COVERBAND_MEMORY_TEST']
65
+
66
+ # we don't want this to run during our standard test suite
67
+ # as the below profiler changes the runtime
68
+ # and shold only be included for isolated processes
69
+ begin
70
+ require 'memory_profiler'
71
+
72
+ # warmup
73
+ 3.times do
74
+ visit '/dummy/show'
75
+ assert_content('I am no dummy')
76
+ Coverband.report_coverage
77
+ end
78
+
79
+ previous_out = $stdout
80
+ capture = StringIO.new
81
+ $stdout = capture
82
+
83
+ MemoryProfiler.report do
84
+ 15.times do
85
+ visit '/dummy/show'
86
+ assert_content('I am no dummy')
87
+ Coverband.report_coverage
88
+ # this is expected to retain memory across requests
89
+ # clear it to remove the false positive from test
90
+ Coverband::Collectors::Coverage.instance.send(:add_previous_results, nil)
91
+ end
92
+ end.pretty_print
93
+ data = $stdout.string
94
+ $stdout = previous_out
95
+ raise 'leaking memory!!!' if data.match(/retained objects by gem(.*)retained objects by file/m)[0]&.match(/coverband/)
96
+ ensure
97
+ $stdout = previous_out
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,32 @@
1
+ require File.expand_path('../rails_test_helper', File.dirname(__FILE__))
2
+ require 'rails'
3
+
4
+ class RailsRakeFullStackTest < Minitest::Test
5
+
6
+ test 'rake tasks shows coverage properly within eager_loading' do
7
+ system("COVERBAND_CONFIG=./test/rails#{Rails::VERSION::MAJOR}_dummy/config/coverband.rb bundle exec rake -f test/rails#{Rails::VERSION::MAJOR}_dummy/Rakefile middleware")
8
+ store.instance_variable_set(:@redis_namespace, 'coverband_test')
9
+ store.type = :eager_loading
10
+ pundit_file = store.coverage.keys.grep(/pundit.rb/).first
11
+ refute_nil pundit_file
12
+ pundit_coverage = store.coverage[pundit_file]
13
+ refute_nil pundit_coverage
14
+ assert_includes pundit_coverage['data'], 1
15
+
16
+ store.type = nil
17
+ pundit_coverage = store.coverage[pundit_file]
18
+ assert_nil pundit_coverage
19
+ end
20
+
21
+ test "ignored rake tasks don't add coverage" do
22
+ store.instance_variable_set(:@redis_namespace, 'coverband_test')
23
+ store.send(:save_report, basic_coverage_full_path)
24
+ output = `COVERBAND_CONFIG=./test/rails#{Rails::VERSION::MAJOR}_dummy/config/coverband.rb bundle exec rake -f test/rails#{Rails::VERSION::MAJOR}_dummy/Rakefile coverband:clear`
25
+ assert_nil output.match(/Coverband: Reported coverage via thread/)
26
+ coverage_report = store.get_coverage_report
27
+ empty_hash = {}
28
+ assert_equal empty_hash, coverage_report[nil]
29
+ assert_equal empty_hash, coverage_report[:eager_loading]
30
+ assert_equal empty_hash, coverage_report[:merged]
31
+ end
32
+ end
@@ -6,52 +6,54 @@ require 'rack'
6
6
  class FullStackTest < Minitest::Test
7
7
  REDIS_STORAGE_FORMAT_VERSION = Coverband::Adapters::RedisStore::REDIS_STORAGE_FORMAT_VERSION
8
8
  TEST_RACK_APP = '../fake_app/basic_rack.rb'
9
- RELATIVE_FILE = './fake_app/basic_rack.rb'
10
9
 
11
10
  def setup
12
11
  super
13
12
  Coverband::Collectors::Coverage.instance.reset_instance
14
13
  Coverband.configure do |config|
15
- config.reporting_frequency = 100.0
16
- config.store = Coverband::Adapters::RedisStore.new(Redis.new)
14
+ config.store = Coverband::Adapters::RedisStore.new(Redis.new(), redis_namespace: 'coverband_test')
17
15
  config.s3_bucket = nil
18
- config.background_reporting_enabled = false
16
+ config.background_reporting_enabled = true
19
17
  config.root_paths = ["#{File.expand_path('../', File.dirname(__FILE__))}/"]
20
18
  config.track_gems = true
21
19
  end
22
20
  Coverband.configuration.store.clear!
23
21
  Coverband.start
22
+ Coverband::Collectors::Coverage.instance.eager_loading!
23
+ @rack_file = require_unique_file 'fake_app/basic_rack.rb'
24
+ Coverband.report_coverage
24
25
  Coverband::Collectors::Coverage.instance.runtime!
25
- @rack_file = File.expand_path(TEST_RACK_APP, File.dirname(__FILE__))
26
- require @rack_file
27
- # preload first coverage hit
28
- Coverband::Collectors::Coverage.instance.report_coverage(true)
29
26
  end
30
27
 
31
28
  test 'call app' do
32
29
  request = Rack::MockRequest.env_for('/anything.json')
33
- middleware = Coverband::Middleware.new(fake_app_with_lines)
30
+ middleware = Coverband::BackgroundMiddleware.new(fake_app_with_lines)
34
31
  results = middleware.call(request)
35
32
  assert_equal 'Hello Rack!', results.last
36
- sleep(0.2)
33
+ Coverband.report_coverage
37
34
  expected = [nil, nil, 0, nil, 0, 0, 1, nil, nil]
38
- assert_equal expected, Coverband.configuration.store.coverage[RELATIVE_FILE]['data']
35
+ assert_equal expected, Coverband.configuration.store.coverage[@rack_file]['data']
39
36
 
40
37
  # additional calls increase count by 1
41
38
  middleware.call(request)
42
- sleep(0.2)
39
+ Coverband.report_coverage
43
40
  expected = [nil, nil, 0, nil, 0, 0, 2, nil, nil]
44
- assert_equal expected, Coverband.configuration.store.coverage[RELATIVE_FILE]['data']
41
+ assert_equal expected, Coverband.configuration.store.coverage[@rack_file]['data']
42
+
43
+ # class coverage
44
+ Coverband.eager_loading_coverage!
45
+ Coverband.configuration.store.coverage[@rack_file]['data']
46
+ expected = [nil, nil, 1, nil, 1, 1, 0, nil, nil]
45
47
  end
46
48
 
47
49
  test 'call app with gem tracking' do
48
50
  require 'rainbow'
49
51
  Rainbow('this text is red').red
50
52
  request = Rack::MockRequest.env_for('/anything.json')
51
- middleware = Coverband::Middleware.new(fake_app_with_lines)
53
+ middleware = Coverband::BackgroundMiddleware.new(fake_app_with_lines)
52
54
  results = middleware.call(request)
53
55
  assert_equal 'Hello Rack!', results.last
54
- sleep(0.1)
56
+ Coverband.report_coverage
55
57
  assert Coverband.configuration.store.coverage.keys.any? { |key| key.end_with?('rainbow/global.rb') }
56
58
  end
57
59