coverband 4.1.1 → 4.2.0.alpha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +1 -4
  3. data/.travis.yml +2 -4
  4. data/README.md +8 -33
  5. data/Rakefile +1 -1
  6. data/changes.md +10 -26
  7. data/coverband.gemspec +0 -4
  8. data/lib/coverband.rb +0 -5
  9. data/lib/coverband/adapters/base.rb +4 -20
  10. data/lib/coverband/adapters/file_store.rb +0 -8
  11. data/lib/coverband/adapters/redis_store.rb +2 -33
  12. data/lib/coverband/at_exit.rb +1 -1
  13. data/lib/coverband/collectors/coverage.rb +1 -7
  14. data/lib/coverband/configuration.rb +2 -30
  15. data/lib/coverband/integrations/background.rb +1 -6
  16. data/lib/coverband/integrations/resque.rb +2 -7
  17. data/lib/coverband/reporters/base.rb +38 -8
  18. data/lib/coverband/reporters/html_report.rb +1 -1
  19. data/lib/coverband/reporters/web.rb +1 -13
  20. data/lib/coverband/utils/file_groups.rb +12 -20
  21. data/lib/coverband/utils/html_formatter.rb +1 -9
  22. data/lib/coverband/utils/railtie.rb +1 -1
  23. data/lib/coverband/utils/tasks.rb +0 -9
  24. data/lib/coverband/version.rb +1 -1
  25. data/test/benchmarks/benchmark.rake +1 -36
  26. data/test/test_helper.rb +12 -5
  27. data/test/{coverband/adapters/base_test.rb → unit/adapters_base_test.rb} +1 -1
  28. data/test/{coverband/adapters/file_store_test.rb → unit/adapters_file_store_test.rb} +1 -1
  29. data/test/{coverband/adapters/redis_store_test.rb → unit/adapters_redis_store_test.rb} +1 -1
  30. data/test/{coverband → unit}/at_exit_test.rb +0 -0
  31. data/test/{coverband/integrations → unit}/background_test.rb +1 -1
  32. data/test/unit/collectors_coverage_test.rb +48 -0
  33. data/test/{coverband → unit}/configuration_test.rb +3 -13
  34. data/test/{coverband → unit}/coverband_test.rb +0 -0
  35. data/test/{dog.rb → unit/dog.rb} +0 -0
  36. data/test/{integration → unit}/full_stack_test.rb +2 -4
  37. data/test/{coverband/integrations → unit}/middleware_test.rb +1 -1
  38. data/test/{coverband/integrations/rack_server_check_test.rb → unit/rack_server_checkout_test.rb} +1 -1
  39. data/test/{integration → unit}/rails_full_stack_test.rb +3 -4
  40. data/test/{integration → unit}/rails_gems_full_stack_test.rb +1 -2
  41. data/test/unit/reports_base_test.rb +117 -0
  42. data/test/{coverband/reporters/console_test.rb → unit/reports_console_test.rb} +5 -6
  43. data/test/{coverband/reporters/html_test.rb → unit/reports_html_test.rb} +1 -1
  44. data/test/{coverband/reporters/web_test.rb → unit/reports_web_test.rb} +2 -2
  45. data/test/{coverband/integrations → unit}/resque_worker_test.rb +8 -9
  46. data/test/{coverband/integrations → unit}/test_resque_job.rb +0 -0
  47. data/test/unit/utils/file_groups_test.rb +31 -0
  48. data/test/{coverband → unit}/utils/file_list_test.rb +0 -0
  49. data/test/{coverband → unit}/utils/gem_list_test.rb +0 -0
  50. data/test/{coverband → unit}/utils/lines_classifier_test.rb +0 -0
  51. data/test/{coverband → unit}/utils/result_test.rb +0 -0
  52. data/test/{coverband → unit}/utils/s3_report_test.rb +0 -0
  53. data/test/{coverband → unit}/utils/source_file_line_test.rb +0 -0
  54. data/test/{coverband → unit}/utils/source_file_test.rb +0 -0
  55. data/views/layout.erb +0 -4
  56. metadata +61 -100
  57. data/lib/coverband/utils/file_path_helper.rb +0 -57
  58. data/public/favicon.png +0 -0
  59. data/test/benchmarks/coverage_fork.sh +0 -37
  60. data/test/coverband/collectors/coverage_test.rb +0 -67
  61. data/test/coverband/reporters/base_test.rb +0 -168
  62. data/test/coverband/utils/file_groups_test.rb +0 -55
  63. data/test/rails4_dummy/tmp/.keep +0 -0
  64. data/test/unique_files.rb +0 -23
  65. data/views/settings.erb +0 -35
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 0e029eb4a5ce229ca0ce9dd7ac6638bc3b9776e07a724269a495b2832228119d
4
- data.tar.gz: 0f37d401fafe727024665b096e337138e53f8be139521dea9e149695b44f39ce
2
+ SHA1:
3
+ metadata.gz: 40372eb3dc52edf4440af29a183eea4354a1695b
4
+ data.tar.gz: 47215556426f24df1aa12a26dadfb97418f59ce9
5
5
  SHA512:
6
- metadata.gz: c0d51d0263c37369abffc5839a367cdebd5fad7d8132362044163614fca33e2bc8617770bb36d3dd268eb34a4f0243e5fe4a1fad516f724a9da122aa5739a8be
7
- data.tar.gz: db40dfd936b39d159e7d92b470b186761cfea6ce944e55ff8079d70279af8c84a3602c5c873317c58d76b08aa0a654e653eb10df8a608ba646e4bd37b006105b
6
+ metadata.gz: da9ddb6c8ad13165d7fca9332e23d10a69fe96d6eb4aa2589f206375f4f87943a878d16858408118a32cb0cb37c33e647b3da581f78792fb0fe84ee3fe36b83b
7
+ data.tar.gz: 29f91f8e81dd7f00c3b3fa3718b5d8734cad42c7feb4dbd83b930b3cf7e0e649e3ecb34de4efef5c43c15bf37b4d25c6622bc6118755b413ecce1914ac88aed6
data/.gitignore CHANGED
@@ -16,10 +16,7 @@ rdoc
16
16
  spec/reports
17
17
  test/tmp
18
18
  test/version_tmp
19
- /tmp/
20
- temp_results
19
+ tmp
21
20
  .byebug_history
22
21
  .env
23
22
  log/
24
- test/unique_files
25
- test/rails5_dummy/tmp
data/.travis.yml CHANGED
@@ -3,7 +3,7 @@ rvm:
3
3
  - "2.3"
4
4
  - "2.4"
5
5
  - "2.5"
6
- - "2.6.1"
6
+ - "2.6"
7
7
  gemfile:
8
8
  - Gemfile
9
9
  - Gemfile.rails4
@@ -11,9 +11,7 @@ services:
11
11
  - redis-server
12
12
  before_install:
13
13
  - echo 'this is a hack to clear default bundler and force bundler 1.17.3'
14
- - ls /home/travis/.rvm/gems/
15
14
  - rm /home/travis/.rvm/gems/ruby-2.3.7@global/specifications/bundler-2.0.1.gemspec || true
16
- - rm /home/travis/.rvm/gems/ruby-2.5.4@global/specifications/bundler-2.0.1.gemspec || true
17
15
  - gem uninstall bundler || true
18
16
  - gem install bundler -v '1.17.3'
19
- - bundler --version
17
+ - bundler --version
data/README.md CHANGED
@@ -38,8 +38,6 @@ Coverband stores coverage data in Redis. The Redis endpoint is looked for in thi
38
38
  2. `ENV['REDIS_URL']`
39
39
  3. `localhost`
40
40
 
41
- The redis store can also be explicitly defined within the coverband.rb. See [advanced config](#advanced-config).
42
-
43
41
  ## Gem Installation
44
42
 
45
43
  Add this line to your application's `Gemfile`, remember to `bundle install` after updating:
@@ -48,11 +46,9 @@ Add this line to your application's `Gemfile`, remember to `bundle install` afte
48
46
  gem 'coverband'
49
47
  ```
50
48
 
51
- If [tracking gem usage](#collecting-gem--library-usage), be sure to include coverband before other gems you would like to track.
52
-
53
49
  ## Rails
54
50
 
55
- The Railtie integration means you shouldn't need to do anything anything else other than ensure coverband is required after rails within your Gemfile.
51
+ The Railtie integration means you shouldn't need to do anything anything else. If you have an issue with that, please [file an issue](https://github.com/danmayer/coverband/issues).
56
52
 
57
53
 
58
54
  ## Sinatra
@@ -202,15 +198,6 @@ ENV['AWS_ACCESS_KEY_ID']
202
198
  ENV['AWS_SECRET_ACCESS_KEY']
203
199
  ```
204
200
 
205
- ### Coverage Data Migration
206
-
207
- Between the release of 4.0 and 4.1 our data format changed. This resets all your coverage data. If you want to restore your previous coverage data, feel free to migrate.
208
-
209
- `rake coverband:migrate`
210
-
211
- * We will be working to support migrations going forward, when possible
212
-
213
-
214
201
  ### Clear Coverage
215
202
 
216
203
  Now that Coverband uses MD5 hashes there should be no reason to manually clear coverage unless one is testing, changing versions, possibly debugging Coverband itself.
@@ -255,28 +242,16 @@ By adding any files above you will get reporting on those files as part of your
255
242
 
256
243
  ### Collecting Gem / Library Usage
257
244
 
258
- Gem usage can be tracked by enabling the `track_gems` config.
259
-
260
- ```
261
- Coverband.configure do |config|
262
- config.track_gems = true
263
- end
264
- ```
265
-
266
- The `track_gems` feature exposes a Gems tab in the report which prints out the percentage usage of each Gem. See demo [here](https://coverband-demo.herokuapp.com/coverage?#_Gems).
267
-
268
- When tracking gems, it is important that `Coverband#start` is called before the gems to be tracked are required. Since `Coverband#start` is automatically called by default when coverband is required, list coverband before the other gems to be tracked within your Gemfile. The exception to this are gems like rails and resque. Since coverband has some specific intergrations for these frameworks, these two gems should be required first.
245
+ By default Coverband has assumed you are trying to track your application code usage and not all the supporting framework and library (Gems) code usage. There are reasons to track library usage though such as finding out which Gems aren't actually being used within production. See some of the discussion on [issue 21](https://github.com/danmayer/coverband/issues/21).
269
246
 
270
- The track_gems config only exposes the overall usage of a gem. In order to see the detail of each file, enable the `gem_details` flag.
247
+ How to collect gem usage with Coverband:
271
248
 
272
- ```
273
- Coverband.configure do |config|
274
- config.track_gems = true
275
- config.gem_details = true
276
- end
277
- ```
249
+ * use the `safe_reload_files` feature to add the path of all gem files you wish to track
250
+ * --- or ---
251
+ * ensure you call `require 'coverband'` which triggers `Coverband.start` before loading all your gems
252
+ * while possible this is currently hard as Rails and most environments load your whole Gemfile
253
+ * we are looking for an improve and easier way to support this.
278
254
 
279
- This flag exposes line by line usage of gem files. Unfortunately due to the way the coverband report is currently rendered, enabling `gem_details` slows down viewing of the coverage report in the browser and is not yet recommended.
280
255
 
281
256
  ### Verbose Debug / Development Mode
282
257
 
data/Rakefile CHANGED
@@ -13,7 +13,7 @@ Rake::TestTask.new(:test) do |test|
13
13
  # exclude benchmark from the tests as the way it functions resets code coverage during executions
14
14
  # test.pattern = 'test/unit/*_test.rb'
15
15
  # using test files opposed to pattern as it outputs which files are run
16
- test.test_files = FileList['test/integration/**/*_test.rb', 'test/coverband/**/*_test.rb']
16
+ test.test_files = FileList['test/unit/**/*_test.rb']
17
17
  test.verbose = true
18
18
  end
19
19
 
data/changes.md CHANGED
@@ -36,7 +36,7 @@ Will be the fully modern release that drops maintenance legacy support in favor
36
36
  - Make good video on setup, install, usage
37
37
  - See if we can add support for views / templates
38
38
  - using this technique https://github.com/ioquatix/covered
39
- - Better default grouping (could use groups features for gems for rails controllers, models, lib, etc)
39
+ - Better default grouping (could use groups features for gems for rails controllers, models, lib, etc)
40
40
 
41
41
  ### Coverband_jam_session
42
42
 
@@ -63,36 +63,20 @@ Feature Ideas:
63
63
 
64
64
  # Alpha
65
65
 
66
- ### Coverband 4.2.0.rc
66
+ ### Coverband 4.2.0.alpha
67
67
 
68
- - loadtime vs runtime coverage
69
- - view coverage
70
- - perf speedup on gem details views
68
+ - pilot release of Gems tracking
69
+ - todos
70
+ - support multiple gem paths (various version managers setup multiple gem paths)
71
+ - speed up page load by allowing multiple pages
71
72
 
72
- # Released
73
-
74
- ### Coverband 4.1.1
75
-
76
- - fix bug on info page when using namespaces
77
- - fix bug related to forking Ruby processes (Resque for example)
78
- - bug caused negative line hits
79
- - bug seemed to cause memory leaks (not entirely sure how)
80
- - various test improvements
81
- - fix bad requests on coverband web admin to `/coverage/favicon.png`
82
- - improved documentation
83
-
84
- ### Coverband 4.1.0
73
+ ### Coverband 4.1.0.alpha
85
74
 
86
75
  - default disabled web clear, add config option to allow it
87
76
  - out of the box support for resque
88
77
  - readme improvements
89
- - fix on regression of merging directory changing deployments
90
- - fixes for duplicate root paths
91
- - pilot release of Gems tracking (disabled by default) - todos - support multiple gem paths (various version managers setup multiple gem paths) - speed up page load by allowing multiple pages
92
- - added web settings and debug views
93
- - added support for seeing coverage data size consumed in redis
94
- - support coverage data migrations from 4.0.x to 4.1.0
95
- - fixes for heroku /tmp asset building
78
+
79
+ # Released
96
80
 
97
81
  ### Coverband 4.0.1
98
82
 
@@ -102,7 +86,7 @@ Feature Ideas:
102
86
  - reduced the S3 dependencies to minimal set (not loading all of aws-sdk, only aws-sdk-s3), ensured they are optional
103
87
  - Improved Coverband web admin
104
88
  - Coverage reports include timestamps of Coverage collection
105
- - Added Coveralls to the dev process thanks @dondonz
89
+ - Added Coveralls to the dev process thanks @dondonz
106
90
  - now tested under Ruby 2.6.0 thanks @Kbaum
107
91
  - improved full stack testing for Rails 5 & 4
108
92
  - warning before clear coverage on coverband web
data/coverband.gemspec CHANGED
@@ -33,8 +33,6 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency 'rack-test'
34
34
  spec.add_development_dependency 'rake'
35
35
  spec.add_development_dependency 'resque'
36
- # temporarily needed to fun tests for classifier-reborn as part of benchmarks
37
- spec.add_development_dependency 'minitest-reporters'
38
36
 
39
37
  # TODO: used for benchmarking and tests I think we have other better benchmarking
40
38
  # perhaps time to drop this and refactor.
@@ -44,8 +42,6 @@ Gem::Specification.new do |spec|
44
42
  # require 'byebug'; byebug
45
43
  spec.add_development_dependency 'pry-byebug'
46
44
 
47
- spec.add_development_dependency 'minitest-profile'
48
-
49
45
  # TODO: Remove when other production adapters exist
50
46
  # because the default configuration of redis store, we really do require
51
47
  # redis now. I was reluctant to add this, but until we offer another production
data/lib/coverband.rb CHANGED
@@ -7,7 +7,6 @@ require 'redis'
7
7
  require 'coverband/version'
8
8
  require 'coverband/at_exit'
9
9
  require 'coverband/configuration'
10
- require 'coverband/utils/file_path_helper'
11
10
  require 'coverband/adapters/base'
12
11
  require 'coverband/adapters/redis_store'
13
12
  require 'coverband/adapters/file_store'
@@ -50,10 +49,6 @@ module Coverband
50
49
  end
51
50
  end
52
51
 
53
- def self.report_coverage(force_report = false)
54
- Coverband::Collectors::Coverage.instance.report_coverage(force_report)
55
- end
56
-
57
52
  def self.configuration
58
53
  self.configuration_data ||= Configuration.new
59
54
  end
@@ -3,8 +3,6 @@
3
3
  module Coverband
4
4
  module Adapters
5
5
  class Base
6
- include Coverband::Utils::FilePathHelper
7
-
8
6
  def initialize
9
7
  @file_hash_cache = {}
10
8
  end
@@ -13,25 +11,13 @@ module Coverband
13
11
  raise 'abstract'
14
12
  end
15
13
 
16
- def migrate!
17
- raise 'abstract'
18
- end
19
-
20
- def size
21
- raise 'abstract'
22
- end
23
-
24
- def size_in_mib
25
- format('%.2f', (size.to_f / 2**20))
26
- end
27
-
28
14
  # Note: This could lead to slight race on redis
29
15
  # where multiple processes pull the old coverage and add to it then push
30
16
  # the Coverband 2 had the same issue,
31
17
  # and the tradeoff has always been acceptable
32
18
  def save_report(report)
33
19
  data = report.dup
34
- data = merge_reports(data, get_report)
20
+ merge_reports(data, get_report)
35
21
  save_coverage(data)
36
22
  end
37
23
 
@@ -63,7 +49,6 @@ module Coverband
63
49
  end
64
50
 
65
51
  def expand_report(report)
66
- expanded = {}
67
52
  report_time = Time.now.to_i
68
53
  report.each_pair do |key, line_data|
69
54
  extended_data = {
@@ -72,13 +57,12 @@ module Coverband
72
57
  'file_hash' => file_hash(key),
73
58
  'data' => line_data
74
59
  }
75
- expanded[full_path_to_relative(key)] = extended_data
60
+ report[key] = extended_data
76
61
  end
77
- expanded
78
62
  end
79
63
 
80
- def merge_reports(new_report, old_report, options = {})
81
- new_report = expand_report(new_report) unless options[:skip_expansion]
64
+ def merge_reports(new_report, old_report)
65
+ new_report = expand_report(new_report)
82
66
  keys = (new_report.keys + old_report.keys).uniq
83
67
  keys.each do |file|
84
68
  new_report[file] = if new_report[file] &&
@@ -20,14 +20,6 @@ module Coverband
20
20
  File.delete(path) if File.exist?(path)
21
21
  end
22
22
 
23
- def size
24
- File.size?(path).to_i
25
- end
26
-
27
- def migrate!
28
- raise NotImplementedError, "FileStore doesn't support migrations"
29
- end
30
-
31
23
  private
32
24
 
33
25
  attr_accessor :path
@@ -11,56 +11,25 @@ module Coverband
11
11
  # used to store data to redis. It is changed only when breaking changes to our
12
12
  # redis format are required.
13
13
  ###
14
- REDIS_STORAGE_FORMAT_VERSION = 'coverband_3_2'
14
+ REDIS_STORAGE_FORMAT_VERSION = 'coverband3_1'
15
15
 
16
16
  def initialize(redis, opts = {})
17
17
  super()
18
18
  @redis = redis
19
19
  @ttl = opts[:ttl]
20
20
  @redis_namespace = opts[:redis_namespace]
21
- @format_version = REDIS_STORAGE_FORMAT_VERSION
22
21
  end
23
22
 
24
23
  def clear!
25
24
  @redis.del(base_key)
26
25
  end
27
26
 
28
- def size
29
- @redis.get(base_key).bytesize
30
- end
31
-
32
- ###
33
- # Current implementation moves from coverband3_1 to coverband_3_2
34
- # In the future this can be made more general and support a more specific
35
- # version format.
36
- ###
37
- def migrate!
38
- reset_base_key
39
- @format_version = 'coverband3_1'
40
- previous_data = get_report
41
- if previous_data.empty?
42
- puts 'no previous data to migrate found'
43
- exit 0
44
- end
45
- relative_path_report = previous_data.each_with_object({}) do |(key, vals), fixed_report|
46
- fixed_report[full_path_to_relative(key)] = vals
47
- end
48
- clear!
49
- reset_base_key
50
- @format_version = REDIS_STORAGE_FORMAT_VERSION
51
- save_coverage(merge_reports(get_report, relative_path_report, skip_expansion: true))
52
- end
53
-
54
27
  private
55
28
 
56
29
  attr_reader :redis
57
30
 
58
- def reset_base_key
59
- @base_key = nil
60
- end
61
-
62
31
  def base_key
63
- @base_key ||= [@format_version, @redis_namespace].compact.join('.')
32
+ @base_key ||= [REDIS_STORAGE_FORMAT_VERSION, @redis_namespace].compact.join('.')
64
33
  end
65
34
 
66
35
  def save_coverage(data)
@@ -11,7 +11,7 @@ module Coverband
11
11
  @at_exit_registered = true
12
12
  at_exit do
13
13
  ::Coverband::Background.stop
14
- Coverband.report_coverage(true)
14
+ Coverband::Collectors::Coverage.instance.report_coverage(true)
15
15
  Coverband.configuration.logger&.debug('Coverband: Reported coverage before exit')
16
16
  end
17
17
  end
@@ -87,13 +87,7 @@ module Coverband
87
87
  end
88
88
 
89
89
  def array_diff(latest, original)
90
- latest.map.with_index do |v, i|
91
- if (v && original[i])
92
- [0, v - original[i]].max
93
- else
94
- nil
95
- end
96
- end
90
+ latest.map.with_index { |v, i| (v && original[i]) ? v - original[i] : nil }
97
91
  end
98
92
 
99
93
  def previous_results
@@ -8,7 +8,7 @@ module Coverband
8
8
  :redis_namespace, :redis_ttl,
9
9
  :safe_reload_files, :background_reporting_enabled,
10
10
  :background_reporting_sleep_seconds, :test_env,
11
- :web_enable_clear, :gem_details, :web_debug
11
+ :web_enable_clear, :gem_details
12
12
 
13
13
  attr_writer :logger, :s3_region, :s3_bucket, :s3_access_key_id, :s3_secret_access_key
14
14
  attr_reader :track_gems
@@ -20,10 +20,7 @@ module Coverband
20
20
  def reset
21
21
  @root = Dir.pwd
22
22
  @root_paths = []
23
- # Heroku when building assets runs code from a dynamic directory
24
- # /tmp was added to avoid coverage from /tmp/build directories during
25
- # heroku asset compilation
26
- @ignore = %w[vendor .erb$ .slim$ /tmp]
23
+ @ignore = %w(vendor .erb$ .slim$)
27
24
  @additional_files = []
28
25
  @reporting_frequency = 0.0
29
26
  @verbose = false
@@ -37,7 +34,6 @@ module Coverband
37
34
  @track_gems = false
38
35
  @gem_details = false
39
36
  @groups = {}
40
- @web_debug = false
41
37
 
42
38
  # TODO: should we push these to adapter configs
43
39
  @s3_region = nil
@@ -87,11 +83,6 @@ module Coverband
87
83
  def track_gems=(value)
88
84
  @track_gems = value
89
85
  return unless @track_gems
90
- # by default we ignore vendor where many deployments put gems
91
- # we will remove this default if track_gems is set
92
- @ignore.delete('vendor')
93
- # while we want to allow vendored gems we don't want to track vendored ruby STDLIB
94
- @ignore << 'vendor/ruby-*'
95
86
  add_group('App', root)
96
87
  # TODO: rework support for multiple gem paths
97
88
  # currently this supports GEM_HOME (which should be first path)
@@ -124,25 +115,6 @@ module Coverband
124
115
  Gem::PathSupport.new(ENV).path.select { |path| File.exist?(path) }
125
116
  end
126
117
 
127
- def current_root
128
- File.expand_path(Coverband.configuration.root)
129
- end
130
-
131
- def all_root_paths
132
- roots = Coverband.configuration.root_paths.dup
133
- roots += Coverband.configuration.gem_paths.dup if Coverband.configuration.track_gems
134
- roots << "#{Coverband.configuration.current_root}/"
135
- roots
136
- end
137
-
138
- SKIPPED_SETTINGS = %w(@s3_secret_access_key @store)
139
- def to_h
140
- instance_variables
141
- .each_with_object('gem_paths': gem_paths) do |var, hash|
142
- hash[var.to_s.delete('@')] = instance_variable_get(var) unless SKIPPED_SETTINGS.include?(var.to_s)
143
- end
144
- end
145
-
146
118
  private
147
119
 
148
120
  def redis_url