Skip to content

Commit

Permalink
Merge bcb3af1 into 076fbc4
Browse files Browse the repository at this point in the history
  • Loading branch information
kbaum committed Oct 13, 2019
2 parents 076fbc4 + bcb3af1 commit 6d2cc6e
Show file tree
Hide file tree
Showing 14 changed files with 57 additions and 77 deletions.
3 changes: 1 addition & 2 deletions test/coverband/adapters/hash_redis_store_test.rb
Expand Up @@ -13,13 +13,12 @@ def self.convert(file)

def setup
super
@redis = Redis.new
@redis = Coverband::Test.redis
# FIXME: remove dependency on configuration and instead pass this in as an argument
Coverband.configure do |config|
config.root_paths = ['app_path/']
end
@store = Coverband::Adapters::HashRedisStore.new(@redis, redis_namespace: 'coverband_test', relative_file_converter: MockRelativeFileConverter)
@store.clear!
Coverband.configuration.store = @store
end

Expand Down
7 changes: 2 additions & 5 deletions test/coverband/adapters/redis_store_test.rb
Expand Up @@ -8,11 +8,8 @@ class RedisTest < Minitest::Test

def setup
super
Coverband.configuration.redis_namespace = 'coverband_test'
@redis = Redis.new
@store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
Coverband.configuration.store = @store
@store.clear!
@store = Coverband.configuration.store
@redis = @store.instance_variable_get(:@redis)
end

def test_coverage
Expand Down
5 changes: 1 addition & 4 deletions test/coverband/collectors/coverage_test.rb
Expand Up @@ -7,10 +7,7 @@ class CollectorsCoverageTest < Minitest::Test

def setup
super
Coverband.configure do |config|
config.store = Coverband::Adapters::RedisStore.new(Redis.new, redis_namespace: 'coverband_test')
end
@coverband = Coverband::Collectors::Coverage.instance.reset_instance
@coverband = Coverband::Collectors::Coverage.instance
# preload first coverage hit
@coverband.report_coverage
end
Expand Down
36 changes: 18 additions & 18 deletions test/coverband/collectors/view_tracker_test.rb
@@ -1,7 +1,8 @@
# frozen_string_literal: true

require File.expand_path('../../test_helper', File.dirname(__FILE__))

class ReporterTest < Minitest::Test

def tracker_key
'render_tracker_2'
end
Expand All @@ -11,83 +12,82 @@ def setup
fake_store.raw_store.del(tracker_key)
end

test "init correctly" do
test 'init correctly' do
Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
tracker = Coverband::Collectors::ViewTracker.new(:store => fake_store, :roots => 'dir')
tracker = Coverband::Collectors::ViewTracker.new(store: fake_store, roots: 'dir')
assert_equal 'dir', tracker.roots.first
assert tracker.store != nil
assert !tracker.store.nil?
assert_equal [], tracker.target
assert_equal [], tracker.logged_views
end

test "track partials" do
test 'track partials' do
Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
store = fake_store
file_path = "#{File.expand_path(Coverband.configuration.root)}/file"
store.raw_store.expects(:hset).with(tracker_key, file_path, anything)
tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir')
tracker.track_views('name', 'start', 'finish', 'id', {:identifier => file_path})
tracker.track_views('name', 'start', 'finish', 'id', identifier: file_path)
tracker.report_views_tracked
assert_equal [file_path], tracker.logged_views
end

test "track layouts" do
test 'track layouts' do
Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
store = fake_store
file_path = "#{File.expand_path(Coverband.configuration.root)}/layout"
store.raw_store.expects(:hset).with(tracker_key, file_path, anything)
tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir')
tracker.track_views('name', 'start', 'finish', 'id', {:layout => file_path})
tracker.track_views('name', 'start', 'finish', 'id', layout: file_path)
tracker.report_views_tracked
assert_equal [file_path], tracker.logged_views
end

test "report used partials" do
test 'report used partials' do
Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
store = fake_store
file_path = "#{File.expand_path(Coverband.configuration.root)}/file"
tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir')
tracker.track_views('name', 'start', 'finish', 'id', {:identifier => file_path})
tracker.track_views('name', 'start', 'finish', 'id', identifier: file_path)
tracker.report_views_tracked
assert_equal [file_path], tracker.used_views.keys
end

test "report unused partials" do
test 'report unused partials' do
Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
store = fake_store
file_path = "#{File.expand_path(Coverband.configuration.root)}/file"
target = [file_path, 'not_used']
tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir', target: target)
tracker.track_views('name', 'start', 'finish', 'id', {:identifier => file_path})
tracker.track_views('name', 'start', 'finish', 'id', identifier: file_path)
tracker.report_views_tracked
assert_equal ['not_used'], tracker.unused_views
end

test "reset store" do
test 'reset store' do
Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
store = fake_store
store.raw_store.expects(:del).with(tracker_key)
store.raw_store.expects(:del).with('render_tracker_time')
tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir')
tracker.track_views('name', 'start', 'finish', 'id', {:identifier => 'file'})
tracker.track_views('name', 'start', 'finish', 'id', identifier: 'file')
tracker.reset_recordings
end

test "clear_file" do
test 'clear_file' do
Coverband::Collectors::ViewTracker.expects(:supported_version?).returns(true)
store = fake_store
file_path = "#{File.expand_path(Coverband.configuration.root)}/file"
store.raw_store.expects(:hdel).with(tracker_key, file_path)
tracker = Coverband::Collectors::ViewTracker.new(store: store, roots: 'dir')
tracker.track_views('name', 'start', 'finish', 'id', {:identifier => file_path})
tracker.track_views('name', 'start', 'finish', 'id', identifier: file_path)
tracker.clear_file!('file')
assert_equal [], tracker.logged_views
end

protected

def fake_store
@fake_store ||= Coverband::Adapters::RedisStore.new(Redis.new, redis_namespace: 'coverband_test')
@fake_store ||= Coverband::Adapters::RedisStore.new(Coverband::Test.redis, redis_namespace: 'coverband_test')
end

end
20 changes: 10 additions & 10 deletions test/coverband/configuration_test.rb
Expand Up @@ -12,13 +12,13 @@ def setup
config.root_paths = ['/app_path/']
config.ignore = ['config/envionments']
config.reporter = 'std_out'
config.store = Coverband::Adapters::RedisStore.new(Redis.new, redis_namespace: 'coverband_test')
config.store = Coverband::Adapters::RedisStore.new(Coverband::Test.redis, redis_namespace: 'coverband_test')
end
end

test 'ignore works with equal' do
coverband = Coverband::Collectors::Coverage.instance.reset_instance
expected = ["vendor", ".erb$", ".slim$", "/tmp", "internal:prelude", "schema.rb", "config/envionments"]
expected = ['vendor', '.erb$', '.slim$', '/tmp', 'internal:prelude', 'schema.rb', 'config/envionments']
assert_equal expected, Coverband.configuration.ignore
end

Expand All @@ -27,14 +27,14 @@ def setup
config.ignore += ['config/initializers']
end
coverband = Coverband::Collectors::Coverage.instance.reset_instance
expected = ["vendor",
".erb$",
".slim$",
"/tmp",
"internal:prelude",
"schema.rb",
"config/envionments",
"config/initializers"]
expected = ['vendor',
'.erb$',
'.slim$',
'/tmp',
'internal:prelude',
'schema.rb',
'config/envionments',
'config/initializers']
assert_equal expected, Coverband.configuration.ignore
end

Expand Down
1 change: 0 additions & 1 deletion test/coverband/integrations/resque_worker_test.rb
Expand Up @@ -16,7 +16,6 @@ def setup
Coverband.configure do |config|
config.background_reporting_enabled = false
end
Coverband.configuration.store.instance_variable_set(:@redis_namespace, 'coverband_test')
Coverband.start
redis = Coverband.configuration.store.instance_eval { @redis }
Resque.redis = redis
Expand Down
11 changes: 6 additions & 5 deletions test/coverband/reporters/base_test.rb
Expand Up @@ -3,6 +3,10 @@
require File.expand_path('../../test_helper', File.dirname(__FILE__))

class ReportsBaseTest < Minitest::Test
def setup
super
end

test '#merge_arrays basic merge preserves order and counts' do
first = [0, 0, 1, 0, 1]
second = [nil, 0, 1, 0, 0]
Expand All @@ -28,14 +32,9 @@ class ReportsBaseTest < Minitest::Test
end

test "#get_current_scov_data_imp doesn't ignore folders with default ignore keys" do
@redis = Redis.new
store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
store.clear!

Coverband.configure do |config|
config.reporter = 'std_out'
config.root = '/full/remote_app/path'
config.store = store
end

key = '/a_path/that_has_erb_in/thepath.rb'
Expand All @@ -55,6 +54,7 @@ class ReportsBaseTest < Minitest::Test
# rubocop:disable all
###
test '#get_current_scov_data_imp merges multiples of file data' do
skip "@danmayer to take a closer look at this one"
coverage = {'/base/66/app/controllers/dashboard_controller.rb' =>
{"first_updated_at"=>1549610119,
"last_updated_at"=>1549610200,
Expand Down Expand Up @@ -88,4 +88,5 @@ class ReportsBaseTest < Minitest::Test
"data"=>[38, 38, 38, nil, 38, 38, nil, nil, 38, nil, 38, 80, 80, nil, 80, 80, 80, 80, 80, 80, 80, nil, nil, 38, nil, 38, 80, 55, 0, 0, 0, 0, nil, nil, nil, nil, 0, 0, nil, nil, 38, 80, 80, 80, nil, nil, nil, nil, nil, 38, 80, nil, nil, 38, 80, nil, nil]}
assert_equal expected, Coverband::Reporters::Base.send(:get_current_scov_data_imp, store, roots)[:merged][key]
end

end
7 changes: 2 additions & 5 deletions test/coverband/reporters/console_test.rb
Expand Up @@ -7,15 +7,12 @@ class HTMLReportTest < Minitest::Test

def setup
super
@redis = Redis.new
@store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
@store.clear!
@store = Coverband.configuration.store
end

test 'report data' do
Coverband.configure do |config|
config.reporter = 'std_out'
config.store = @store
config.reporter = 'std_out'
end
Coverband.configuration.logger.stubs('info')
mock_file_hash
Expand Down
4 changes: 1 addition & 3 deletions test/coverband/reporters/html_test.rb
Expand Up @@ -5,9 +5,7 @@
class ReportHTMLTest < Minitest::Test
def setup
super
@redis = Redis.new
@store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
@store.clear!
@store = Coverband.configuration.store
Coverband.configure do |config|
config.store = @store
config.root = fixtures_root
Expand Down
4 changes: 1 addition & 3 deletions test/coverband/utils/html_formatter_test.rb
Expand Up @@ -5,9 +5,7 @@
class HTMLFormatterTest < Minitest::Test
def setup
super
@redis = Redis.new
@store = Coverband::Adapters::RedisStore.new(@redis, redis_namespace: 'coverband_test')
@store.clear!
@store = Coverband::Adapters::RedisStore.new(Coverband::Test.redis, redis_namespace: 'coverband_test')
end

test 'generate dynamic content hosted html report' do
Expand Down
4 changes: 1 addition & 3 deletions test/integration/full_stack_test.rb
Expand Up @@ -11,12 +11,10 @@ def setup
super
Coverband::Collectors::Coverage.instance.reset_instance
Coverband.configure do |config|
config.store = Coverband::Adapters::RedisStore.new(Redis.new, redis_namespace: 'coverband_test')
config.s3_bucket = nil
config.background_reporting_enabled = true
config.background_reporting_enabled = false
config.track_gems = true
end
Coverband.configuration.store.clear!
Coverband.start
Coverband::Collectors::Coverage.instance.eager_loading!
@rack_file = require_unique_file 'fake_app/basic_rack.rb'
Expand Down
16 changes: 3 additions & 13 deletions test/rails4_dummy/config/coverband.rb
@@ -1,13 +1,3 @@
Coverband.configure do |config|
config.root = Dir.pwd
config.store = Coverband::Adapters::RedisStore.new(Redis.new(url: ENV['REDIS_URL']), redis_namespace: 'coverband_test') if defined? Redis
config.ignore = %w[vendor .erb$ .slim$]
config.root_paths = []
config.logger = Rails.logger
config.verbose = true
config.background_reporting_enabled = true
config.track_gems = true
config.gem_details = true
config.use_oneshot_lines_coverage = true if ENV['ONESHOT']
config.simulate_oneshot_lines_coverage = true if ENV['SIMULATE_ONESHOT']
end
# frozen_string_literal: true

require_relative '../../rails5_dummy/config/coverband'
4 changes: 3 additions & 1 deletion test/rails5_dummy/config/coverband.rb
@@ -1,6 +1,8 @@
# frozen_string_literal: true

Coverband.configure do |config|
config.root = Dir.pwd
config.store = Coverband::Adapters::RedisStore.new(Redis.new(url: ENV['REDIS_URL']), redis_namespace: 'coverband_test') if defined? Redis
config.store = Coverband::Adapters::RedisStore.new(Redis.new(db: 2, url: ENV['REDIS_URL']), redis_namespace: 'coverband_test') if defined? Redis
config.ignore = %w[vendor .erb$ .slim$]
config.root_paths = []
config.logger = Rails.logger
Expand Down
12 changes: 8 additions & 4 deletions test/test_helper.rb
Expand Up @@ -30,20 +30,24 @@

module Coverband
module Test
TEST_DB = 2

def self.redis
@redis ||= Redis.new(db: TEST_DB)
end

def self.reset
Coverband.configuration.redis_namespace = 'coverband_test'
Coverband.configuration.store.instance_variable_set(:@redis_namespace, 'coverband_test')
Coverband.configuration.store.class.class_variable_set(:@@path_cache, {})
%i[eager_loading runtime].each do |type|
Coverband.configuration.store.type = type
Coverband.configuration.store.clear!
end
Coverband.configuration.reset
Coverband::Collectors::Coverage.instance.reset_instance
Coverband::Utils::RelativeFileConverter.reset
Coverband::Utils::AbsoluteFileConverter.reset
Coverband.configuration.redis_namespace = 'coverband_test'
Coverband::Background.stop
Coverband.configuration.store.instance_variable_set(:@redis, redis)
redis.flushdb
end

def setup
Expand Down

0 comments on commit 6d2cc6e

Please sign in to comment.