coverband 4.2.3 → 4.2.4

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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -6
  3. data/.travis.yml +6 -0
  4. data/README.md +40 -20
  5. data/changes.md +16 -9
  6. data/coverband.gemspec +1 -0
  7. data/lib/coverband/adapters/base.rb +1 -1
  8. data/lib/coverband/adapters/hash_redis_store.rb +49 -42
  9. data/lib/coverband/adapters/redis_store.rb +4 -2
  10. data/lib/coverband/collectors/coverage.rb +1 -1
  11. data/lib/coverband/collectors/view_tracker.rb +14 -5
  12. data/lib/coverband/configuration.rb +18 -5
  13. data/lib/coverband/integrations/background.rb +3 -0
  14. data/lib/coverband/reporters/html_report.rb +10 -0
  15. data/lib/coverband/reporters/web.rb +16 -0
  16. data/lib/coverband/utils/html_formatter.rb +8 -0
  17. data/lib/coverband/utils/railtie.rb +16 -9
  18. data/lib/coverband/utils/s3_report.rb +0 -1
  19. data/lib/coverband/version.rb +1 -1
  20. data/lib/coverband.rb +12 -7
  21. data/lua/install.sh +15 -0
  22. data/lua/lib/persist-coverage.lua +28 -0
  23. data/lua/test/bootstrap.lua +5 -0
  24. data/lua/test/harness.lua +19 -0
  25. data/lua/test/redis-call.lua +55 -0
  26. data/lua/test/test-persist-coverage.lua +132 -0
  27. data/test/coverband/adapters/hash_redis_store_test.rb +4 -3
  28. data/test/coverband/adapters/redis_store_test.rb +10 -5
  29. data/test/coverband/collectors/coverage_test.rb +10 -4
  30. data/test/coverband/collectors/view_tracker_test.rb +38 -18
  31. data/test/coverband/configuration_test.rb +10 -10
  32. data/test/coverband/integrations/background_test.rb +10 -0
  33. data/test/coverband/integrations/resque_worker_test.rb +0 -1
  34. data/test/coverband/reporters/base_test.rb +6 -5
  35. data/test/coverband/reporters/console_test.rb +2 -5
  36. data/test/coverband/reporters/html_test.rb +1 -3
  37. data/test/coverband/utils/html_formatter_test.rb +1 -3
  38. data/test/forked/rails_rake_full_stack_test.rb +10 -0
  39. data/test/integration/full_stack_test.rb +1 -3
  40. data/test/rails4_dummy/config/coverband.rb +3 -13
  41. data/test/rails4_dummy/config/coverband_missing_redis.rb +3 -0
  42. data/test/rails5_dummy/config/coverband.rb +4 -2
  43. data/test/rails5_dummy/config/coverband_missing_redis.rb +15 -0
  44. data/test/test_helper.rb +8 -4
  45. data/views/data.erb +1 -0
  46. data/views/nav.erb +1 -0
  47. data/views/view_tracker.erb +5 -2
  48. metadata +27 -2
@@ -11,22 +11,29 @@ module Coverband
11
11
 
12
12
  class Railtie < Rails::Railtie
13
13
  initializer 'coverband.configure' do |app|
14
- app.middleware.use Coverband::BackgroundMiddleware
14
+ begin
15
+ app.middleware.use Coverband::BackgroundMiddleware
15
16
 
16
- if Coverband.configuration.track_views
17
- CoverbandViewTracker = Coverband::Collectors::ViewTracker.new
18
- Coverband.configuration.view_tracker = CoverbandViewTracker
17
+ if Coverband.configuration.track_views
18
+ CoverbandViewTracker = Coverband::Collectors::ViewTracker.new
19
+ Coverband.configuration.view_tracker = CoverbandViewTracker
19
20
 
20
- ActiveSupport::Notifications.subscribe(/render_partial.action_view|render_template.action_view/) do |name, start, finish, id, payload|
21
- CoverbandViewTracker.track_views(name, start, finish, id, payload) unless name.include?('!')
21
+ ActiveSupport::Notifications.subscribe(/render_partial.action_view|render_template.action_view/) do |name, start, finish, id, payload|
22
+ CoverbandViewTracker.track_views(name, start, finish, id, payload) unless name.include?('!')
23
+ end
22
24
  end
25
+ rescue Redis::CannotConnectError => error
26
+ Coverband.configuration.logger.info "Redis is not available (#{error}), Coverband not configured"
27
+ Coverband.configuration.logger.info 'If this is a setup task like assets:precompile feel free to ignore'
23
28
  end
24
29
  end
25
30
 
26
31
  config.after_initialize do
27
- Coverband.eager_loading_coverage!
28
- Coverband.report_coverage
29
- Coverband.runtime_coverage!
32
+ unless Coverband.tasks_to_ignore?
33
+ Coverband.eager_loading_coverage!
34
+ Coverband.report_coverage
35
+ Coverband.runtime_coverage!
36
+ end
30
37
  end
31
38
 
32
39
  rake_tasks do
@@ -28,7 +28,6 @@ module Coverband
28
28
  rescue StandardError
29
29
  err_msg = 'Coverband requires aws-sdk in order use S3Report.'
30
30
  Coverband.configuration.logger&.error err_msg
31
- return
32
31
  end
33
32
  end
34
33
 
@@ -5,5 +5,5 @@
5
5
  # use format '4.2.1.rc.1' ~> 4.2.1.rc to prerelease versions like v4.2.1.rc.2 and v4.2.1.rc.3
6
6
  ###
7
7
  module Coverband
8
- VERSION = '4.2.3'
8
+ VERSION = '4.2.4'
9
9
  end
data/lib/coverband.rb CHANGED
@@ -99,12 +99,17 @@ module Coverband
99
99
  Coverband::Collectors::Coverage.instance
100
100
  end
101
101
  unless ENV['COVERBAND_DISABLE_AUTO_START']
102
- # Coverband should be setup as early as possible
103
- # to capture usage of things loaded by initializers or other Rails engines
104
- configure
105
- start
106
- require 'coverband/utils/railtie' if defined? ::Rails::Railtie
107
- require 'coverband/integrations/resque' if defined? ::Resque
108
- require 'coverband/integrations/bundler' if defined? ::Bundler
102
+ begin
103
+ # Coverband should be setup as early as possible
104
+ # to capture usage of things loaded by initializers or other Rails engines
105
+ configure
106
+ start
107
+ require 'coverband/utils/railtie' if defined? ::Rails::Railtie
108
+ require 'coverband/integrations/resque' if defined? ::Resque
109
+ require 'coverband/integrations/bundler' if defined? ::Bundler
110
+ rescue Redis::CannotConnectError => error
111
+ Coverband.configuration.logger.info "Redis is not available (#{error}), Coverband not configured"
112
+ Coverband.configuration.logger.info 'If this is a setup task like assets:precompile feel free to ignore'
113
+ end
109
114
  end
110
115
  end
data/lua/install.sh ADDED
@@ -0,0 +1,15 @@
1
+ #!/bin/bash
2
+
3
+ LUA_DIR="$HOME/lua51"
4
+ LUA="$LUA_DIR/bin/lua"
5
+
6
+ if [ ! -f $LUA ]; then
7
+ echo "Installing lua"
8
+ pip install hererocks
9
+ hererocks $LUA_DIR -l5.1 -rlatest
10
+ fi
11
+ source $LUA_DIR/bin/activate
12
+ lua -v
13
+ for i in luacov busted redis-lua inspect lua-cjson; do
14
+ luarocks install $i;
15
+ done
@@ -0,0 +1,28 @@
1
+ local hmset = function (key, dict)
2
+ if next(dict) == nil then return nil end
3
+ local bulk = {}
4
+ for k, v in pairs(dict) do
5
+ table.insert(bulk, k)
6
+ table.insert(bulk, v)
7
+ end
8
+ return redis.call('HMSET', key, unpack(bulk))
9
+ end
10
+ local payload = cjson.decode(redis.call('get', (KEYS[1])))
11
+ local ttl = payload.ttl
12
+ local files_data = payload.files_data
13
+ redis.call('DEL', KEYS[1])
14
+ for _, file_data in ipairs(files_data) do
15
+
16
+ local hash_key = file_data.hash_key
17
+ local first_updated_at = file_data.meta.first_updated_at
18
+ file_data.meta.first_updated_at = nil
19
+
20
+ hmset(hash_key, file_data.meta)
21
+ redis.call('HSETNX', hash_key, 'first_updated_at', first_updated_at)
22
+ for line, coverage in pairs(file_data.coverage) do
23
+ redis.call("HINCRBY", hash_key, line, coverage)
24
+ end
25
+ if ttl and ttl ~= cjson.null then
26
+ redis.call("EXPIRE", hash_key, ttl)
27
+ end
28
+ end
@@ -0,0 +1,5 @@
1
+ inspect = require "inspect"
2
+ cjson = require 'cjson'
3
+ require './lua/test/redis-call'
4
+
5
+
@@ -0,0 +1,19 @@
1
+ require './lua/test/bootstrap'
2
+
3
+
4
+ KEYS = {}
5
+ ARGV = {}
6
+
7
+
8
+ function call_redis_script(script, keys, argv)
9
+ -- This may not be strictly necessary
10
+ for k,v in pairs(ARGV) do ARGV[k] = nil end
11
+ for k,v in pairs(KEYS) do KEYS[k] = nil end
12
+
13
+ for k,v in pairs(keys) do table.insert(KEYS, v) end
14
+ for k,v in pairs(argv) do table.insert(ARGV, v) end
15
+
16
+ return dofile('./lua/lib/' .. script)
17
+ end
18
+
19
+ return call_redis_script;
@@ -0,0 +1,55 @@
1
+ redis = require 'redis'
2
+
3
+ -- If you have some different host/port change it here
4
+ local host = "127.0.0.1"
5
+ local port = 6379
6
+
7
+
8
+ client = redis.connect(host, port)
9
+
10
+ -- Workaround for absence of redis.call
11
+ redis.call = function(cmd, ...)
12
+ local arg={...}
13
+ local args_string = ''
14
+ for i,v in ipairs(arg) do
15
+ args_string = args_string .. ' ' .. v
16
+ end
17
+ cmd = string.lower(cmd)
18
+ print(cmd .. args_string)
19
+ --local result = assert(load('return client:'.. cmd ..'(...)'))(...)
20
+ local result = assert(loadstring('return client:'.. cmd ..'(...)'))(...)
21
+
22
+ -- The redis-lua library returns some values differently to how `redis.call` works inside redis.
23
+ -- this makes the responses look like those from the builtin redis
24
+ local response_lookup = {
25
+ type = function() return { ["ok"]= result } end,
26
+ sadd = function() return tonumber(result) end,
27
+ zrange = function()
28
+ if type(result) == "table" and type(result[1]) == "table" then
29
+ -- Deal with WITHSCORES...
30
+ local new_result = {}
31
+ for k,v in pairs(result) do
32
+ table.insert(new_result, v[1])
33
+ table.insert(new_result, v[2])
34
+ end
35
+ return new_result;
36
+ end
37
+
38
+ return result;
39
+ end,
40
+ hgetall = function()
41
+ local new_result = {}
42
+ for key, value in pairs(result) do
43
+ table.insert(new_result, key)
44
+ table.insert(new_result, value)
45
+ end
46
+ return new_result
47
+ end
48
+ }
49
+
50
+ if response_lookup[cmd] then
51
+ return response_lookup[cmd]()
52
+ end
53
+
54
+ return result;
55
+ end
@@ -0,0 +1,132 @@
1
+ local call_redis_script = require "./lua/test/harness";
2
+
3
+ describe("persist-coverage", function()
4
+ local function hgetall(hash_key)
5
+ local flat_map = redis.call('HGETALL', hash_key)
6
+ local result = {}
7
+ for i = 1, #flat_map, 2 do
8
+ result[flat_map[i]] = flat_map[i + 1]
9
+ end
10
+ return result
11
+ end
12
+
13
+ local function clean_redis()
14
+ redis.call('flushdb')
15
+ end
16
+
17
+ before_each(function()
18
+ clean_redis()
19
+ end)
20
+
21
+ after_each(function()
22
+ clean_redis()
23
+ end)
24
+
25
+ it("Adds data on multiple files", function()
26
+ local first_updated_at = "1569453853"
27
+ local last_updated_at = first_updated_at
28
+
29
+ local key = 'hash_key'
30
+ local json = cjson.encode({
31
+ ttl = nil,
32
+ files_data = {
33
+ {
34
+ hash_key = "coverband_hash_3_3.coverband_test.runtime../dog.rb.abcd",
35
+ meta = {
36
+ first_updated_at = first_updated_at,
37
+ last_updated_at = last_updated_at,
38
+ file = "./dog.rb",
39
+ file_hash = 'abcd',
40
+ file_length = 3
41
+ },
42
+ coverage = {
43
+ ['0'] = 0,
44
+ ['1'] = 1,
45
+ ['2'] = 2
46
+ }
47
+ },
48
+ {
49
+ hash_key = "coverband_hash_3_3.coverband_test.runtime../fish.rb.1234",
50
+ meta = {
51
+ first_updated_at = first_updated_at,
52
+ last_updated_at = last_updated_at,
53
+ file = "./fish.rb",
54
+ file_hash = '1234',
55
+ file_length = 3
56
+ },
57
+ coverage = {
58
+ ['0'] = 1,
59
+ ['1'] = 0,
60
+ ['2'] = 1
61
+ }
62
+ }
63
+ }
64
+ });
65
+ redis.call( 'set', key, json)
66
+
67
+ call_redis_script('persist-coverage.lua', { key }, {});
68
+ local results = hgetall("coverband_hash_3_3.coverband_test.runtime../dog.rb.abcd")
69
+ assert.are.same({
70
+ ["0"] = "0",
71
+ ["1"] = "1",
72
+ ["2"] = "2",
73
+ file = "./dog.rb",
74
+ file_hash = "abcd",
75
+ file_length = "3",
76
+ first_updated_at = first_updated_at ,
77
+ last_updated_at = last_updated_at
78
+ }, results)
79
+
80
+ results = hgetall("coverband_hash_3_3.coverband_test.runtime../fish.rb.1234")
81
+ assert.are.same({
82
+ ["0"] = "1",
83
+ ["1"] = "0",
84
+ ["2"] = "1",
85
+ file = "./fish.rb",
86
+ file_hash = "1234",
87
+ file_length = "3",
88
+ first_updated_at = first_updated_at ,
89
+ last_updated_at = last_updated_at
90
+ }, results)
91
+
92
+ assert.is_false(false, redis.call('exists', key))
93
+
94
+ last_updated_at = "1569453953"
95
+ json = cjson.encode({
96
+ ttl = nil,
97
+ files_data = {
98
+ {
99
+ hash_key="coverband_hash_3_3.coverband_test.runtime../dog.rb.abcd",
100
+ meta = {
101
+ first_updated_at=first_updated_at,
102
+ last_updated_at=last_updated_at,
103
+ file="./dog.rb",
104
+ file_hash='abcd',
105
+ file_length=3
106
+ },
107
+ coverage = {
108
+ ['0']= 1,
109
+ ['1']= 1,
110
+ ['2']= 1
111
+ }
112
+ }
113
+ }
114
+ })
115
+ redis.call( 'set', key, json )
116
+
117
+ call_redis_script('persist-coverage.lua', { key }, {} );
118
+ results = hgetall("coverband_hash_3_3.coverband_test.runtime../dog.rb.abcd")
119
+ assert.are.same({
120
+ ["0"] = "1",
121
+ ["1"] = "2",
122
+ ["2"] = "3",
123
+ file = "./dog.rb",
124
+ file_hash = "abcd",
125
+ file_length = "3",
126
+ first_updated_at = first_updated_at,
127
+ last_updated_at = last_updated_at
128
+ }, results)
129
+
130
+ assert.is_false(false, redis.call('exists', key))
131
+ end)
132
+ end)
@@ -13,13 +13,12 @@ class HashRedisStoreTest < Minitest::Test
13
13
 
14
14
  def setup
15
15
  super
16
- @redis = Redis.new
16
+ @redis = Coverband::Test.redis
17
17
  # FIXME: remove dependency on configuration and instead pass this in as an argument
18
18
  Coverband.configure do |config|
19
19
  config.root_paths = ['app_path/']
20
20
  end
21
21
  @store = Coverband::Adapters::HashRedisStore.new(@redis, redis_namespace: 'coverband_test', relative_file_converter: MockRelativeFileConverter)
22
- @store.clear!
23
22
  Coverband.configuration.store = @store
24
23
  end
25
24
 
@@ -57,6 +56,7 @@ class HashRedisStoreTest < Minitest::Test
57
56
  {
58
57
  'first_updated_at' => yesterday.to_i,
59
58
  'last_updated_at' => yesterday.to_i,
59
+ 'file_hash' => 'abcd',
60
60
  'data' => [0, 1, 2]
61
61
  },
62
62
  @store.coverage['./dog.rb']
@@ -69,6 +69,7 @@ class HashRedisStoreTest < Minitest::Test
69
69
  {
70
70
  'first_updated_at' => yesterday.to_i,
71
71
  'last_updated_at' => today.to_i,
72
+ 'file_hash' => 'abcd',
72
73
  'data' => [1, 2, 2]
73
74
  },
74
75
  @store.coverage['./dog.rb']
@@ -107,6 +108,7 @@ class HashRedisStoreTest < Minitest::Test
107
108
  {
108
109
  'first_updated_at' => current_time.to_i,
109
110
  'last_updated_at' => current_time.to_i,
111
+ 'file_hash' => 'abcd',
110
112
  'data' => [0, nil, 1, 2]
111
113
  }, @store.coverage['./dog.rb']
112
114
  )
@@ -121,7 +123,6 @@ class HashRedisStoreTest < Minitest::Test
121
123
  assert_equal [0, nil, 1, 2], @store.coverage['./dog.rb']['data']
122
124
  @store.instance_eval { @file_hash_cache = {} }
123
125
  mock_file_hash(hash: '123')
124
- $debug = true
125
126
  assert_nil @store.coverage['./dog.rb']
126
127
  end
127
128
 
@@ -8,11 +8,8 @@ unless ENV['COVERBAND_HASH_REDIS_STORE']
8
8
 
9
9
  def setup
10
10
  super
11
- Coverband.configuration.redis_namespace = 'coverband_test'
12
- @redis = Redis.new
13
- @store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
14
- Coverband.configuration.store = @store
15
- @store.clear!
11
+ @store = Coverband.configuration.store
12
+ @redis = @store.instance_variable_get(:@redis)
16
13
  end
17
14
 
18
15
  def test_coverage
@@ -39,6 +36,14 @@ unless ENV['COVERBAND_HASH_REDIS_STORE']
39
36
  assert current_time <= @store.coverage['app_path/dog.rb']['last_updated_at']
40
37
  end
41
38
 
39
+ def test_file_hash_change
40
+ mock_file_hash(hash: 'abc')
41
+ @store.save_report('app_path/dog.rb' => [0, nil, 1, 2])
42
+ assert_equal [0, nil, 1, 2], @store.coverage['app_path/dog.rb']['data']
43
+ mock_file_hash(hash: '123')
44
+ assert_nil @store.coverage['app_path/dog.rb']
45
+ end
46
+
42
47
  def test_store_coverage_by_type
43
48
  mock_file_hash
44
49
  expected = basic_coverage
@@ -7,10 +7,7 @@ class CollectorsCoverageTest < Minitest::Test
7
7
 
8
8
  def setup
9
9
  super
10
- Coverband.configure do |config|
11
- config.store = Coverband::Adapters::RedisStore.new(Redis.new, redis_namespace: 'coverband_test')
12
- end
13
- @coverband = Coverband::Collectors::Coverage.instance.reset_instance
10
+ @coverband = Coverband::Collectors::Coverage.instance
14
11
  # preload first coverage hit
15
12
  @coverband.report_coverage
16
13
  end
@@ -85,6 +82,15 @@ class CollectorsCoverageTest < Minitest::Test
85
82
  assert_equal false, @coverband.send(:track_file?, heroku_build_file)
86
83
  end
87
84
 
85
+ # verifies a fix where we were storing, merging, and tracking ignored files
86
+ # then just filtering them out of the final report
87
+ test 'ignores uses regex same as reporter does' do
88
+ regex_file = Coverband.configuration.current_root + '/config/initializers/fake.rb'
89
+ assert_equal true, @coverband.send(:track_file?, regex_file)
90
+ @coverband.instance_variable_set(:@ignore_patterns, ['config/initializers/*'])
91
+ assert_equal false, @coverband.send(:track_file?, regex_file)
92
+ end
93
+
88
94
  test 'one shot line coverage disabled for ruby >= 2.6' do
89
95
  return unless Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('2.5.0')
90
96
 
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require File.expand_path('../../test_helper', File.dirname(__FILE__))
2
4
 
3
5
  class ReporterTest < Minitest::Test
4
-
5
6
  def tracker_key
6
7
  'render_tracker_2'
7
8
  end
@@ -11,75 +12,95 @@ class ReporterTest < Minitest::Test
11
12
  fake_store.raw_store.del(tracker_key)
12
13
  end
13
14
 
14
- test "init correctly" do
15
+ test 'init correctly' do
15
16
  Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
16
- tracker = Coverband::Collectors::ViewTracker.new(:store => fake_store, :roots => 'dir')
17
+ tracker = Coverband::Collectors::ViewTracker.new(store: fake_store, roots: 'dir')
17
18
  assert_equal 'dir', tracker.roots.first
18
- assert tracker.store != nil
19
+ assert !tracker.store.nil?
19
20
  assert_equal [], tracker.target
20
21
  assert_equal [], tracker.logged_views
21
22
  end
22
23
 
23
- test "track partials" do
24
+ test 'track partials' do
24
25
  Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
25
26
  store = fake_store
26
27
  file_path = "#{File.expand_path(Coverband.configuration.root)}/file"
27
28
  store.raw_store.expects(:hset).with(tracker_key, file_path, anything)
28
29
  tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir')
29
- tracker.track_views('name', 'start', 'finish', 'id', {:identifier => file_path})
30
+ tracker.track_views('name', 'start', 'finish', 'id', identifier: file_path)
30
31
  tracker.report_views_tracked
31
32
  assert_equal [file_path], tracker.logged_views
32
33
  end
33
34
 
34
- test "track layouts" do
35
+ test 'track partials that include the word vendor in the path' do
36
+ Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
37
+ store = fake_store
38
+ file_path = "#{File.expand_path(Coverband.configuration.root)}/vendor_relations/file"
39
+ tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir')
40
+ tracker.track_views('name', 'start', 'finish', 'id', identifier: file_path)
41
+ tracker.report_views_tracked
42
+ assert_equal [file_path], tracker.used_views.keys
43
+ end
44
+
45
+ test 'ignore partials that include the folder vendor in the path' do
46
+ Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
47
+ store = fake_store
48
+ file_path = "#{File.expand_path(Coverband.configuration.root)}/vendor/file"
49
+ tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir')
50
+ tracker.track_views('name', 'start', 'finish', 'id', identifier: file_path)
51
+ tracker.report_views_tracked
52
+ assert_equal Hash.new, tracker.used_views
53
+ end
54
+
55
+ test 'track layouts' do
35
56
  Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
36
57
  store = fake_store
37
58
  file_path = "#{File.expand_path(Coverband.configuration.root)}/layout"
38
59
  store.raw_store.expects(:hset).with(tracker_key, file_path, anything)
39
60
  tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir')
40
- tracker.track_views('name', 'start', 'finish', 'id', {:layout => file_path})
61
+ tracker.track_views('name', 'start', 'finish', 'id', layout: file_path)
41
62
  tracker.report_views_tracked
42
63
  assert_equal [file_path], tracker.logged_views
43
64
  end
44
65
 
45
- test "report used partials" do
66
+ test 'report used partials' do
46
67
  Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
47
68
  store = fake_store
48
69
  file_path = "#{File.expand_path(Coverband.configuration.root)}/file"
49
70
  tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir')
50
- tracker.track_views('name', 'start', 'finish', 'id', {:identifier => file_path})
71
+ tracker.track_views('name', 'start', 'finish', 'id', identifier: file_path)
51
72
  tracker.report_views_tracked
52
73
  assert_equal [file_path], tracker.used_views.keys
53
74
  end
54
75
 
55
- test "report unused partials" do
76
+ test 'report unused partials' do
56
77
  Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
57
78
  store = fake_store
58
79
  file_path = "#{File.expand_path(Coverband.configuration.root)}/file"
59
80
  target = [file_path, 'not_used']
60
81
  tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir', target: target)
61
- tracker.track_views('name', 'start', 'finish', 'id', {:identifier => file_path})
82
+ tracker.track_views('name', 'start', 'finish', 'id', identifier: file_path)
62
83
  tracker.report_views_tracked
63
84
  assert_equal ['not_used'], tracker.unused_views
64
85
  end
65
86
 
66
- test "reset store" do
87
+ test 'reset store' do
67
88
  Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
68
89
  store = fake_store
69
90
  store.raw_store.expects(:del).with(tracker_key)
70
91
  store.raw_store.expects(:del).with('render_tracker_time')
71
92
  tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir')
72
- tracker.track_views('name', 'start', 'finish', 'id', {:identifier => 'file'})
93
+ tracker.track_views('name', 'start', 'finish', 'id', identifier: 'file')
73
94
  tracker.reset_recordings
74
95
  end
75
96
 
76
- test "clear_file" do
97
+ test 'clear_file' do
77
98
  Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
78
99
  store = fake_store
79
100
  file_path = "#{File.expand_path(Coverband.configuration.root)}/file"
80
101
  store.raw_store.expects(:hdel).with(tracker_key, file_path)
81
102
  tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir')
82
- tracker.track_views('name', 'start', 'finish', 'id', {:identifier => file_path})
103
+ tracker.track_views('name', 'start', 'finish', 'id', identifier: file_path)
83
104
  tracker.clear_file!('file')
84
105
  assert_equal [], tracker.logged_views
85
106
  end
@@ -87,7 +108,6 @@ class ReporterTest < Minitest::Test
87
108
  protected
88
109
 
89
110
  def fake_store
90
- @fake_store ||= Coverband::Adapters::RedisStore.new(Redis.new, redis_namespace: 'coverband_test')
111
+ @fake_store ||= Coverband::Adapters::RedisStore.new(Coverband::Test.redis, redis_namespace: 'coverband_test')
91
112
  end
92
-
93
113
  end
@@ -12,13 +12,13 @@ class BaseTest < Minitest::Test
12
12
  config.root_paths = ['/app_path/']
13
13
  config.ignore = ['config/envionments']
14
14
  config.reporter = 'std_out'
15
- config.store = Coverband::Adapters::RedisStore.new(Redis.new, redis_namespace: 'coverband_test')
15
+ config.store = Coverband::Adapters::RedisStore.new(Coverband::Test.redis, redis_namespace: 'coverband_test')
16
16
  end
17
17
  end
18
18
 
19
19
  test 'ignore works with equal' do
20
20
  coverband = Coverband::Collectors::Coverage.instance.reset_instance
21
- expected = ["vendor", ".erb$", ".slim$", "/tmp", "internal:prelude", "schema.rb", "config/envionments"]
21
+ expected = ['vendor/', '.erb$', '.slim$', '/tmp', 'internal:prelude', 'schema.rb', 'config/envionments']
22
22
  assert_equal expected, Coverband.configuration.ignore
23
23
  end
24
24
 
@@ -27,14 +27,14 @@ class BaseTest < Minitest::Test
27
27
  config.ignore += ['config/initializers']
28
28
  end
29
29
  coverband = Coverband::Collectors::Coverage.instance.reset_instance
30
- expected = ["vendor",
31
- ".erb$",
32
- ".slim$",
33
- "/tmp",
34
- "internal:prelude",
35
- "schema.rb",
36
- "config/envionments",
37
- "config/initializers"]
30
+ expected = ['vendor/',
31
+ '.erb$',
32
+ '.slim$',
33
+ '/tmp',
34
+ 'internal:prelude',
35
+ 'schema.rb',
36
+ 'config/envionments',
37
+ 'config/initializers']
38
38
  assert_equal expected, Coverband.configuration.ignore
39
39
  end
40
40
 
@@ -19,6 +19,16 @@ class BackgroundTest < Minitest::Test
19
19
  2.times { Coverband::Background.start }
20
20
  end
21
21
 
22
+ def test_start_with_wiggle
23
+ Thread.expects(:new).yields.returns(ThreadDouble.new(true))
24
+ Coverband::Background.expects(:loop).yields
25
+ Coverband::Background.expects(:sleep).with(35)
26
+ Coverband::Background.expects(:rand).with(10).returns(5)
27
+ Coverband.configuration.reporting_wiggle = 10
28
+ Coverband::Collectors::Coverage.instance.expects(:report_coverage).once
29
+ 2.times { Coverband::Background.start }
30
+ end
31
+
22
32
  def test_start_dead_thread
23
33
  Thread.expects(:new).yields.returns(ThreadDouble.new(false)).twice
24
34
  Coverband::Background.expects(:loop).yields.twice
@@ -16,7 +16,6 @@ class ResqueWorkerTest < Minitest::Test
16
16
  Coverband.configure do |config|
17
17
  config.background_reporting_enabled = false
18
18
  end
19
- Coverband.configuration.store.instance_variable_set(:@redis_namespace, 'coverband_test')
20
19
  Coverband.start
21
20
  redis = Coverband.configuration.store.instance_eval { @redis }
22
21
  Resque.redis = redis