coverband 4.2.5 → 5.0.0.rc.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. data/.standard.yml +25 -0
  3. data/.travis.yml +2 -1
  4. data/Gemfile +5 -7
  5. data/Gemfile.rails4 +0 -3
  6. data/Gemfile.rails6 +0 -3
  7. data/README.md +24 -77
  8. data/Rakefile +17 -17
  9. data/changes.md +31 -34
  10. data/config.ru +1 -1
  11. data/coverband.gemspec +30 -34
  12. data/lib/alternative_coverband_patch.rb +5 -0
  13. data/lib/coverband.rb +68 -44
  14. data/lib/coverband/adapters/base.rb +17 -18
  15. data/lib/coverband/adapters/file_store.rb +38 -6
  16. data/lib/coverband/adapters/hash_redis_store.rb +24 -21
  17. data/lib/coverband/adapters/redis_store.rb +12 -12
  18. data/lib/coverband/adapters/stdout_store.rb +41 -0
  19. data/lib/coverband/adapters/web_service_store.rb +157 -0
  20. data/lib/coverband/at_exit.rb +1 -1
  21. data/lib/coverband/collectors/coverage.rb +15 -27
  22. data/lib/coverband/collectors/delta.rb +29 -9
  23. data/lib/coverband/collectors/view_tracker.rb +19 -11
  24. data/lib/coverband/collectors/view_tracker_service.rb +59 -0
  25. data/lib/coverband/configuration.rb +121 -88
  26. data/lib/coverband/integrations/background.rb +6 -6
  27. data/lib/coverband/integrations/rack_server_check.rb +3 -3
  28. data/lib/coverband/integrations/resque.rb +13 -1
  29. data/lib/coverband/reporters/base.rb +10 -10
  30. data/lib/coverband/reporters/console_report.rb +1 -1
  31. data/lib/coverband/reporters/html_report.rb +10 -30
  32. data/lib/coverband/reporters/web.rb +55 -50
  33. data/lib/coverband/utils/absolute_file_converter.rb +6 -6
  34. data/lib/coverband/utils/html_formatter.rb +32 -61
  35. data/lib/coverband/utils/railtie.rb +23 -6
  36. data/lib/coverband/utils/relative_file_converter.rb +2 -2
  37. data/lib/coverband/utils/result.rb +6 -11
  38. data/lib/coverband/utils/results.rb +0 -10
  39. data/lib/coverband/utils/source_file.rb +21 -30
  40. data/lib/coverband/utils/tasks.rb +8 -11
  41. data/lib/coverband/version.rb +1 -1
  42. data/public/application.js +0 -30
  43. data/test/benchmarks/benchmark.rake +97 -92
  44. data/test/benchmarks/dog.rb +1 -1
  45. data/test/benchmarks/init_rails.rake +4 -4
  46. data/test/coverband/adapters/base_test.rb +29 -30
  47. data/test/coverband/adapters/file_store_test.rb +19 -20
  48. data/test/coverband/adapters/hash_redis_store_test.rb +57 -57
  49. data/test/coverband/adapters/redis_store_test.rb +26 -26
  50. data/test/coverband/adapters/web_service_store_test.rb +56 -0
  51. data/test/coverband/at_exit_test.rb +2 -2
  52. data/test/coverband/collectors/coverage_test.rb +33 -47
  53. data/test/coverband/collectors/delta_test.rb +52 -23
  54. data/test/coverband/collectors/view_tracker_test.rb +35 -35
  55. data/test/coverband/configuration_test.rb +27 -53
  56. data/test/coverband/coverband_test.rb +11 -11
  57. data/test/coverband/integrations/background_middleware_test.rb +10 -10
  58. data/test/coverband/integrations/background_test.rb +6 -5
  59. data/test/coverband/integrations/rack_server_check_test.rb +7 -7
  60. data/test/coverband/integrations/report_middleware_test.rb +9 -9
  61. data/test/coverband/integrations/resque_worker_test.rb +9 -9
  62. data/test/coverband/integrations/test_resque_job.rb +1 -1
  63. data/test/coverband/reporters/base_test.rb +9 -9
  64. data/test/coverband/reporters/console_test.rb +6 -6
  65. data/test/coverband/reporters/html_test.rb +36 -48
  66. data/test/coverband/reporters/web_test.rb +16 -18
  67. data/test/coverband/utils/absolute_file_converter_test.rb +22 -22
  68. data/test/coverband/utils/file_hasher_test.rb +6 -12
  69. data/test/coverband/utils/file_list_test.rb +13 -13
  70. data/test/coverband/utils/html_formatter_test.rb +9 -23
  71. data/test/coverband/utils/lines_classifier_test.rb +29 -29
  72. data/test/coverband/utils/relative_file_converter_test.rb +13 -13
  73. data/test/coverband/utils/result_test.rb +18 -18
  74. data/test/coverband/utils/results_test.rb +17 -17
  75. data/test/coverband/utils/source_file_line_test.rb +46 -46
  76. data/test/coverband/utils/source_file_test.rb +38 -88
  77. data/test/dog.rb +1 -1
  78. data/test/fake_app/basic_rack.rb +2 -2
  79. data/test/fixtures/app/controllers/sample_controller.rb +1 -1
  80. data/test/fixtures/app/models/user.rb +1 -1
  81. data/test/fixtures/sample.rb +1 -1
  82. data/test/fixtures/utf-8.rb +0 -2
  83. data/test/forked/rails_full_stack_test.rb +24 -27
  84. data/test/forked/rails_rake_full_stack_test.rb +7 -26
  85. data/test/integration/full_stack_test.rb +11 -22
  86. data/test/jruby_check.rb +2 -3
  87. data/test/rails4_dummy/Rakefile +1 -1
  88. data/test/rails4_dummy/config.ru +1 -1
  89. data/test/rails4_dummy/config/application.rb +4 -4
  90. data/test/rails4_dummy/config/boot.rb +2 -2
  91. data/test/rails4_dummy/config/coverband.rb +1 -1
  92. data/test/rails4_dummy/config/coverband_missing_redis.rb +1 -1
  93. data/test/rails4_dummy/config/environment.rb +1 -1
  94. data/test/rails4_dummy/config/routes.rb +2 -2
  95. data/test/rails5_dummy/Rakefile +1 -1
  96. data/test/rails5_dummy/config.ru +1 -1
  97. data/test/rails5_dummy/config/application.rb +3 -3
  98. data/test/rails5_dummy/config/coverband.rb +8 -8
  99. data/test/rails5_dummy/config/coverband_missing_redis.rb +8 -8
  100. data/test/rails5_dummy/config/environment.rb +1 -1
  101. data/test/rails5_dummy/config/routes.rb +2 -2
  102. data/test/rails6_dummy/Rakefile +1 -1
  103. data/test/rails6_dummy/config.ru +1 -1
  104. data/test/rails6_dummy/config/application.rb +4 -4
  105. data/test/rails6_dummy/config/boot.rb +2 -2
  106. data/test/rails6_dummy/config/coverband.rb +1 -1
  107. data/test/rails6_dummy/config/coverband_missing_redis.rb +1 -1
  108. data/test/rails6_dummy/config/environment.rb +1 -1
  109. data/test/rails6_dummy/config/routes.rb +2 -2
  110. data/test/rails_test_helper.rb +11 -11
  111. data/test/test_helper.rb +43 -34
  112. data/test/unique_files.rb +10 -10
  113. data/views/layout.erb +2 -12
  114. metadata +15 -34
  115. data/.rubocop.yml +0 -84
  116. data/lib/coverband/integrations/bundler.rb +0 -8
  117. data/lib/coverband/utils/file_groups.rb +0 -53
  118. data/lib/coverband/utils/gem_list.rb +0 -31
  119. data/lib/coverband/utils/s3_report.rb +0 -105
  120. data/test/coverband/utils/file_groups_test.rb +0 -61
  121. data/test/coverband/utils/gem_list_test.rb +0 -48
  122. data/test/coverband/utils/s3_report_test.rb +0 -44
  123. data/views/gem_list.erb +0 -63
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Coverband
4
+ module Collectors
5
+ ###
6
+ # This class extends view tracker to support web service reporting
7
+ ###
8
+ class ViewTrackerService < ViewTracker
9
+ def report_views_tracked
10
+ reported_time = Time.now.to_i
11
+ if views_to_record.any?
12
+ relative_views = views_to_record.map! do |view|
13
+ roots.each do |root|
14
+ view = view.gsub(/#{root}/, "")
15
+ end
16
+ view
17
+ end
18
+ save_tracked_views(views: relative_views, reported_time: reported_time)
19
+ end
20
+ self.views_to_record = []
21
+ rescue => e
22
+ # we don't want to raise errors if Coverband can't reach the service
23
+ logger&.error "Coverband: view_tracker failed to store, error #{e.class.name}" if Coverband.configuration.verbose || Coverband.configuration.service_dev_mode
24
+ end
25
+
26
+ def self.supported_version?
27
+ defined?(Rails) && defined?(Rails::VERSION) && Rails::VERSION::STRING.split(".").first.to_i >= 4
28
+ end
29
+
30
+ private
31
+
32
+ def logger
33
+ Coverband.configuration.logger
34
+ end
35
+
36
+ def save_tracked_views(views:, reported_time:)
37
+ uri = URI("#{Coverband.configuration.service_url}/api/collector")
38
+ req = Net::HTTP::Post.new(uri, "Content-Type" => "application/json", "Coverband-Token" => Coverband.configuration.api_key)
39
+ data = {
40
+ collection_type: "view_tracker_delta",
41
+ collection_data: {
42
+ tags: {
43
+ runtime_env: Coverband.configuration.coverband_env
44
+ },
45
+ collection_time: reported_time,
46
+ tracked_views: views
47
+ }
48
+ }
49
+ # puts "sending #{data}"
50
+ req.body = {remote_uuid: SecureRandom.uuid, data: data}.to_json
51
+ Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == "https") do |http|
52
+ http.request(req)
53
+ end
54
+ rescue => e
55
+ logger&.error "Coverband: Error while saving coverage #{e}" if Coverband.configuration.verbose || Coverband.configuration.service_dev_mode
56
+ end
57
+ end
58
+ end
59
+ end
@@ -3,16 +3,17 @@
3
3
  module Coverband
4
4
  class Configuration
5
5
  attr_accessor :root_paths, :root,
6
- :additional_files, :verbose,
7
- :reporter, :redis_namespace, :redis_ttl,
8
- :background_reporting_enabled,
9
- :background_reporting_sleep_seconds, :test_env,
10
- :web_enable_clear, :gem_details, :web_debug, :report_on_exit,
11
- :simulate_oneshot_lines_coverage, :track_views, :view_tracker,
12
- :reporting_wiggle
13
-
6
+ :additional_files, :verbose,
7
+ :reporter, :redis_namespace, :redis_ttl,
8
+ :background_reporting_enabled,
9
+ :test_env, :web_enable_clear, :gem_details, :web_debug, :report_on_exit,
10
+ :simulate_oneshot_lines_coverage,
11
+ :view_tracker
14
12
  attr_writer :logger, :s3_region, :s3_bucket, :s3_access_key_id,
15
- :s3_secret_access_key, :password
13
+ :s3_secret_access_key, :password, :api_key, :service_url, :coverband_timeout, :service_dev_mode,
14
+ :service_test_mode, :proces_type, :report_period, :track_views,
15
+ :background_reporting_sleep_seconds, :reporting_wiggle
16
+
16
17
  attr_reader :track_gems, :ignore, :use_oneshot_lines_coverage
17
18
 
18
19
  #####
@@ -22,25 +23,25 @@ module Coverband
22
23
  # * should we skip /bin/rails webpacker:compile ?
23
24
  # * Perhaps detect heroku deployment ENV var opposed to tasks?
24
25
  #####
25
- IGNORE_TASKS = ['coverband:clear',
26
- 'coverband:coverage',
27
- 'coverband:coverage_server',
28
- 'coverband:migrate',
29
- 'assets:precompile',
30
- 'db:version',
31
- 'db:create',
32
- 'db:drop',
33
- 'db:seed',
34
- 'db:setup',
35
- 'db:test:prepare',
36
- 'db:structure:dump',
37
- 'db:structure:load',
38
- 'db:version']
26
+ IGNORE_TASKS = ["coverband:clear",
27
+ "coverband:coverage",
28
+ "coverband:coverage_server",
29
+ "coverband:migrate",
30
+ "assets:precompile",
31
+ "db:version",
32
+ "db:create",
33
+ "db:drop",
34
+ "db:seed",
35
+ "db:setup",
36
+ "db:test:prepare",
37
+ "db:structure:dump",
38
+ "db:structure:load",
39
+ "db:version"]
39
40
 
40
41
  # Heroku when building assets runs code from a dynamic directory
41
42
  # /tmp was added to avoid coverage from /tmp/build directories during
42
43
  # heroku asset compilation
43
- IGNORE_DEFAULTS = %w[vendor/ .erb$ .slim$ /tmp internal:prelude schema.rb]
44
+ IGNORE_DEFAULTS = %w[vendor/ .erb$ .slim$ /tmp internal:prelude db/schema.rb]
44
45
 
45
46
  # Add in missing files which were never loaded
46
47
  # we need to know what all paths to check for unloaded files
@@ -57,31 +58,41 @@ module Coverband
57
58
  @search_paths = TRACKED_DEFAULT_PATHS.dup
58
59
  @additional_files = []
59
60
  @verbose = false
60
- @reporter = 'scov'
61
+ @reporter = "scov"
61
62
  @logger = nil
62
63
  @store = nil
63
64
  @background_reporting_enabled = true
64
- @background_reporting_sleep_seconds = 30
65
+ @background_reporting_sleep_seconds = nil
65
66
  @test_env = nil
66
67
  @web_enable_clear = false
67
68
  @track_gems = false
68
69
  @gem_details = false
69
- @track_views = false
70
- @groups = {}
70
+ @track_views = true
71
+ @view_tracker = nil
71
72
  @web_debug = false
72
73
  @report_on_exit = true
73
- @use_oneshot_lines_coverage = ENV['ONESHOT'] || false
74
- @simulate_oneshot_lines_coverage = ENV['SIMULATE_ONESHOT'] || false
74
+ @use_oneshot_lines_coverage = ENV["ONESHOT"] || false
75
+ @simulate_oneshot_lines_coverage = ENV["SIMULATE_ONESHOT"] || false
75
76
  @current_root = nil
76
77
  @all_root_paths = nil
77
78
  @all_root_patterns = nil
78
79
  @password = nil
79
80
 
80
- # TODO: should we push these to adapter configs
81
+ # coverband service settings
82
+ @api_key = nil
83
+ @service_url = nil
84
+ @coverband_timeout = nil
85
+ @service_dev_mode = nil
86
+ @service_test_mode = nil
87
+ @proces_type = nil
88
+ @report_period = nil
89
+
90
+ # TODO: these are deprecated
81
91
  @s3_region = nil
82
92
  @s3_bucket = nil
83
93
  @s3_access_key_id = nil
84
94
  @s3_secret_access_key = nil
95
+
85
96
  @redis_namespace = nil
86
97
  @redis_ttl = 2_592_000 # in seconds. Default is 30 days.
87
98
  @reporting_wiggle = nil
@@ -89,38 +100,59 @@ module Coverband
89
100
 
90
101
  def logger
91
102
  @logger ||= if defined?(Rails.logger) && Rails.logger
92
- Rails.logger
93
- else
94
- Logger.new(STDOUT)
95
- end
103
+ Rails.logger
104
+ else
105
+ Logger.new(STDOUT)
106
+ end
96
107
  end
97
108
 
98
109
  def password
99
- @password || ENV['COVERBAND_PASSWORD']
110
+ @password || ENV["COVERBAND_PASSWORD"]
100
111
  end
101
112
 
102
113
  def s3_bucket
103
- @s3_bucket || ENV['AWS_BUCKET']
114
+ puts "deprecated, s3 is no longer support"
104
115
  end
105
116
 
106
117
  def s3_region
107
- @s3_region || ENV['AWS_REGION']
118
+ puts "deprecated, s3 is no longer support"
108
119
  end
109
120
 
110
121
  def s3_access_key_id
111
- @s3_access_key_id || ENV['AWS_ACCESS_KEY_ID']
122
+ puts "deprecated, s3 is no longer support"
112
123
  end
113
124
 
114
125
  def s3_secret_access_key
115
- @s3_secret_access_key || ENV['AWS_SECRET_ACCESS_KEY']
126
+ puts "deprecated, s3 is no longer support"
127
+ end
128
+
129
+ def background_reporting_sleep_seconds
130
+ @background_reporting_sleep_seconds ||= if Coverband.coverband_service?
131
+ Coverband.configuration.coverband_env == "production" ? Coverband.configuration.report_period : 60
132
+ else
133
+ 60
134
+ end
135
+ end
136
+
137
+ def reporting_wiggle
138
+ @reporting_wiggle ||= 30
116
139
  end
117
140
 
118
141
  def store
119
- @store ||= Coverband::Adapters::RedisStore.new(Redis.new(url: redis_url), redis_store_options)
142
+ @store ||= if Coverband.coverband_service?
143
+ require "coverband/adapters/web_service_store"
144
+ Coverband::Adapters::WebServiceStore.new(service_url)
145
+ else
146
+ Coverband::Adapters::RedisStore.new(Redis.new(url: redis_url), redis_store_options)
147
+ end
148
+ end
149
+
150
+ def track_views
151
+ @track_views ||= service_disabled_dev_test_env? ? false : true
120
152
  end
121
153
 
122
154
  def store=(store)
123
- raise 'Pass in an instance of Coverband::Adapters' unless store.is_a?(Coverband::Adapters::Base)
155
+ raise "Pass in an instance of Coverband::Adapters" unless store.is_a?(Coverband::Adapters::Base)
124
156
 
125
157
  # Default to 5 minutes if using the hash redis store
126
158
  # This is a safer default for the high server volumes that need the hash store
@@ -134,7 +166,7 @@ module Coverband
134
166
  # Search Paths
135
167
  ###
136
168
  def tracked_search_paths
137
- "#{Coverband.configuration.current_root}/{#{@search_paths.join(',')}}/**/*.{rb}"
169
+ "#{Coverband.configuration.current_root}/{#{@search_paths.join(",")}}/**/*.{rb}"
138
170
  end
139
171
 
140
172
  ###
@@ -151,43 +183,8 @@ module Coverband
151
183
  @ignore = (@ignore + ignored_array).uniq
152
184
  end
153
185
 
154
- def track_gems=(value)
155
- @track_gems = value
156
- return unless @track_gems
157
-
158
- # by default we ignore vendor where many deployments put gems
159
- # we will remove this default if track_gems is set
160
- @ignore.delete('vendor/')
161
- # while we want to allow vendored gems we don't want to track vendored ruby STDLIB
162
- @ignore << 'vendor/ruby-*' unless @ignore.include?('vendor/ruby-*')
163
- add_group('App', root)
164
- # TODO: rework support for multiple gem paths
165
- # this works but seems hacky and error prone
166
- # basically since it is converted to a regex we join all the paths
167
- # with a regex 'OR' using '|'
168
- add_group('Gems', gem_paths.join('|'))
169
- end
170
-
171
- #
172
- # Returns the configured groups. Add groups using SimpleCov.add_group
173
- #
174
- def groups
175
- @groups ||= {}
176
- end
177
-
178
- #
179
- # Define a group for files. Works similar to add_filter, only that the first
180
- # argument is the desired group name and files PASSING the filter end up in the group
181
- # (while filters exclude when the filter is applicable).
182
- #
183
- def add_group(group_name, filter_argument = nil)
184
- groups[group_name] = filter_argument
185
- end
186
-
187
- def gem_paths
188
- # notes ignore any paths that aren't on this system, resolves
189
- # bug related to multiple ruby version managers / bad dot files
190
- Gem::PathSupport.new(ENV).path.select { |path| File.exist?(path) }
186
+ def track_gems=(_value)
187
+ puts "gem tracking is deprecated, setting this will be ignored"
191
188
  end
192
189
 
193
190
  def current_root
@@ -198,7 +195,6 @@ module Coverband
198
195
  return @all_root_paths if @all_root_paths
199
196
 
200
197
  @all_root_paths = Coverband.configuration.root_paths.dup
201
- @all_root_paths += Coverband.configuration.gem_paths.dup if Coverband.configuration.track_gems
202
198
  @all_root_paths << "#{Coverband.configuration.current_root}/"
203
199
  @all_root_paths
204
200
  end
@@ -210,30 +206,67 @@ module Coverband
210
206
  SKIPPED_SETTINGS = %w[@s3_secret_access_key @store]
211
207
  def to_h
212
208
  instance_variables
213
- .each_with_object('gem_paths': gem_paths) do |var, hash|
214
- hash[var.to_s.delete('@')] = instance_variable_get(var) unless SKIPPED_SETTINGS.include?(var.to_s)
209
+ .each_with_object({}) do |var, hash|
210
+ hash[var.to_s.delete("@")] = instance_variable_get(var) unless SKIPPED_SETTINGS.include?(var.to_s)
215
211
  end
216
212
  end
217
213
 
218
214
  def use_oneshot_lines_coverage=(value)
219
- raise(Exception, 'One shot line coverage is only available in ruby >= 2.6') unless one_shot_coverage_implemented_in_ruby_version? || !value
215
+ raise(StandardError, "One shot line coverage is only available in ruby >= 2.6") unless one_shot_coverage_implemented_in_ruby_version? || !value
220
216
 
221
217
  @use_oneshot_lines_coverage = value
222
218
  end
223
219
 
224
220
  def one_shot_coverage_implemented_in_ruby_version?
225
- Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.6.0')
221
+ Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.6.0")
222
+ end
223
+
224
+ def api_key
225
+ @api_key ||= ENV["COVERBAND_API_KEY"]
226
+ end
227
+
228
+ def service_url
229
+ @service_url ||= ENV["COVERBAND_URL"] || "https://coverband.io"
230
+ end
231
+
232
+ def coverband_env
233
+ ENV["RACK_ENV"] || ENV["RAILS_ENV"] || (defined?(Rails) && Rails.respond_to?(:env) ? Rails.env : "unknown")
234
+ end
235
+
236
+ def coverband_timeout
237
+ @coverband_timeout ||= coverband_env == "development" ? 5 : 2
238
+ end
239
+
240
+ def service_dev_mode
241
+ @service_dev_mode ||= ENV["COVERBAND_ENABLE_DEV_MODE"] || false
242
+ end
243
+
244
+ def service_test_mode
245
+ @service_dev_mode ||= ENV["COVERBAND_ENABLE_TEST_MODE"] || false
246
+ end
247
+
248
+ def proces_type
249
+ @process_type ||= ENV["PROCESS_TYPE"] || "unknown"
250
+ end
251
+
252
+ def report_period
253
+ @process_type ||= (ENV["COVERBAND_REPORT_PERIOD"] || 600).to_i
254
+ end
255
+
256
+ def service_disabled_dev_test_env?
257
+ (coverband_env == "test" && !Coverband.configuration.service_test_mode) ||
258
+ (coverband_env == "development" && !Coverband.configuration.service_dev_mode)
226
259
  end
227
260
 
228
261
  private
229
262
 
230
263
  def redis_url
231
- ENV['COVERBAND_REDIS_URL'] || ENV['REDIS_URL']
264
+ ENV["COVERBAND_REDIS_URL"] || ENV["REDIS_URL"]
232
265
  end
233
266
 
234
267
  def redis_store_options
235
- { ttl: Coverband.configuration.redis_ttl,
236
- redis_namespace: Coverband.configuration.redis_namespace }
268
+ {ttl: Coverband.configuration.redis_ttl,
269
+ redis_namespace: Coverband.configuration.redis_namespace}
237
270
  end
238
271
  end
239
272
  end
@@ -27,21 +27,21 @@ module Coverband
27
27
  @semaphore.synchronize do
28
28
  return if running?
29
29
 
30
- logger.debug('Coverband: Starting background reporting') if Coverband.configuration.verbose
31
- sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds
32
- @thread = Thread.new do
30
+ logger.debug("Coverband: Starting background reporting") if Coverband.configuration.verbose
31
+ sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds.to_i
32
+ @thread = Thread.new {
33
33
  loop do
34
34
  Coverband.report_coverage
35
35
  Coverband.configuration.view_tracker&.report_views_tracked
36
36
  if Coverband.configuration.reporting_wiggle
37
- sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds + rand(Coverband.configuration.reporting_wiggle.to_i)
37
+ sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds.to_i + rand(Coverband.configuration.reporting_wiggle.to_i)
38
38
  end
39
39
  if Coverband.configuration.verbose
40
40
  logger.debug("Coverband: background reporting coverage (#{Coverband.configuration.store.type}). Sleeping #{sleep_seconds}s")
41
41
  end
42
- sleep(sleep_seconds)
42
+ sleep(sleep_seconds.to_i)
43
43
  end
44
- end
44
+ }
45
45
  end
46
46
  end
47
47
  end
@@ -15,14 +15,14 @@ module Coverband
15
15
  end
16
16
 
17
17
  def rack_server?
18
- @stack.any? { |line| line.path.include?('lib/rack/') }
18
+ @stack.any? { |line| line.path.include?("lib/rack/") }
19
19
  end
20
20
 
21
21
  def rails_server?
22
22
  @stack.any? do |location|
23
23
  (
24
- location.path.include?('rails/commands/commands_tasks.rb') && location.label == 'server' ||
25
- location.path.include?('rails/commands/server/server_command.rb') && location.label == 'perform'
24
+ location.path.include?("rails/commands/commands_tasks.rb") && location.label == "server" ||
25
+ location.path.include?("rails/commands/server/server_command.rb") && location.label == "perform"
26
26
  )
27
27
  end
28
28
  end
@@ -22,4 +22,16 @@ module Coverband
22
22
  end
23
23
  end
24
24
 
25
- Resque::Job.prepend(Coverband::ResqueWorker)
25
+ if defined?(Coverband::COVERBAND_ALTERNATE_PATCH)
26
+ Resque::Job.class_eval do
27
+ def perform_with_coverband
28
+ perform_without_coverband
29
+ ensure
30
+ Coverband.report_coverage
31
+ end
32
+ alias perform_without_coverband perform
33
+ alias perform perform_with_coverband
34
+ end
35
+ else
36
+ Resque::Job.prepend(Coverband::ResqueWorker)
37
+ end
@@ -8,7 +8,7 @@ module Coverband
8
8
  ###
9
9
  class Base
10
10
  class << self
11
- DATA_KEY = 'data'
11
+ DATA_KEY = "data"
12
12
 
13
13
  def report(store, _options = {})
14
14
  all_roots = Coverband.configuration.all_root_paths
@@ -49,7 +49,7 @@ module Coverband
49
49
  protected
50
50
 
51
51
  def fix_file_names(report_hash, roots)
52
- Coverband.configuration.logger.debug "fixing root: #{roots.join(', ')}" if Coverband.configuration.verbose
52
+ Coverband.configuration.logger.debug "fixing root: #{roots.join(", ")}" if Coverband.configuration.verbose
53
53
 
54
54
  # normalize names across servers
55
55
  report_hash.each_with_object({}) do |(name, report), fixed_report|
@@ -57,12 +57,12 @@ module Coverband
57
57
  report.each_pair do |key, vals|
58
58
  filename = Coverband::Utils::AbsoluteFileConverter.convert(key)
59
59
  fixed_report[name][filename] = if fixed_report[name].key?(filename) && fixed_report[name][filename][DATA_KEY] && vals[DATA_KEY]
60
- merged_data = merge_arrays(fixed_report[name][filename][DATA_KEY], vals[DATA_KEY])
61
- vals[DATA_KEY] = merged_data
62
- vals
63
- else
64
- vals
65
- end
60
+ merged_data = merge_arrays(fixed_report[name][filename][DATA_KEY], vals[DATA_KEY])
61
+ vals[DATA_KEY] = merged_data
62
+ vals
63
+ else
64
+ vals
65
+ end
66
66
  end
67
67
  end
68
68
  end
@@ -75,8 +75,8 @@ module Coverband
75
75
 
76
76
  longest.each_with_index do |_line, index|
77
77
  merged[index] = if first[index] || second[index]
78
- (first[index].to_i + second[index].to_i)
79
- end
78
+ (first[index].to_i + second[index].to_i)
79
+ end
80
80
  end
81
81
 
82
82
  merged