coverband 4.1.0.beta → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 455614fde267b2ba0264e2949996587a342059f0
4
- data.tar.gz: 6246b3c559c1d68d895928ceccdd8ebb8211934a
3
+ metadata.gz: b7070c0b3648d9f4fe856175711373dbddc19df4
4
+ data.tar.gz: d31f4e2ae34e9ad28cbf93fa6e7bcebeb99a9c52
5
5
  SHA512:
6
- metadata.gz: e2c4d201b82e29c772bc201aea5eecc5d3edc79746dbaf0838497b73def8fbb23c8b394b4e218ae9fd6a0e0b9a9df05fd71baa63ecbbf88768afe67fb0259dcb
7
- data.tar.gz: ebce43a1554a11de5c8f0c280a32b89a762e44e8a68228e7fb63e3ef1855e0617018bfb6e052492b664708061e0ffc4d6350a2ce02b1f5bed568022b8f3c597f
6
+ metadata.gz: 630244e791fe41a7f5d53b89a6d2782764252fd6f8f7eecb37eab9259928bf422e1a2a6282dc046e0c6fdbc7d2b3581c8a1eeb9584670848fc1b678b5ab0629e
7
+ data.tar.gz: b03947618d4e2b51a27a84438de3c5cc5d1da4f9a5024e4d9d6cf00d39f652874ecc0f0c0ae2a6d475b90a8bfa792c133a01696084f337f4c7146d567a8044f9
data/README.md CHANGED
@@ -198,6 +198,15 @@ ENV['AWS_ACCESS_KEY_ID']
198
198
  ENV['AWS_SECRET_ACCESS_KEY']
199
199
  ```
200
200
 
201
+ ### Coverage Data Migration
202
+
203
+ 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.
204
+
205
+ `rake coverband:migrate`
206
+
207
+ * We will be working to support migrations going forward, when possible
208
+
209
+
201
210
  ### Clear Coverage
202
211
 
203
212
  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.
data/changes.md CHANGED
@@ -73,14 +73,34 @@ Feature Ideas:
73
73
  - out of the box support for resque
74
74
  - readme improvements
75
75
  - fix on regression of merging directory changing deployments
76
+ - fixes for duplicate root paths
76
77
  - pilot release of Gems tracking (disabled by default)
77
78
  - todos
78
79
  - support multiple gem paths (various version managers setup multiple gem paths)
79
80
  - speed up page load by allowing multiple pages
80
81
  - added web settings and debug views
82
+ - added support for seeing coverage data size consumed in redis
83
+ - support coverage data migrations from 4.0.x to 4.1.0
84
+ - fixes for heroku /tmp asset building
81
85
 
82
86
  # Released
83
87
 
88
+ ### Coverband 4.1.0
89
+
90
+ - default disabled web clear, add config option to allow it
91
+ - out of the box support for resque
92
+ - readme improvements
93
+ - fix on regression of merging directory changing deployments
94
+ - fixes for duplicate root paths
95
+ - pilot release of Gems tracking (disabled by default)
96
+ - todos
97
+ - support multiple gem paths (various version managers setup multiple gem paths)
98
+ - speed up page load by allowing multiple pages
99
+ - added web settings and debug views
100
+ - added support for seeing coverage data size consumed in redis
101
+ - support coverage data migrations from 4.0.x to 4.1.0
102
+ - fixes for heroku /tmp asset building
103
+
84
104
  ### Coverband 4.0.1
85
105
 
86
106
  - drops Simplecov runtime dependency
data/lib/coverband.rb CHANGED
@@ -7,6 +7,7 @@ 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'
10
11
  require 'coverband/adapters/base'
11
12
  require 'coverband/adapters/redis_store'
12
13
  require 'coverband/adapters/file_store'
@@ -49,6 +50,10 @@ module Coverband
49
50
  end
50
51
  end
51
52
 
53
+ def self.report_coverage(force_report = false)
54
+ Coverband::Collectors::Coverage.instance.report_coverage(force_report)
55
+ end
56
+
52
57
  def self.configuration
53
58
  self.configuration_data ||= Configuration.new
54
59
  end
@@ -3,6 +3,8 @@
3
3
  module Coverband
4
4
  module Adapters
5
5
  class Base
6
+ include Coverband::Utils::FilePathHelper
7
+
6
8
  def initialize
7
9
  @file_hash_cache = {}
8
10
  end
@@ -11,13 +13,25 @@ module Coverband
11
13
  raise 'abstract'
12
14
  end
13
15
 
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
+
14
28
  # Note: This could lead to slight race on redis
15
29
  # where multiple processes pull the old coverage and add to it then push
16
30
  # the Coverband 2 had the same issue,
17
31
  # and the tradeoff has always been acceptable
18
32
  def save_report(report)
19
33
  data = report.dup
20
- merge_reports(data, get_report)
34
+ data = merge_reports(data, get_report)
21
35
  save_coverage(data)
22
36
  end
23
37
 
@@ -49,6 +63,7 @@ module Coverband
49
63
  end
50
64
 
51
65
  def expand_report(report)
66
+ expanded = {}
52
67
  report_time = Time.now.to_i
53
68
  report.each_pair do |key, line_data|
54
69
  extended_data = {
@@ -57,12 +72,13 @@ module Coverband
57
72
  'file_hash' => file_hash(key),
58
73
  'data' => line_data
59
74
  }
60
- report[key] = extended_data
75
+ expanded[full_path_to_relative(key)] = extended_data
61
76
  end
77
+ expanded
62
78
  end
63
79
 
64
- def merge_reports(new_report, old_report)
65
- new_report = expand_report(new_report)
80
+ def merge_reports(new_report, old_report, options = {})
81
+ new_report = expand_report(new_report) unless options[:skip_expansion]
66
82
  keys = (new_report.keys + old_report.keys).uniq
67
83
  keys.each do |file|
68
84
  new_report[file] = if new_report[file] &&
@@ -20,6 +20,14 @@ 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
+
23
31
  private
24
32
 
25
33
  attr_accessor :path
@@ -11,25 +11,56 @@ 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 = 'coverband3_1'
14
+ REDIS_STORAGE_FORMAT_VERSION = 'coverband_3_2'
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
21
22
  end
22
23
 
23
24
  def clear!
24
25
  @redis.del(base_key)
25
26
  end
26
27
 
28
+ def size
29
+ @redis.get(REDIS_STORAGE_FORMAT_VERSION).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
+
27
54
  private
28
55
 
29
56
  attr_reader :redis
30
57
 
58
+ def reset_base_key
59
+ @base_key = nil
60
+ end
61
+
31
62
  def base_key
32
- @base_key ||= [REDIS_STORAGE_FORMAT_VERSION, @redis_namespace].compact.join('.')
63
+ @base_key ||= [@format_version, @redis_namespace].compact.join('.')
33
64
  end
34
65
 
35
66
  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::Collectors::Coverage.instance.report_coverage(true)
14
+ Coverband.report_coverage(true)
15
15
  Coverband.configuration.logger&.debug('Coverband: Reported coverage before exit')
16
16
  end
17
17
  end
@@ -20,7 +20,10 @@ module Coverband
20
20
  def reset
21
21
  @root = Dir.pwd
22
22
  @root_paths = []
23
- @ignore = %w[vendor .erb$ .slim$]
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]
24
27
  @additional_files = []
25
28
  @reporting_frequency = 0.0
26
29
  @verbose = false
@@ -121,7 +124,18 @@ module Coverband
121
124
  Gem::PathSupport.new(ENV).path.select { |path| File.exist?(path) }
122
125
  end
123
126
 
124
- SKIPPED_SETTINGS = %w[@s3_secret_access_key @store]
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)
125
139
  def to_h
126
140
  instance_variables
127
141
  .each_with_object('gem_paths': gem_paths) do |var, hash|
@@ -5,6 +5,7 @@ module Coverband
5
5
  @semaphore = Mutex.new
6
6
 
7
7
  def self.stop
8
+ return unless @thread
8
9
  @semaphore.synchronize do
9
10
  if @thread
10
11
  @thread.exit
@@ -13,6 +14,10 @@ module Coverband
13
14
  end
14
15
  end
15
16
 
17
+ def self.running?
18
+ !!@thread
19
+ end
20
+
16
21
  def self.start
17
22
  return if @thread
18
23
 
@@ -23,7 +28,7 @@ module Coverband
23
28
  sleep_seconds = Coverband.configuration.background_reporting_sleep_seconds
24
29
  @thread = Thread.new do
25
30
  loop do
26
- Coverband::Collectors::Coverage.instance.report_coverage(true)
31
+ Coverband.report_coverage(true)
27
32
  logger&.debug("Coverband: Reported coverage via thread. Sleeping #{sleep_seconds}s") if Coverband.configuration.verbose
28
33
  sleep(sleep_seconds)
29
34
  end
@@ -4,12 +4,18 @@ Resque.after_fork do |job|
4
4
  Coverband.start
5
5
  end
6
6
 
7
+ Resque.before_first_fork do
8
+ Coverband.configuration.background_reporting_enabled = false
9
+ Coverband::Background.stop
10
+ Coverband::Collectors::Coverage.instance.report_coverage(true)
11
+ end
12
+
7
13
  module Coverband
8
14
  module ResqueWorker
9
15
  def perform
10
16
  super
11
17
  ensure
12
- Coverband::Collectors::Coverage.instance.report_coverage(true)
18
+ Coverband.report_coverage(true)
13
19
  end
14
20
  end
15
21
  end
@@ -8,8 +8,10 @@ module Coverband
8
8
  ###
9
9
  class Base
10
10
  class << self
11
+ include Coverband::Utils::FilePathHelper
11
12
  def report(store, _options = {})
12
- scov_style_report = get_current_scov_data_imp(store, root_paths)
13
+ all_roots = Coverband.configuration.all_root_paths
14
+ scov_style_report = get_current_scov_data_imp(store, all_roots)
13
15
 
14
16
  if Coverband.configuration.verbose
15
17
  msg = "report:\n #{scov_style_report.inspect}"
@@ -20,17 +22,6 @@ module Coverband
20
22
 
21
23
  protected
22
24
 
23
- def root_paths
24
- roots = Coverband.configuration.root_paths
25
- roots += Coverband.configuration.gem_paths if Coverband.configuration.track_gems
26
- roots << "#{current_root}/"
27
- roots
28
- end
29
-
30
- def current_root
31
- File.expand_path(Coverband.configuration.root)
32
- end
33
-
34
25
  def fix_file_names(report_hash, roots)
35
26
  if Coverband.configuration.verbose
36
27
  Coverband.configuration.logger.info "fixing root: #{roots.join(', ')}"
@@ -38,7 +29,7 @@ module Coverband
38
29
 
39
30
  # normalize names across servers
40
31
  report_hash.each_with_object({}) do |(key, vals), fixed_report|
41
- filename = filename_from_key(key, roots)
32
+ filename = relative_path_to_full(key, roots)
42
33
  fixed_report[filename] = if fixed_report.key?(filename) && fixed_report[filename]['data'] && vals['data']
43
34
  merged_data = merge_arrays(fixed_report[filename]['data'], vals['data'])
44
35
  vals['data'] = merged_data
@@ -64,40 +55,6 @@ module Coverband
64
55
  merged
65
56
  end
66
57
 
67
- ###
68
- # filename_from_key code takes:
69
- # key: which is a full path the same as reported by Coverage
70
- # roots: if a collection of all possible full app paths
71
- # EX: [Coverband.configuration.root_paths, "#{current_root}/"]
72
- # The LAST item should be the current file system root
73
- # it expands that expands and adds a '/' as that isn't there from Dir.pwd
74
- #
75
- # NOTEs on configuration.root_paths usage
76
- # strings: matching is pretty simple for full string paths
77
- # regex: to get regex to work for changing deploy directories
78
- # the regex must be double escaped in double quotes
79
- # (if using \d for example)
80
- # or use single qoutes
81
- # example: '/box/apps/app_name/releases/\d+/'
82
- # example: '/var/local/company/company.d/[0-9]*/'
83
- ###
84
- def filename_from_key(key, roots)
85
- relative_filename = key
86
- local_filename = relative_filename
87
- roots.each do |root|
88
- relative_filename = relative_filename.gsub(/^#{root}/, './')
89
- end
90
- # the filename for our reports is expected to be a full path.
91
- # roots.last should be roots << current_root}/
92
- # a fully expanded path of config.root
93
- # filename = filename.gsub('./', roots.last)
94
- # above only works for app files
95
- # we need to rethink some of this logic
96
- # gems aren't at project root and can have multiple locations
97
- local_root = roots.find { |root| File.exist?(relative_filename.gsub('./', root)) }
98
- local_root ? relative_filename.gsub('./', local_root) : local_filename
99
- end
100
-
101
58
  ###
102
59
  # why do we need to merge covered files data?
103
60
  # basically because paths on machines or deployed hosts could be different, so
@@ -11,7 +11,7 @@ module Coverband
11
11
  base_path = options.fetch(:base_path) { nil }
12
12
 
13
13
  # list all files, even if not tracked by Coverband (0% coverage)
14
- tracked_glob = "#{current_root}/{app,lib,config}/**/*.{rb}"
14
+ tracked_glob = "#{Coverband.configuration.current_root}/{app,lib,config}/**/*.{rb}"
15
15
  report_files = Coverband::Utils::Result.add_not_loaded_files(scov_style_report, tracked_glob)
16
16
  # apply coverband filters
17
17
  filtered_report_files = {}
@@ -66,7 +66,7 @@ module Coverband
66
66
  end
67
67
 
68
68
  def collect_coverage
69
- Coverband::Collectors::Coverage.instance.report_coverage(true)
69
+ Coverband.report_coverage(true)
70
70
  notice = 'coverband coverage collected'
71
71
  [301, { 'Location' => "#{base_path}?notice=#{notice}" }, []]
72
72
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ ####
4
+ # Helper functions for shared logic related to file path manipulation
5
+ ####
6
+ module Coverband
7
+ module Utils
8
+ module FilePathHelper
9
+ ###
10
+ # Takes a full path and converts to a relative path
11
+ ###
12
+ def full_path_to_relative(full_path)
13
+ relative_filename = full_path
14
+ Coverband.configuration.all_root_paths.each do |root|
15
+ relative_filename = relative_filename.gsub(/^#{root}/, './')
16
+ # once we have a relative path break out of the loop
17
+ break if relative_filename.start_with? './'
18
+ end
19
+ relative_filename
20
+ end
21
+
22
+ ###
23
+ # relative_path_to_full code takes:
24
+ # relative_path: which is a full path the same as reported by Coverage
25
+ # roots: if a collection of all possible full app paths
26
+ # EX: [Coverband.configuration.root_paths, "#{current_root}/"]
27
+ # The LAST item should be the current file system root
28
+ # it expands that expands and adds a '/' as that isn't there from Dir.pwd
29
+ #
30
+ # NOTEs on configuration.root_paths usage
31
+ # strings: matching is pretty simple for full string paths
32
+ # regex: to get regex to work for changing deploy directories
33
+ # the regex must be double escaped in double quotes
34
+ # (if using \d for example)
35
+ # or use single qoutes
36
+ # example: '/box/apps/app_name/releases/\d+/'
37
+ # example: '/var/local/company/company.d/[0-9]*/'
38
+ ###
39
+ def relative_path_to_full(relative_path, roots)
40
+ relative_filename = relative_path
41
+ local_filename = relative_filename
42
+ roots.each do |root|
43
+ relative_filename = relative_filename.gsub(/^#{root}/, './')
44
+ end
45
+ # the filename for our reports is expected to be a full path.
46
+ # roots.last should be roots << current_root}/
47
+ # a fully expanded path of config.root
48
+ # filename = filename.gsub('./', roots.last)
49
+ # above only works for app files
50
+ # we need to rethink some of this logic
51
+ # gems aren't at project root and can have multiple locations
52
+ local_root = roots.find { |root| File.exist?(relative_filename.gsub('./', root)) }
53
+ local_root ? relative_filename.gsub('./', local_root) : local_filename
54
+ end
55
+ end
56
+ end
57
+ end
@@ -7,7 +7,7 @@ module Coverband
7
7
  end
8
8
 
9
9
  config.after_initialize do
10
- Coverband::Collectors::Coverage.instance.report_coverage(true)
10
+ Coverband.report_coverage(true)
11
11
  end
12
12
 
13
13
  rake_tasks do
@@ -25,4 +25,13 @@ namespace :coverband do
25
25
  environment
26
26
  Coverband.configuration.store.clear!
27
27
  end
28
+
29
+ ###
30
+ # clear data helpful for development or after configuration issues
31
+ ###
32
+ desc 'upgrade previous Coverband datastore to latest format'
33
+ task :migrate do
34
+ environment
35
+ Coverband.configuration.store.migrate!
36
+ end
28
37
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Coverband
4
- VERSION = '4.1.0.beta'
4
+ VERSION = '4.1.0'
5
5
  end
@@ -134,7 +134,7 @@ namespace :benchmarks do
134
134
  x.config(time: 12, warmup: 5, suite: suite)
135
135
  x.report 'coverband' do
136
136
  work
137
- Coverband::Collectors::Coverage.instance.report_coverage
137
+ Coverband.report_coverage(true)
138
138
  end
139
139
  x.report 'no coverband' do
140
140
  work
@@ -176,6 +176,10 @@ namespace :benchmarks do
176
176
  @file_hash_cache[file] = Digest::MD5.file(__FILE__).hexdigest
177
177
  end
178
178
  end
179
+
180
+ def store.full_path_to_relative(file)
181
+ file
182
+ end
179
183
  end
180
184
 
181
185
  def reporting_speed
@@ -44,5 +44,10 @@ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.3.0')
44
44
  @coverband.reset_instance
45
45
  @coverband.report_coverage
46
46
  end
47
+
48
+ test 'default tmp ignores' do
49
+ heroku_build_file = '/tmp/build_81feca8c72366e4edf020dc6f1937485/config/initializers/assets.rb'
50
+ assert_equal false, @coverband.send(:track_file?, heroku_build_file)
51
+ end
47
52
  end
48
53
  end
@@ -16,22 +16,32 @@ class BaseTest < Minitest::Test
16
16
  end
17
17
  end
18
18
 
19
- test 'defaults ' do
19
+ test 'defaults' do
20
20
  coverband = Coverband::Collectors::Coverage.instance.reset_instance
21
21
  assert_equal ['vendor', 'internal:prelude', 'schema.rb'], coverband.instance_variable_get('@ignore_patterns')
22
22
  end
23
23
 
24
- test 'gem_paths ' do
24
+ test 'gem_paths' do
25
25
  Coverband::Collectors::Coverage.instance.reset_instance
26
26
  assert Coverband.configuration.gem_paths.first != nil
27
27
  end
28
28
 
29
- test 'groups ' do
29
+ test 'groups' do
30
30
  Coverband::Collectors::Coverage.instance.reset_instance
31
31
  Coverband.configuration.track_gems = true
32
32
  assert_equal %w(App Gems), Coverband.configuration.groups.keys
33
33
  end
34
34
 
35
+ test 'all_root_paths' do
36
+ Coverband::Collectors::Coverage.instance.reset_instance
37
+ current_paths = Coverband.configuration.root_paths.dup
38
+ # verify previous bug fix
39
+ # it would extend the root_paths instance variable on each invokation
40
+ Coverband.configuration.all_root_paths
41
+ Coverband.configuration.all_root_paths
42
+ assert_equal current_paths, Coverband.configuration.root_paths
43
+ end
44
+
35
45
  test 's3 options' do
36
46
  Coverband::Collectors::Coverage.instance.reset_instance
37
47
  Coverband.configure do |config|
@@ -6,6 +6,7 @@ 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'
9
10
 
10
11
  def setup
11
12
  super
@@ -15,6 +16,7 @@ class FullStackTest < Minitest::Test
15
16
  config.store = Coverband::Adapters::RedisStore.new(Redis.new)
16
17
  config.s3_bucket = nil
17
18
  config.background_reporting_enabled = false
19
+ config.root_paths = ["#{File.expand_path('../', File.dirname(__FILE__))}/"]
18
20
  end
19
21
  Coverband.configuration.store.clear!
20
22
  Coverband.start
@@ -29,13 +31,13 @@ class FullStackTest < Minitest::Test
29
31
  assert_equal 'Hello Rack!', results.last
30
32
  sleep(0.1)
31
33
  expected = [nil, nil, 1, nil, 1, 1, 1, nil, nil]
32
- assert_equal expected, Coverband.configuration.store.coverage[@rack_file]['data']
34
+ assert_equal expected, Coverband.configuration.store.coverage[RELATIVE_FILE]['data']
33
35
 
34
36
  # additional calls increase count by 1
35
37
  middleware.call(request)
36
38
  sleep(0.1)
37
39
  expected = [nil, nil, 1, nil, 1, 1, 2, nil, nil]
38
- assert_equal expected, Coverband.configuration.store.coverage[@rack_file]['data']
40
+ assert_equal expected, Coverband.configuration.store.coverage[RELATIVE_FILE]['data']
39
41
  end
40
42
 
41
43
  test 'call app with gem tracking' do
@@ -10,6 +10,7 @@ class RailsFullStackTest < Minitest::Test
10
10
  super
11
11
  # The normal relative directory lookup of coverband won't work for our dummy rails project
12
12
  Coverband.configure("./test/rails#{Rails::VERSION::MAJOR}_dummy/config/coverband.rb")
13
+ Coverband.configuration.background_reporting_enabled = false
13
14
  Coverband.start
14
15
  end
15
16
 
@@ -21,8 +22,8 @@ class RailsFullStackTest < Minitest::Test
21
22
 
22
23
  test 'this is how we do it' do
23
24
  visit '/dummy/show'
25
+ Coverband.report_coverage(true)
24
26
  assert_content('I am no dummy')
25
- sleep 0.2
26
27
  visit '/coverage'
27
28
  within page.find('a', text: /dummy_controller.rb/).find(:xpath, '../..') do
28
29
  assert_selector('td', text: '100.0 %')
@@ -46,7 +47,7 @@ class RailsFullStackTest < Minitest::Test
46
47
  3.times do
47
48
  visit '/dummy/show'
48
49
  assert_content('I am no dummy')
49
- Coverband::Collectors::Coverage.instance.report_coverage(true)
50
+ Coverband.report_coverage(true)
50
51
  end
51
52
 
52
53
  previous_out = $stdout
@@ -57,7 +58,7 @@ class RailsFullStackTest < Minitest::Test
57
58
  15.times do
58
59
  visit '/dummy/show'
59
60
  assert_content('I am no dummy')
60
- Coverband::Collectors::Coverage.instance.report_coverage(true)
61
+ Coverband.report_coverage(true)
61
62
  # this is expected to retain memory across requests
62
63
  # clear it to remove the false positive from test
63
64
  Coverband::Collectors::Coverage.instance.send(:add_previous_results, nil)
@@ -12,6 +12,7 @@ class RailsGemsFullStackTest < Minitest::Test
12
12
  Coverband.configure("./test/rails#{Rails::VERSION::MAJOR}_dummy/config/coverband.rb")
13
13
  Coverband.configuration.track_gems = true
14
14
  Coverband.configuration.gem_details = true
15
+ Coverband.configuration.background_reporting_enabled = false
15
16
  Coverband.start
16
17
  require 'rainbow'
17
18
  Rainbow('this text is red').red
@@ -26,7 +27,7 @@ class RailsGemsFullStackTest < Minitest::Test
26
27
  test 'this is how gem it' do
27
28
  visit '/dummy/show'
28
29
  assert_content('I am no dummy')
29
- sleep 0.2
30
+ Coverband.report_coverage(true)
30
31
  visit '/coverage'
31
32
  assert_content('Coverband Admin')
32
33
  assert_content('Gems')
@@ -3,7 +3,7 @@
3
3
  require File.expand_path('../test_helper', File.dirname(__FILE__))
4
4
 
5
5
  class ReportsBaseTest < Minitest::Test
6
- test 'filename_from_key fix filename from a key with a swappable path' do
6
+ test 'relative_path_to_full fix filename from a key with a swappable path' do
7
7
  Coverband.configure do |config|
8
8
  config.reporter = 'std_out'
9
9
  config.root = '/full/remote_app/path'
@@ -16,10 +16,10 @@ class ReportsBaseTest < Minitest::Test
16
16
  expected_path = '/full/remote_app/path/is/a/path.rb'
17
17
  File.expects(:exist?).with(key).returns(false)
18
18
  File.expects(:exist?).with(expected_path).returns(true)
19
- assert_equal expected_path, Coverband::Reporters::Base.send(:filename_from_key, key, roots)
19
+ assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
20
20
  end
21
21
 
22
- test 'filename_from_key fix filename a changing deploy path with quotes' do
22
+ test 'relative_path_to_full fix filename a changing deploy path with quotes' do
23
23
  Coverband.configure do |config|
24
24
  config.reporter = 'std_out'
25
25
  config.root = '/full/remote_app/path'
@@ -30,14 +30,14 @@ class ReportsBaseTest < Minitest::Test
30
30
  roots = ["/box/apps/app_name/releases/\\d+/", '/full/remote_app/path/']
31
31
  File.expects(:exist?).with('/box/apps/app_name/releases/\\d+/app/models/user.rb').returns(false)
32
32
  File.expects(:exist?).with(expected_path).returns(true)
33
- assert_equal expected_path, Coverband::Reporters::Base.send(:filename_from_key, key, roots)
33
+ assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
34
34
  File.expects(:exist?).with('/box/apps/app_name/releases/\\d+/app/models/user.rb').returns(false)
35
35
  File.expects(:exist?).with(expected_path).returns(true)
36
36
  roots = ['/box/apps/app_name/releases/\d+/', '/full/remote_app/path/']
37
- assert_equal expected_path, Coverband::Reporters::Base.send(:filename_from_key, key, roots)
37
+ assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
38
38
  end
39
39
 
40
- test 'filename_from_key fix filename a changing deploy path real world examples' do
40
+ test 'relative_path_to_full fix filename a changing deploy path real world examples' do
41
41
  current_app_root = '/var/local/company/company.d/79'
42
42
  Coverband.configure do |config|
43
43
  config.reporter = 'std_out'
@@ -50,14 +50,14 @@ class ReportsBaseTest < Minitest::Test
50
50
  File.expects(:exist?).with('/var/local/company/company.d/[0-9]*/app/controllers/dashboard_controller.rb').returns(false)
51
51
  File.expects(:exist?).with(expected_path).returns(true)
52
52
  roots = ['/var/local/company/company.d/[0-9]*/', "#{current_app_root}/"]
53
- assert_equal expected_path, Coverband::Reporters::Base.send(:filename_from_key, key, roots)
53
+ assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
54
54
  File.expects(:exist?).with('/var/local/company/company.d/[0-9]*/app/controllers/dashboard_controller.rb').returns(false)
55
55
  File.expects(:exist?).with(expected_path).returns(true)
56
56
  roots = ["/var/local/company/company.d/[0-9]*/", "#{current_app_root}/"]
57
- assert_equal expected_path, Coverband::Reporters::Base.send(:filename_from_key, key, roots)
57
+ assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
58
58
  end
59
59
 
60
- test 'filename_from_key leave filename from a key with a local path' do
60
+ test 'relative_path_to_full leave filename from a key with a local path' do
61
61
  Coverband.configure do |config|
62
62
  config.reporter = 'std_out'
63
63
  config.root = '/full/remote_app/path'
@@ -68,7 +68,7 @@ class ReportsBaseTest < Minitest::Test
68
68
  roots = ['/app/', '/full/remote_app/path/']
69
69
 
70
70
  expected_path = '/full/remote_app/path/is/a/path.rb'
71
- assert_equal expected_path, Coverband::Reporters::Base.send(:filename_from_key, key, roots)
71
+ assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
72
72
  end
73
73
 
74
74
  test '#merge_arrays basic merge preserves order and counts' do
@@ -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
29
  report = Coverband::Reporters::ConsoleReport.report(@store)
29
- expected = { 'app_path/dog.rb' => [0, 1, 2] }
30
+ expected = { './dog.rb' => [0, 1, 2] }
30
31
  assert_equal(expected.keys, report.keys)
31
32
  end
32
33
  end
@@ -6,13 +6,16 @@ class ResqueWorkerTest < Minitest::Test
6
6
  def enqueue_and_run_job
7
7
  Resque.enqueue(TestResqueJob)
8
8
  queue = ENV['QUEUE'] ='resque_coverband'
9
- Resque::Worker.new.work_one_job
9
+ worker = Resque::Worker.new
10
+ worker.startup
11
+ worker.work_one_job
10
12
  end
11
13
 
12
14
  def setup
13
15
  super
14
16
  Coverband.configure do |config|
15
17
  config.background_reporting_enabled = false
18
+ config.root_paths = ["#{File.expand_path('../', File.dirname(__FILE__))}/"]
16
19
  end
17
20
  Coverband.start
18
21
  redis = Coverband.configuration.store.send(:redis)
@@ -20,16 +23,14 @@ class ResqueWorkerTest < Minitest::Test
20
23
  end
21
24
 
22
25
  test 'resque job coverage' do
26
+ relative_job_file = './unit/test_resque_job.rb'
23
27
  resque_job_file = File.expand_path('./test_resque_job.rb', File.dirname(__FILE__))
24
28
  require resque_job_file
25
29
 
26
- #report after loading the file in parent process
27
- Coverband::Collectors::Coverage.instance.report_coverage(true)
28
-
29
30
  enqueue_and_run_job
30
31
 
31
- puts "assert_equal 1, Coverband.configuration.store.coverage['#{resque_job_file}']['data'][4]"
32
- assert_equal 1, Coverband.configuration.store.coverage[resque_job_file]['data'][4]
32
+ assert !Coverband::Background.running?
33
+
34
+ assert_equal 1, Coverband.configuration.store.coverage[relative_job_file]['data'][4]
33
35
  end
34
36
  end
35
-
data/views/layout.erb CHANGED
@@ -16,7 +16,7 @@
16
16
  <div id="wrapper" style="display:none;">
17
17
  <div id="header">
18
18
  <a href='<%= base_path %>'>Coverband Admin</a> &nbsp;
19
- <a href='<%= base_path %>settings'>Settings</a> &nbsp;
19
+ <a href='<%= base_path %>settings'>Info</a> &nbsp;
20
20
  <%= button("#{base_path}collect_coverage", 'force coverage collection') %> &nbsp;
21
21
  <%= button("#{base_path}reload_files", 'reload Coverband files') %> &nbsp;
22
22
  <% if Coverband.configuration.web_enable_clear %>
data/views/settings.erb CHANGED
@@ -1,7 +1,7 @@
1
1
  <!DOCTYPE html>
2
2
  <html xmlns='http://www.w3.org/1999/xhtml'>
3
3
  <head>
4
- <title>Coverband Settings: <%= Coverband::VERSION %></title>
4
+ <title>Coverband Info: <%= Coverband::VERSION %></title>
5
5
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6
6
  <script src='<%= assets_path('application.js') %>' type='text/javascript'></script>
7
7
  <link href='<%= assets_path('application.css') %>' media='screen, projection, print' rel='stylesheet' type='text/css'>
@@ -12,7 +12,7 @@
12
12
  <div id="wrapper" style="">
13
13
  <div id="header">
14
14
  <a href='<%= base_path %>'>Coverband Admin</a> &nbsp;
15
- <a href='<%= base_path %>settings'>Settings</a> &nbsp;
15
+ <a href='<%= base_path %>settings'>Info</a> &nbsp;
16
16
  </div>
17
17
  <div id="content">
18
18
  <dl>
@@ -20,6 +20,11 @@
20
20
  <dt><%= key %></dt>
21
21
  <dd><%= value %></dd>
22
22
  <% end %>
23
+
24
+ <dt>Size (in bytes)</dt>
25
+ <dd><%= Coverband.configuration.store.size %></dd>
26
+ <dt>Size (in MiB)</dt>
27
+ <dd><%= Coverband.configuration.store.size_in_mib %></dd>
23
28
  </dl>
24
29
  </div>
25
30
  <div id="footer">
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: coverband
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.1.0.beta
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Mayer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-02-11 00:00:00.000000000 Z
12
+ date: 2019-02-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: aws-sdk-s3
@@ -257,6 +257,7 @@ files:
257
257
  - lib/coverband/reporters/web.rb
258
258
  - lib/coverband/utils/file_groups.rb
259
259
  - lib/coverband/utils/file_list.rb
260
+ - lib/coverband/utils/file_path_helper.rb
260
261
  - lib/coverband/utils/gem_list.rb
261
262
  - lib/coverband/utils/html_formatter.rb
262
263
  - lib/coverband/utils/lines_classifier.rb
@@ -366,9 +367,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
366
367
  version: '0'
367
368
  required_rubygems_version: !ruby/object:Gem::Requirement
368
369
  requirements:
369
- - - ">"
370
+ - - ">="
370
371
  - !ruby/object:Gem::Version
371
- version: 1.3.1
372
+ version: '0'
372
373
  requirements: []
373
374
  rubyforge_project:
374
375
  rubygems_version: 2.5.1