coverband 4.0.1 → 4.2.0

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.
Files changed (90) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +6 -1
  3. data/.travis.yml +8 -2
  4. data/Gemfile +2 -0
  5. data/Gemfile.rails4 +2 -0
  6. data/README.md +135 -157
  7. data/Rakefile +1 -1
  8. data/changes.md +56 -5
  9. data/coverband.gemspec +5 -3
  10. data/lib/coverband/adapters/base.rb +44 -11
  11. data/lib/coverband/adapters/file_store.rb +8 -0
  12. data/lib/coverband/adapters/redis_store.rb +65 -8
  13. data/lib/coverband/at_exit.rb +37 -0
  14. data/lib/coverband/collectors/coverage.rb +43 -72
  15. data/lib/coverband/collectors/delta.rb +67 -0
  16. data/lib/coverband/configuration.rb +71 -2
  17. data/lib/coverband/integrations/background.rb +9 -10
  18. data/lib/coverband/integrations/middleware.rb +3 -2
  19. data/lib/coverband/integrations/rack_server_check.rb +4 -1
  20. data/lib/coverband/integrations/resque.rb +27 -0
  21. data/lib/coverband/reporters/base.rb +24 -36
  22. data/lib/coverband/reporters/html_report.rb +40 -15
  23. data/lib/coverband/reporters/web.rb +52 -10
  24. data/lib/coverband/utils/file_groups.rb +53 -0
  25. data/lib/coverband/utils/file_path_helper.rb +57 -0
  26. data/lib/coverband/utils/gem_list.rb +31 -0
  27. data/lib/coverband/utils/html_formatter.rb +50 -8
  28. data/lib/coverband/utils/railtie.rb +9 -1
  29. data/lib/coverband/utils/result.rb +16 -19
  30. data/lib/coverband/utils/results.rb +63 -0
  31. data/lib/coverband/utils/source_file.rb +23 -1
  32. data/lib/coverband/utils/tasks.rb +17 -17
  33. data/lib/coverband/version.rb +1 -1
  34. data/lib/coverband.rb +32 -2
  35. data/public/application.css +5 -0
  36. data/public/application.js +117 -1640
  37. data/public/dependencies.js +1581 -0
  38. data/public/favicon.png +0 -0
  39. data/test/benchmarks/benchmark.rake +36 -1
  40. data/test/benchmarks/coverage_fork.sh +37 -0
  41. data/test/{unit/adapters_base_test.rb → coverband/adapters/base_test.rb} +1 -1
  42. data/test/{unit/adapters_file_store_test.rb → coverband/adapters/file_store_test.rb} +1 -1
  43. data/test/{unit/adapters_redis_store_test.rb → coverband/adapters/redis_store_test.rb} +28 -11
  44. data/test/coverband/at_exit_test.rb +13 -0
  45. data/test/coverband/collectors/coverage_test.rb +73 -0
  46. data/test/coverband/collectors/delta_test.rb +52 -0
  47. data/test/coverband/configuration_test.rb +67 -0
  48. data/test/{unit → coverband}/coverband_test.rb +7 -0
  49. data/test/coverband/integrations/background_test.rb +31 -0
  50. data/test/{unit → coverband/integrations}/middleware_test.rb +3 -2
  51. data/test/{unit/rack_server_checkout_test.rb → coverband/integrations/rack_server_check_test.rb} +1 -1
  52. data/test/coverband/integrations/resque_worker_test.rb +42 -0
  53. data/test/coverband/integrations/test_resque_job.rb +7 -0
  54. data/test/coverband/reporters/base_test.rb +168 -0
  55. data/test/{unit/reports_console_test.rb → coverband/reporters/console_test.rb} +8 -7
  56. data/test/coverband/reporters/html_test.rb +45 -0
  57. data/test/coverband/reporters/web_test.rb +52 -0
  58. data/test/coverband/utils/file_groups_test.rb +55 -0
  59. data/test/{unit → coverband}/utils/file_list_test.rb +1 -1
  60. data/test/coverband/utils/gem_list_test.rb +48 -0
  61. data/test/{unit → coverband}/utils/source_file_test.rb +1 -1
  62. data/test/{unit → integration}/full_stack_test.rb +25 -12
  63. data/test/{unit → integration}/rails_full_stack_test.rb +27 -7
  64. data/test/rails4_dummy/config/application.rb +1 -1
  65. data/test/rails4_dummy/config/coverband.rb +4 -1
  66. data/test/rails4_dummy/tmp/.keep +0 -0
  67. data/test/rails5_dummy/config/application.rb +1 -1
  68. data/test/rails5_dummy/config/coverband.rb +3 -1
  69. data/test/rails5_dummy/tmp/.keep +0 -0
  70. data/test/rails_test_helper.rb +13 -8
  71. data/test/test_helper.rb +12 -17
  72. data/test/unique_files.rb +23 -0
  73. data/views/file_list.erb +33 -20
  74. data/views/gem_list.erb +54 -0
  75. data/views/layout.erb +13 -4
  76. data/views/settings.erb +35 -0
  77. data/views/source_file.erb +16 -4
  78. data/views/source_file_loader.erb +7 -0
  79. metadata +108 -62
  80. data/test/unit/background_test.rb +0 -29
  81. data/test/unit/collectors_coverage_test.rb +0 -48
  82. data/test/unit/configuration_test.rb +0 -23
  83. data/test/unit/reports_base_test.rb +0 -109
  84. data/test/unit/reports_html_test.rb +0 -29
  85. data/test/unit/reports_web_test.rb +0 -39
  86. /data/test/{unit → coverband}/utils/lines_classifier_test.rb +0 -0
  87. /data/test/{unit → coverband}/utils/result_test.rb +0 -0
  88. /data/test/{unit → coverband}/utils/s3_report_test.rb +0 -0
  89. /data/test/{unit → coverband}/utils/source_file_line_test.rb +0 -0
  90. /data/test/{unit/dog.rb → dog.rb} +0 -0
@@ -0,0 +1,168 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../../test_helper', File.dirname(__FILE__))
4
+
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
+ test '#merge_arrays basic merge preserves order and counts' do
75
+ first = [0, 0, 1, 0, 1]
76
+ second = [nil, 0, 1, 0, 0]
77
+ expects = [0, 0, 2, 0, 1]
78
+
79
+ assert_equal expects, Coverband::Reporters::Base.send(:merge_arrays, first, second)
80
+ end
81
+
82
+ test '#merge_arrays basic merge preserves order and counts different lengths' do
83
+ first = [0, 0, 1, 0, 1]
84
+ second = [nil, 0, 1, 0, 0, 0, 0, 1]
85
+ expects = [0, 0, 2, 0, 1, 0, 0, 1]
86
+
87
+ assert_equal expects, Coverband::Reporters::Base.send(:merge_arrays, first, second)
88
+ end
89
+
90
+ test '#merge_arrays basic merge preserves nils' do
91
+ first = [0, 1, 2, nil, nil, nil]
92
+ second = [0, 1, 2, nil, 0, 1, 2]
93
+ expects = [0, 2, 4, nil, 0, 1, 2]
94
+
95
+ assert_equal expects, Coverband::Reporters::Base.send(:merge_arrays, first, second)
96
+ end
97
+
98
+ test "#get_current_scov_data_imp doesn't ignore folders with default ignore keys" do
99
+ @redis = Redis.new
100
+ store = Coverband::Adapters::RedisStore.new(@redis)
101
+ store.clear!
102
+
103
+ Coverband.configure do |config|
104
+ config.reporter = 'std_out'
105
+ config.root = '/full/remote_app/path'
106
+ config.store = store
107
+ end
108
+
109
+ key = '/a_path/that_has_erb_in/thepath.rb'
110
+ roots = ['/app/', '/full/remote_app/path/']
111
+
112
+ lines_hit = [1, 3, 6]
113
+ store.stubs(:merged_coverage).returns(key => lines_hit)
114
+ expected = { key => [1, 3, 6] }
115
+
116
+ assert_equal expected, Coverband::Reporters::Base.send(:get_current_scov_data_imp, store, roots)[:merged]
117
+ end
118
+
119
+ ###
120
+ # This test uses real world example data which helped uncover a bug
121
+ # The copied data doesn't format easily and isn't worth the effort to meet
122
+ # string style
123
+ # rubocop:disable all
124
+ ###
125
+ test '#get_current_scov_data_imp merges multiples of file data' do
126
+ coverage = {'/base/66/app/controllers/dashboard_controller.rb' =>
127
+ {"first_updated_at"=>1549610119,
128
+ "last_updated_at"=>1549610200,
129
+ "file_hash"=>"14dc84e940e26cbfb9ac79b43862e762",
130
+ "data"=>[1, 1, 1, nil, 1, 1, nil, nil, 1, nil, 1, 26, 26, nil, 26, 26, 26, 26, 26, 26, 26, nil, nil, 1, nil, 1, 26, 19, 0, 0, 0, 0, nil, nil, nil, nil, 0, 0, nil, nil, 1, 26, 26, 26, nil, nil, nil, nil, nil, 1, 26, nil, nil, 1, 26, nil, nil]},
131
+ '/base/78/app/controllers/dashboard_controller.rb' =>
132
+ {"first_updated_at"=>1549658574,
133
+ "last_updated_at"=>1549729830,
134
+ "file_hash"=>"14dc84e940e26cbfb9ac79b43862e762",
135
+ "data"=>[21, 21, 21, nil, 21, 21, nil, nil, 21, nil, 21, 22, 22, nil, 22, 22, 22, 22, 22, 22, 22, nil, nil, 21, nil, 21, 22, 13, 0, 0, 0, 0, nil, nil, nil, nil, 0, 0, nil, nil, 21, 22, 22, 22, nil, nil, nil, nil, nil, 21, 22, nil, nil, 21, 22, nil, nil]},
136
+ '/base/70/app/controllers/dashboard_controller.rb' =>
137
+ {"first_updated_at"=>1549617873,
138
+ "last_updated_at"=>1549618094,
139
+ "file_hash"=>"14dc84e940e26cbfb9ac79b43862e762",
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
+ }
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
+ key = '/base/78/app/app/controllers/dashboard_controller.rb'
153
+ roots = ['/base/[0-9]*/', '/base/78/app/']
154
+
155
+ lines_hit = [1, 3, 6]
156
+ store.stubs(:merged_coverage).returns(coverage)
157
+ File.expects(:exist?).at_least_once
158
+ .with('/base/[0-9]*/app/controllers/dashboard_controller.rb')
159
+ .returns(false)
160
+ File.expects(:exist?).at_least_once.with(key).returns(true)
161
+
162
+ expected = {"first_updated_at"=>1549617873,
163
+ "last_updated_at"=>1549618094,
164
+ "file_hash"=>"14dc84e940e26cbfb9ac79b43862e762",
165
+ "data"=>[38, 38, 38, nil, 38, 38, nil, nil, 38, nil, 38, 80, 80, nil, 80, 80, 80, 80, 80, 80, 80, nil, nil, 38, nil, 38, 80, 55, 0, 0, 0, 0, nil, nil, nil, nil, 0, 0, nil, nil, 38, 80, 80, 80, nil, nil, nil, nil, nil, 38, 80, nil, nil, 38, 80, nil, nil]}
166
+ assert_equal expected, Coverband::Reporters::Base.send(:get_current_scov_data_imp, store, roots)[:merged][key]
167
+ end
168
+ end
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require File.expand_path('../test_helper', File.dirname(__FILE__))
3
+ require File.expand_path('../../test_helper', File.dirname(__FILE__))
4
4
 
5
5
  class HTMLReportTest < Minitest::Test
6
- BASE_KEY = Coverband::Adapters::RedisStore::BASE_KEY
6
+ REDIS_STORAGE_FORMAT_VERSION = Coverband::Adapters::RedisStore::REDIS_STORAGE_FORMAT_VERSION
7
7
 
8
8
  def setup
9
9
  super
@@ -20,13 +20,14 @@ class HTMLReportTest < Minitest::Test
20
20
  end
21
21
  Coverband.configuration.logger.stubs('info')
22
22
  mock_file_hash
23
- Coverband::Reporters::ConsoleReport
24
- .expects(:current_root)
25
- .returns('app_path')
23
+ Coverband.configuration
24
+ .expects(:current_root)
25
+ .at_least_once
26
+ .returns('app_path')
26
27
  @store.send(:save_report, basic_coverage)
27
28
 
28
- report = Coverband::Reporters::ConsoleReport.report(@store)
29
- expected = { 'app_path/dog.rb' => [0, 1, 2] }
29
+ report = Coverband::Reporters::ConsoleReport.report(@store)[:merged]
30
+ expected = { './dog.rb' => [0, 1, 2] }
30
31
  assert_equal(expected.keys, report.keys)
31
32
  end
32
33
  end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../../test_helper', File.dirname(__FILE__))
4
+
5
+ class ReportHTMLTest < Minitest::Test
6
+ def setup
7
+ super
8
+ @redis = Redis.new
9
+ @store = Coverband::Adapters::RedisStore.new(@redis)
10
+ @store.clear!
11
+ end
12
+
13
+ test 'generate scov html report' do
14
+ Coverband.configure do |config|
15
+ config.reporter = 'scov'
16
+ config.store = @store
17
+ config.s3_bucket = nil
18
+ config.ignore = ['notsomething.rb']
19
+ end
20
+ mock_file_hash
21
+ @store.send(:save_report, basic_coverage)
22
+
23
+ html = Coverband::Reporters::HTMLReport.new(@store,
24
+ html: true,
25
+ open_report: false).report
26
+ assert_match 'Generated by', html
27
+ end
28
+
29
+ test 'generate scov report file' do
30
+ Coverband.configure do |config|
31
+ config.reporter = 'scov'
32
+ config.store = @store
33
+ config.s3_bucket = nil
34
+ config.ignore = ['notsomething.rb']
35
+ end
36
+ mock_file_hash
37
+ @store.send(:save_report, basic_coverage)
38
+
39
+ reporter = Coverband::Reporters::HTMLReport.new(@store,
40
+ html: false,
41
+ open_report: false)
42
+ Coverband::Utils::HTMLFormatter.any_instance.expects(:format!).once
43
+ reporter.report
44
+ end
45
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../../test_helper', File.dirname(__FILE__))
4
+ require 'aws-sdk-s3'
5
+ require File.expand_path('../../../lib/coverband/reporters/web', File.dirname(__FILE__))
6
+ require 'rack/test'
7
+
8
+ ENV['RACK_ENV'] = 'test'
9
+
10
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.2.0')
11
+ module Coverband
12
+ class WebTest < Minitest::Test
13
+ include Rack::Test::Methods
14
+
15
+ def app
16
+ Coverband::Reporters::Web.new
17
+ end
18
+
19
+ def teardown
20
+ super
21
+ Coverband.configuration.s3_bucket = nil
22
+ end
23
+
24
+ test 'renders index content' do
25
+ get '/'
26
+ assert last_response.ok?
27
+ assert_match 'Coverband Admin', last_response.body
28
+ end
29
+
30
+ test 'renders 404' do
31
+ get '/show'
32
+ assert last_response.not_found?
33
+ assert_equal '404 error!', last_response.body
34
+ end
35
+
36
+ test 'clears coverband' do
37
+ post '/clear'
38
+ assert_equal 301, last_response.status
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
+ end
51
+ end
52
+ end
@@ -0,0 +1,55 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../../test_helper', File.dirname(__FILE__))
4
+
5
+ describe Coverband::Utils::FileGroups do
6
+ FAKE_GEM_PATH = 'fake/gem/path'
7
+ subject do
8
+ controller_lines = [nil, 2, 2, 0, nil, nil, 0, nil, nil, nil]
9
+ files = [
10
+ Coverband::Utils::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil]),
11
+ Coverband::Utils::SourceFile.new(source_fixture('app/models/user.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]),
12
+ 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
+ ]
15
+ Coverband.configuration.expects(:gem_paths).at_least_once.returns([FAKE_GEM_PATH])
16
+ Coverband.configuration.track_gems = true
17
+ Coverband::Utils::FileGroups.new(files)
18
+ end
19
+
20
+ it 'has app files' do
21
+ assert_equal 'test/fixtures/sample.rb', subject.grouped_results['App'].first.short_name
22
+ end
23
+
24
+ it 'has gem files' do
25
+ assert_equal "#{FAKE_GEM_PATH}/gem_name.rb", subject.grouped_results['Gems'].first.first.short_name
26
+ end
27
+ end
28
+
29
+ describe Coverband::Utils::FileGroups, :vendored_gems do
30
+ FAKE_VENDOR_GEM_PATH = "#{test_root}/app/vendor/bundle/ruby/2.5.0/gems"
31
+ subject do
32
+ controller_lines = [nil, 2, 2, 0, nil, nil, 0, nil, nil, nil]
33
+ files = [
34
+ Coverband::Utils::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil]),
35
+ Coverband::Utils::SourceFile.new(source_fixture('app/models/user.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]),
36
+ Coverband::Utils::SourceFile.new(source_fixture('app/controllers/sample_controller.rb'), controller_lines),
37
+ Coverband::Utils::SourceFile.new("#{FAKE_VENDOR_GEM_PATH}/gem_name.rb", controller_lines)
38
+ ]
39
+ Coverband.configuration.expects(:gem_paths).at_least_once.returns([FAKE_VENDOR_GEM_PATH])
40
+ Coverband.configuration.track_gems = true
41
+ Coverband::Utils::FileGroups.new(files)
42
+ end
43
+
44
+ it 'has app files' do
45
+ assert_equal 'test/fixtures/sample.rb', subject.grouped_results['App'].first.short_name
46
+ end
47
+
48
+ it "doesn't include vendor gems in app files app files" do
49
+ assert_nil subject.grouped_results['App'].select { |files| files.short_name.match(/gem_name/) }.first
50
+ end
51
+
52
+ it 'does has gem files' do
53
+ assert_equal 'gem_name.rb', subject.grouped_results['Gems'].first.first.short_name
54
+ end
55
+ end
@@ -6,7 +6,7 @@ require File.expand_path('../../test_helper', File.dirname(__FILE__))
6
6
  # Thanks for all the help SimpleCov https://github.com/colszowka/simplecov-html
7
7
  # initial version of test pulled into Coverband from Simplecov 12/19/2018
8
8
  ####
9
- describe Coverband::Utils::Result do
9
+ describe Coverband::Utils::FileList do
10
10
  subject do
11
11
  original_result = {
12
12
  source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
@@ -0,0 +1,48 @@
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('../../test_helper', File.dirname(__FILE__))
4
+
5
+ ####
6
+ # Thanks for all the help SimpleCov https://github.com/colszowka/simplecov-html
7
+ # initial version of test pulled into Coverband from Simplecov 12/19/2018
8
+ ####
9
+ describe Coverband::Utils::GemList do
10
+ subject do
11
+ controller_lines = [nil, 2, 2, 0, nil, nil, 0, nil, nil, nil]
12
+ gem_files = [
13
+ Coverband::Utils::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil]),
14
+ Coverband::Utils::SourceFile.new(source_fixture('app/models/user.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]),
15
+ Coverband::Utils::SourceFile.new(source_fixture('app/controllers/sample_controller.rb'), controller_lines)
16
+ ]
17
+ gem_lists = [Coverband::Utils::FileList.new(gem_files), Coverband::Utils::FileList.new(gem_files)]
18
+ Coverband::Utils::GemList.new(gem_lists)
19
+ end
20
+
21
+ it 'has 22 covered lines' do
22
+ assert_equal 22, subject.covered_lines
23
+ end
24
+
25
+ it 'has 6 missed lines' do
26
+ assert_equal 6, subject.missed_lines
27
+ end
28
+
29
+ it 'has 34 never lines' do
30
+ assert_equal 34, subject.never_lines
31
+ end
32
+
33
+ it 'has 28 lines of code' do
34
+ assert_equal 28, subject.lines_of_code
35
+ end
36
+
37
+ it 'has 10 skipped lines' do
38
+ assert_equal 10, subject.skipped_lines
39
+ end
40
+
41
+ it 'has the correct covered percent' do
42
+ assert_equal 78.57142857142857, subject.covered_percent
43
+ end
44
+
45
+ it 'has the correct covered strength' do
46
+ assert_equal 0.9285714285714286, subject.covered_strength
47
+ end
48
+ end
@@ -79,7 +79,7 @@ describe Coverband::Utils::SourceFile do
79
79
  subject.lines
80
80
  end
81
81
 
82
- assert(captured_output.match(/^Warning: coverage data provided/))
82
+ assert(captured_output.match(/^Warning: coverage data/))
83
83
  end
84
84
  end
85
85
 
@@ -4,21 +4,28 @@ require File.expand_path('../test_helper', File.dirname(__FILE__))
4
4
  require 'rack'
5
5
 
6
6
  class FullStackTest < Minitest::Test
7
- BASE_KEY = Coverband::Adapters::RedisStore::BASE_KEY
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'
9
10
 
10
11
  def setup
12
+ super
11
13
  Coverband::Collectors::Coverage.instance.reset_instance
12
14
  Coverband.configure do |config|
13
15
  config.reporting_frequency = 100.0
14
16
  config.store = Coverband::Adapters::RedisStore.new(Redis.new)
15
17
  config.s3_bucket = nil
16
18
  config.background_reporting_enabled = false
19
+ config.root_paths = ["#{File.expand_path('../', File.dirname(__FILE__))}/"]
20
+ config.track_gems = true
17
21
  end
18
22
  Coverband.configuration.store.clear!
19
23
  Coverband.start
24
+ Coverband::Collectors::Coverage.instance.runtime!
20
25
  @rack_file = File.expand_path(TEST_RACK_APP, File.dirname(__FILE__))
21
- load @rack_file
26
+ require @rack_file
27
+ # preload first coverage hit
28
+ Coverband::Collectors::Coverage.instance.report_coverage(true)
22
29
  end
23
30
 
24
31
  test 'call app' do
@@ -26,20 +33,26 @@ class FullStackTest < Minitest::Test
26
33
  middleware = Coverband::Middleware.new(fake_app_with_lines)
27
34
  results = middleware.call(request)
28
35
  assert_equal 'Hello Rack!', results.last
29
- sleep(0.1)
30
- expected = [nil, nil, 1, nil, 1, 1, 1, nil, nil]
31
- assert_equal expected, Coverband.configuration.store.coverage[@rack_file]['data']
36
+ sleep(0.2)
37
+ expected = [nil, nil, 0, nil, 0, 0, 1, nil, nil]
38
+ assert_equal expected, Coverband.configuration.store.coverage[RELATIVE_FILE]['data']
32
39
 
33
40
  # additional calls increase count by 1
34
41
  middleware.call(request)
35
- sleep(0.1)
36
- expected = [nil, nil, 1, nil, 1, 1, 2, nil, nil]
37
- assert_equal expected, Coverband.configuration.store.coverage[@rack_file]['data']
42
+ sleep(0.2)
43
+ expected = [nil, nil, 0, nil, 0, 0, 2, nil, nil]
44
+ assert_equal expected, Coverband.configuration.store.coverage[RELATIVE_FILE]['data']
45
+ end
38
46
 
39
- # expected = nil
40
- # TODO: read the html to test it matches expectations? or return data as a hash?
41
- # actual = Coverband::Reporters::HTMLReport.report(Coverband.configuration.store, open_report: false)
42
- # assert_equal expected, actual
47
+ test 'call app with gem tracking' do
48
+ require 'rainbow'
49
+ Rainbow('this text is red').red
50
+ request = Rack::MockRequest.env_for('/anything.json')
51
+ middleware = Coverband::Middleware.new(fake_app_with_lines)
52
+ results = middleware.call(request)
53
+ assert_equal 'Hello Rack!', results.last
54
+ sleep(0.1)
55
+ assert Coverband.configuration.store.coverage.keys.any? { |key| key.end_with?('rainbow/global.rb') }
43
56
  end
44
57
 
45
58
  private
@@ -8,9 +8,11 @@ class RailsFullStackTest < Minitest::Test
8
8
 
9
9
  def setup
10
10
  super
11
- #The normal relative directory lookup of coverband won't work for our dummy rails project
12
- Coverband.configure("./test/rails#{Rails::VERSION::MAJOR}_dummy/config/coverband.rb")
13
- Coverband.start
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
14
16
  end
15
17
 
16
18
  def teardown
@@ -19,14 +21,32 @@ class RailsFullStackTest < Minitest::Test
19
21
  Capybara.use_default_driver
20
22
  end
21
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?
22
27
  test 'this is how we do it' do
23
28
  visit '/dummy/show'
29
+ Coverband.report_coverage(true)
24
30
  assert_content('I am no dummy')
25
- sleep 0.2
26
31
  visit '/coverage'
27
- within page.find('a', text: /dummy_controller.rb/).find(:xpath, "../..") do
32
+ within page.find('a', text: /dummy_controller.rb/).find(:xpath, '../..') do
28
33
  assert_selector('td', text: '100.0 %')
29
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']
30
50
  end
31
51
 
32
52
  ###
@@ -46,7 +66,7 @@ class RailsFullStackTest < Minitest::Test
46
66
  3.times do
47
67
  visit '/dummy/show'
48
68
  assert_content('I am no dummy')
49
- Coverband::Collectors::Coverage.instance.report_coverage(true)
69
+ Coverband.report_coverage(true)
50
70
  end
51
71
 
52
72
  previous_out = $stdout
@@ -57,7 +77,7 @@ class RailsFullStackTest < Minitest::Test
57
77
  15.times do
58
78
  visit '/dummy/show'
59
79
  assert_content('I am no dummy')
60
- Coverband::Collectors::Coverage.instance.report_coverage(true)
80
+ Coverband.report_coverage(true)
61
81
  # this is expected to retain memory across requests
62
82
  # clear it to remove the false positive from test
63
83
  Coverband::Collectors::Coverage.instance.send(:add_previous_results, nil)
@@ -10,6 +10,6 @@ module Rails4Dummy
10
10
  config.before_initialize do
11
11
  Coverband.start
12
12
  end
13
- config.eager_load = false
13
+ config.eager_load = true
14
14
  end
15
15
  end
@@ -4,5 +4,8 @@ Coverband.configure do |config|
4
4
  config.ignore = %w[vendor .erb$ .slim$]
5
5
  config.root_paths = []
6
6
  config.logger = Rails.logger
7
- config.background_reporting_sleep_seconds = 0.1
7
+ config.verbose = true
8
+ config.background_reporting_enabled = false
9
+ config.track_gems = true
10
+ config.gem_details = true
8
11
  end
File without changes
@@ -10,7 +10,7 @@ module Dummy
10
10
  config.before_initialize do
11
11
  Coverband.start
12
12
  end
13
- config.eager_load = false
13
+ config.eager_load = true
14
14
  end
15
15
  end
16
16
 
@@ -5,5 +5,7 @@ Coverband.configure do |config|
5
5
  config.root_paths = []
6
6
  config.logger = Rails.logger
7
7
  config.verbose = true
8
- config.background_reporting_sleep_seconds = 0.1
8
+ config.background_reporting_enabled = false
9
+ config.track_gems = true
10
+ config.gem_details = true
9
11
  end
File without changes
@@ -1,11 +1,16 @@
1
- # Configure Rails Environment
2
- ENV["RAILS_ENV"] = "test"
3
- require 'rails'
4
1
  require File.expand_path('./test_helper', File.dirname(__FILE__))
5
- require_relative "../test/rails#{Rails::VERSION::MAJOR}_dummy/config/environment"
6
- require 'capybara/rails'
2
+ require 'capybara'
7
3
  require 'capybara/minitest'
4
+ def rails_setup
5
+ ENV["RAILS_ENV"] = "test"
6
+ require 'rails'
7
+ #coverband must be required after rails
8
+ load 'coverband/utils/railtie.rb'
9
+ Coverband.configure("./test/rails#{Rails::VERSION::MAJOR}_dummy/config/coverband.rb")
10
+ require_relative "../test/rails#{Rails::VERSION::MAJOR}_dummy/config/environment"
11
+ require 'capybara/rails'
12
+ #Our coverage report is wrapped in display:none as of now
13
+ Capybara.ignore_hidden_elements = false
14
+ require 'mocha/minitest'
15
+ end
8
16
 
9
- #Our coverage report is wrapped in display:none as of now
10
- Capybara.ignore_hidden_elements = false
11
- require 'mocha/minitest'