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.
- checksums.yaml +5 -5
- data/.gitignore +1 -4
- data/.travis.yml +2 -4
- data/README.md +8 -33
- data/Rakefile +1 -1
- data/changes.md +10 -26
- data/coverband.gemspec +0 -4
- data/lib/coverband.rb +0 -5
- data/lib/coverband/adapters/base.rb +4 -20
- data/lib/coverband/adapters/file_store.rb +0 -8
- data/lib/coverband/adapters/redis_store.rb +2 -33
- data/lib/coverband/at_exit.rb +1 -1
- data/lib/coverband/collectors/coverage.rb +1 -7
- data/lib/coverband/configuration.rb +2 -30
- data/lib/coverband/integrations/background.rb +1 -6
- data/lib/coverband/integrations/resque.rb +2 -7
- data/lib/coverband/reporters/base.rb +38 -8
- data/lib/coverband/reporters/html_report.rb +1 -1
- data/lib/coverband/reporters/web.rb +1 -13
- data/lib/coverband/utils/file_groups.rb +12 -20
- data/lib/coverband/utils/html_formatter.rb +1 -9
- data/lib/coverband/utils/railtie.rb +1 -1
- data/lib/coverband/utils/tasks.rb +0 -9
- data/lib/coverband/version.rb +1 -1
- data/test/benchmarks/benchmark.rake +1 -36
- data/test/test_helper.rb +12 -5
- data/test/{coverband/adapters/base_test.rb → unit/adapters_base_test.rb} +1 -1
- data/test/{coverband/adapters/file_store_test.rb → unit/adapters_file_store_test.rb} +1 -1
- data/test/{coverband/adapters/redis_store_test.rb → unit/adapters_redis_store_test.rb} +1 -1
- data/test/{coverband → unit}/at_exit_test.rb +0 -0
- data/test/{coverband/integrations → unit}/background_test.rb +1 -1
- data/test/unit/collectors_coverage_test.rb +48 -0
- data/test/{coverband → unit}/configuration_test.rb +3 -13
- data/test/{coverband → unit}/coverband_test.rb +0 -0
- data/test/{dog.rb → unit/dog.rb} +0 -0
- data/test/{integration → unit}/full_stack_test.rb +2 -4
- data/test/{coverband/integrations → unit}/middleware_test.rb +1 -1
- data/test/{coverband/integrations/rack_server_check_test.rb → unit/rack_server_checkout_test.rb} +1 -1
- data/test/{integration → unit}/rails_full_stack_test.rb +3 -4
- data/test/{integration → unit}/rails_gems_full_stack_test.rb +1 -2
- data/test/unit/reports_base_test.rb +117 -0
- data/test/{coverband/reporters/console_test.rb → unit/reports_console_test.rb} +5 -6
- data/test/{coverband/reporters/html_test.rb → unit/reports_html_test.rb} +1 -1
- data/test/{coverband/reporters/web_test.rb → unit/reports_web_test.rb} +2 -2
- data/test/{coverband/integrations → unit}/resque_worker_test.rb +8 -9
- data/test/{coverband/integrations → unit}/test_resque_job.rb +0 -0
- data/test/unit/utils/file_groups_test.rb +31 -0
- data/test/{coverband → unit}/utils/file_list_test.rb +0 -0
- data/test/{coverband → unit}/utils/gem_list_test.rb +0 -0
- data/test/{coverband → unit}/utils/lines_classifier_test.rb +0 -0
- data/test/{coverband → unit}/utils/result_test.rb +0 -0
- data/test/{coverband → unit}/utils/s3_report_test.rb +0 -0
- data/test/{coverband → unit}/utils/source_file_line_test.rb +0 -0
- data/test/{coverband → unit}/utils/source_file_test.rb +0 -0
- data/views/layout.erb +0 -4
- metadata +61 -100
- data/lib/coverband/utils/file_path_helper.rb +0 -57
- data/public/favicon.png +0 -0
- data/test/benchmarks/coverage_fork.sh +0 -37
- data/test/coverband/collectors/coverage_test.rb +0 -67
- data/test/coverband/reporters/base_test.rb +0 -168
- data/test/coverband/utils/file_groups_test.rb +0 -55
- data/test/rails4_dummy/tmp/.keep +0 -0
- data/test/unique_files.rb +0 -23
- data/views/settings.erb +0 -35
@@ -1,57 +0,0 @@
|
|
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
|
data/public/favicon.png
DELETED
Binary file
|
@@ -1,37 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
# This is a small script to illustrate how previous results get wiped out by forking
|
4
|
-
# this has implications of forking processes like Resque...
|
5
|
-
# this in the end would cause coverage.array_diff
|
6
|
-
# with previous results to add NEGATIVE code hits to the stored Coverage
|
7
|
-
# which in turn causes all sorts of crazy issues.
|
8
|
-
#
|
9
|
-
# ruby test/benchmarks/coverage_fork.rb
|
10
|
-
# in parent before fork
|
11
|
-
# {"/Users/danmayer/projects/coverband/test/dog.rb"=>[nil, nil, 1, 1, 2, nil, nil]}
|
12
|
-
# in child after fork
|
13
|
-
# {"/Users/danmayer/projects/coverband/test/dog.rb"=>[nil, nil, 0, 0, 0, nil, nil]}
|
14
|
-
# now triggering hits
|
15
|
-
# {"/Users/danmayer/projects/coverband/test/dog.rb"=>[nil, nil, 0, 0, 3, nil, nil]}
|
16
|
-
#
|
17
|
-
# I believe this might be related to CoW and GC... not sure
|
18
|
-
# http://patshaughnessy.net/2012/3/23/why-you-should-be-excited-about-garbage-collection-in-ruby-2-0
|
19
|
-
#
|
20
|
-
# NOTE: That the child now has 0 hits where previously method definitions had 1
|
21
|
-
# this causes all sorts of bad things to happen.
|
22
|
-
require 'coverage'
|
23
|
-
Coverage.start
|
24
|
-
load './test/dog.rb'
|
25
|
-
Dog.new.bark
|
26
|
-
Dog.new.bark
|
27
|
-
puts 'in parent before fork'
|
28
|
-
puts Coverage.peek_result
|
29
|
-
fork do
|
30
|
-
puts 'in child after fork'
|
31
|
-
puts Coverage.peek_result
|
32
|
-
puts 'now triggering hits'
|
33
|
-
Dog.new.bark
|
34
|
-
Dog.new.bark
|
35
|
-
Dog.new.bark
|
36
|
-
puts Coverage.peek_result
|
37
|
-
end
|
@@ -1,67 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
4
|
-
|
5
|
-
class CollectorsCoverageTest < Minitest::Test
|
6
|
-
attr_accessor :coverband
|
7
|
-
|
8
|
-
def setup
|
9
|
-
super
|
10
|
-
Coverband.configure do |config|
|
11
|
-
config.store = Coverband::Adapters::RedisStore.new(Redis.new)
|
12
|
-
end
|
13
|
-
@coverband = Coverband::Collectors::Coverage.instance.reset_instance
|
14
|
-
end
|
15
|
-
|
16
|
-
def teardown
|
17
|
-
Thread.current[:coverband_instance] = nil
|
18
|
-
Coverband.configure do |config|
|
19
|
-
end
|
20
|
-
@coverband = Coverband::Collectors::Coverage.instance.reset_instance
|
21
|
-
end
|
22
|
-
|
23
|
-
test 'Dog class coverage' do
|
24
|
-
file = require_unique_file
|
25
|
-
coverband.report_coverage(true)
|
26
|
-
coverage = Coverband.configuration.store.coverage
|
27
|
-
assert_equal(coverage[file]["data"], [nil, nil, 1, 1, 0, nil, nil])
|
28
|
-
end
|
29
|
-
|
30
|
-
test 'Dog method and class coverage' do
|
31
|
-
load File.expand_path('../../dog.rb', File.dirname(__FILE__))
|
32
|
-
Dog.new.bark
|
33
|
-
coverband.report_coverage(true)
|
34
|
-
coverage = Coverband.configuration.store.coverage
|
35
|
-
assert_equal(coverage["./test/dog.rb"]["data"], [nil, nil, 1, 1, 1, nil, nil])
|
36
|
-
end
|
37
|
-
|
38
|
-
test 'gets coverage instance' do
|
39
|
-
assert_equal Coverband::Collectors::Coverage, coverband.class
|
40
|
-
end
|
41
|
-
|
42
|
-
test 'defaults to a redis store' do
|
43
|
-
assert_equal Coverband::Adapters::RedisStore, coverband.instance_variable_get('@store').class
|
44
|
-
end
|
45
|
-
|
46
|
-
test 'report_coverage raises errors in tests' do
|
47
|
-
@coverband.reset_instance
|
48
|
-
@coverband.expects(:ready_to_report?).raises('Oh no')
|
49
|
-
assert_raises RuntimeError do
|
50
|
-
@coverband.report_coverage
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
test 'default tmp ignores' do
|
55
|
-
heroku_build_file = '/tmp/build_81feca8c72366e4edf020dc6f1937485/config/initializers/assets.rb'
|
56
|
-
assert_equal false, @coverband.send(:track_file?, heroku_build_file)
|
57
|
-
end
|
58
|
-
|
59
|
-
test '#array_diff never returns negative hits' do
|
60
|
-
# this can occur if a process forks after initializing the previous results
|
61
|
-
# see test/benchmarks/coverage_fork.rb
|
62
|
-
latest = [0, nil]
|
63
|
-
original = [1, nil]
|
64
|
-
expected = [0, nil]
|
65
|
-
assert_equal expected, @coverband.send(:array_diff, latest, original)
|
66
|
-
end
|
67
|
-
end
|
@@ -1,168 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
4
|
-
|
5
|
-
class ReportsBaseTest < Minitest::Test
|
6
|
-
test 'relative_path_to_full fix filename from a key with a swappable path' do
|
7
|
-
Coverband.configure do |config|
|
8
|
-
config.reporter = 'std_out'
|
9
|
-
config.root = '/full/remote_app/path'
|
10
|
-
end
|
11
|
-
|
12
|
-
key = '/app/is/a/path.rb'
|
13
|
-
# the code takes config.root expands and adds a '/' for the final path in roots
|
14
|
-
roots = ['/app/', '/full/remote_app/path/']
|
15
|
-
|
16
|
-
expected_path = '/full/remote_app/path/is/a/path.rb'
|
17
|
-
File.expects(:exist?).with(key).returns(false)
|
18
|
-
File.expects(:exist?).with(expected_path).returns(true)
|
19
|
-
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
20
|
-
end
|
21
|
-
|
22
|
-
test 'relative_path_to_full fix filename a changing deploy path with quotes' do
|
23
|
-
Coverband.configure do |config|
|
24
|
-
config.reporter = 'std_out'
|
25
|
-
config.root = '/full/remote_app/path'
|
26
|
-
end
|
27
|
-
|
28
|
-
expected_path = '/full/remote_app/path/app/models/user.rb'
|
29
|
-
key = '/box/apps/app_name/releases/20140725203539/app/models/user.rb'
|
30
|
-
roots = ["/box/apps/app_name/releases/\\d+/", '/full/remote_app/path/']
|
31
|
-
File.expects(:exist?).with('/box/apps/app_name/releases/\\d+/app/models/user.rb').returns(false)
|
32
|
-
File.expects(:exist?).with(expected_path).returns(true)
|
33
|
-
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
34
|
-
File.expects(:exist?).with('/box/apps/app_name/releases/\\d+/app/models/user.rb').returns(false)
|
35
|
-
File.expects(:exist?).with(expected_path).returns(true)
|
36
|
-
roots = ['/box/apps/app_name/releases/\d+/', '/full/remote_app/path/']
|
37
|
-
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
38
|
-
end
|
39
|
-
|
40
|
-
test 'relative_path_to_full fix filename a changing deploy path real world examples' do
|
41
|
-
current_app_root = '/var/local/company/company.d/79'
|
42
|
-
Coverband.configure do |config|
|
43
|
-
config.reporter = 'std_out'
|
44
|
-
config.root = current_app_root
|
45
|
-
end
|
46
|
-
|
47
|
-
expected_path = '/var/local/company/company.d/79/app/controllers/dashboard_controller.rb'
|
48
|
-
key = '/var/local/company/company.d/78/app/controllers/dashboard_controller.rb'
|
49
|
-
|
50
|
-
File.expects(:exist?).with('/var/local/company/company.d/[0-9]*/app/controllers/dashboard_controller.rb').returns(false)
|
51
|
-
File.expects(:exist?).with(expected_path).returns(true)
|
52
|
-
roots = ['/var/local/company/company.d/[0-9]*/', "#{current_app_root}/"]
|
53
|
-
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
54
|
-
File.expects(:exist?).with('/var/local/company/company.d/[0-9]*/app/controllers/dashboard_controller.rb').returns(false)
|
55
|
-
File.expects(:exist?).with(expected_path).returns(true)
|
56
|
-
roots = ["/var/local/company/company.d/[0-9]*/", "#{current_app_root}/"]
|
57
|
-
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
58
|
-
end
|
59
|
-
|
60
|
-
test 'relative_path_to_full leave filename from a key with a local path' do
|
61
|
-
Coverband.configure do |config|
|
62
|
-
config.reporter = 'std_out'
|
63
|
-
config.root = '/full/remote_app/path'
|
64
|
-
end
|
65
|
-
|
66
|
-
key = '/full/remote_app/path/is/a/path.rb'
|
67
|
-
# the code takes config.root expands and adds a '/' for the final path in roots
|
68
|
-
roots = ['/app/', '/full/remote_app/path/']
|
69
|
-
|
70
|
-
expected_path = '/full/remote_app/path/is/a/path.rb'
|
71
|
-
assert_equal expected_path, Coverband::Reporters::Base.send(:relative_path_to_full, key, roots)
|
72
|
-
end
|
73
|
-
|
74
|
-
test '#merge_arrays basic merge preserves order and counts' do
|
75
|
-
first = [0, 0, 1, 0, 1]
|
76
|
-
second = [nil, 0, 1, 0, 0]
|
77
|
-
expects = [0, 0, 2, 0, 1]
|
78
|
-
|
79
|
-
assert_equal expects, Coverband::Reporters::Base.send(:merge_arrays, first, second)
|
80
|
-
end
|
81
|
-
|
82
|
-
test '#merge_arrays basic merge preserves order and counts different lengths' do
|
83
|
-
first = [0, 0, 1, 0, 1]
|
84
|
-
second = [nil, 0, 1, 0, 0, 0, 0, 1]
|
85
|
-
expects = [0, 0, 2, 0, 1, 0, 0, 1]
|
86
|
-
|
87
|
-
assert_equal expects, Coverband::Reporters::Base.send(:merge_arrays, first, second)
|
88
|
-
end
|
89
|
-
|
90
|
-
test '#merge_arrays basic merge preserves nils' do
|
91
|
-
first = [0, 1, 2, nil, nil, nil]
|
92
|
-
second = [0, 1, 2, nil, 0, 1, 2]
|
93
|
-
expects = [0, 2, 4, nil, 0, 1, 2]
|
94
|
-
|
95
|
-
assert_equal expects, Coverband::Reporters::Base.send(:merge_arrays, first, second)
|
96
|
-
end
|
97
|
-
|
98
|
-
test "#get_current_scov_data_imp doesn't ignore folders with default ignore keys" do
|
99
|
-
@redis = Redis.new
|
100
|
-
store = Coverband::Adapters::RedisStore.new(@redis)
|
101
|
-
store.clear!
|
102
|
-
|
103
|
-
Coverband.configure do |config|
|
104
|
-
config.reporter = 'std_out'
|
105
|
-
config.root = '/full/remote_app/path'
|
106
|
-
config.store = store
|
107
|
-
end
|
108
|
-
|
109
|
-
key = '/a_path/that_has_erb_in/thepath.rb'
|
110
|
-
roots = ['/app/', '/full/remote_app/path/']
|
111
|
-
|
112
|
-
lines_hit = [1, 3, 6]
|
113
|
-
store.stubs(:coverage).returns(key => lines_hit)
|
114
|
-
expected = { key => [1, 3, 6] }
|
115
|
-
|
116
|
-
assert_equal expected, Coverband::Reporters::Base.send(:get_current_scov_data_imp, store, roots)
|
117
|
-
end
|
118
|
-
|
119
|
-
###
|
120
|
-
# This test uses real world example data which helped uncover a bug
|
121
|
-
# The copied data doesn't format easily and isn't worth the effort to meet
|
122
|
-
# string style
|
123
|
-
# rubocop:disable all
|
124
|
-
###
|
125
|
-
test '#get_current_scov_data_imp merges multiples of file data' do
|
126
|
-
coverage = {'/base/66/app/controllers/dashboard_controller.rb' =>
|
127
|
-
{"first_updated_at"=>1549610119,
|
128
|
-
"last_updated_at"=>1549610200,
|
129
|
-
"file_hash"=>"14dc84e940e26cbfb9ac79b43862e762",
|
130
|
-
"data"=>[1, 1, 1, nil, 1, 1, nil, nil, 1, nil, 1, 26, 26, nil, 26, 26, 26, 26, 26, 26, 26, nil, nil, 1, nil, 1, 26, 19, 0, 0, 0, 0, nil, nil, nil, nil, 0, 0, nil, nil, 1, 26, 26, 26, nil, nil, nil, nil, nil, 1, 26, nil, nil, 1, 26, nil, nil]},
|
131
|
-
'/base/78/app/controllers/dashboard_controller.rb' =>
|
132
|
-
{"first_updated_at"=>1549658574,
|
133
|
-
"last_updated_at"=>1549729830,
|
134
|
-
"file_hash"=>"14dc84e940e26cbfb9ac79b43862e762",
|
135
|
-
"data"=>[21, 21, 21, nil, 21, 21, nil, nil, 21, nil, 21, 22, 22, nil, 22, 22, 22, 22, 22, 22, 22, nil, nil, 21, nil, 21, 22, 13, 0, 0, 0, 0, nil, nil, nil, nil, 0, 0, nil, nil, 21, 22, 22, 22, nil, nil, nil, nil, nil, 21, 22, nil, nil, 21, 22, nil, nil]},
|
136
|
-
'/base/70/app/controllers/dashboard_controller.rb' =>
|
137
|
-
{"first_updated_at"=>1549617873,
|
138
|
-
"last_updated_at"=>1549618094,
|
139
|
-
"file_hash"=>"14dc84e940e26cbfb9ac79b43862e762",
|
140
|
-
"data"=>[16, 16, 16, nil, 16, 16, nil, nil, 16, nil, 16, 32, 32, nil, 32, 32, 32, 32, 32, 32, 32, nil, nil, 16, nil, 16, 32, 23, 0, 0, 0, 0, nil, nil, nil, nil, 0, 0, nil, nil, 16, 32, 32, 32, nil, nil, nil, nil, nil, 16, 32, nil, nil, 16, 32, nil, nil]}
|
141
|
-
}
|
142
|
-
@redis = Redis.new
|
143
|
-
store = Coverband::Adapters::RedisStore.new(@redis)
|
144
|
-
store.clear!
|
145
|
-
|
146
|
-
Coverband.configure do |config|
|
147
|
-
config.reporter = 'std_out'
|
148
|
-
config.root = '/base/78/app/'
|
149
|
-
config.store = store
|
150
|
-
end
|
151
|
-
|
152
|
-
key = '/base/78/app/app/controllers/dashboard_controller.rb'
|
153
|
-
roots = ['/base/[0-9]*/', '/base/78/app/']
|
154
|
-
|
155
|
-
lines_hit = [1, 3, 6]
|
156
|
-
store.stubs(:coverage).returns(coverage)
|
157
|
-
File.expects(:exist?).at_least_once
|
158
|
-
.with('/base/[0-9]*/app/controllers/dashboard_controller.rb')
|
159
|
-
.returns(false)
|
160
|
-
File.expects(:exist?).at_least_once.with(key).returns(true)
|
161
|
-
|
162
|
-
expected = {"first_updated_at"=>1549617873,
|
163
|
-
"last_updated_at"=>1549618094,
|
164
|
-
"file_hash"=>"14dc84e940e26cbfb9ac79b43862e762",
|
165
|
-
"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]}
|
166
|
-
assert_equal expected, Coverband::Reporters::Base.send(:get_current_scov_data_imp, store, roots)[key]
|
167
|
-
end
|
168
|
-
end
|
@@ -1,55 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require File.expand_path('../../test_helper', File.dirname(__FILE__))
|
4
|
-
|
5
|
-
describe Coverband::Utils::FileGroups do
|
6
|
-
FAKE_GEM_PATH = 'fake/gem/path'
|
7
|
-
subject do
|
8
|
-
controller_lines = [nil, 2, 2, 0, nil, nil, 0, nil, nil, nil]
|
9
|
-
files = [
|
10
|
-
Coverband::Utils::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil]),
|
11
|
-
Coverband::Utils::SourceFile.new(source_fixture('app/models/user.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]),
|
12
|
-
Coverband::Utils::SourceFile.new(source_fixture('app/controllers/sample_controller.rb'), controller_lines),
|
13
|
-
Coverband::Utils::SourceFile.new("#{FAKE_GEM_PATH}/gem_name.rb", controller_lines)
|
14
|
-
]
|
15
|
-
Coverband.configuration.expects(:gem_paths).at_least_once.returns([FAKE_GEM_PATH])
|
16
|
-
Coverband.configuration.track_gems = true
|
17
|
-
Coverband::Utils::FileGroups.new(files)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'has app files' do
|
21
|
-
assert_equal 'test/fixtures/sample.rb', subject.grouped_results['App'].first.short_name
|
22
|
-
end
|
23
|
-
|
24
|
-
it 'has gem files' do
|
25
|
-
assert_equal "#{FAKE_GEM_PATH}/gem_name.rb", subject.grouped_results['Gems'].first.first.short_name
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
describe Coverband::Utils::FileGroups, :vendored_gems do
|
30
|
-
FAKE_VENDOR_GEM_PATH = "#{test_root}/app/vendor/bundle/ruby/2.5.0/gems"
|
31
|
-
subject do
|
32
|
-
controller_lines = [nil, 2, 2, 0, nil, nil, 0, nil, nil, nil]
|
33
|
-
files = [
|
34
|
-
Coverband::Utils::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil]),
|
35
|
-
Coverband::Utils::SourceFile.new(source_fixture('app/models/user.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]),
|
36
|
-
Coverband::Utils::SourceFile.new(source_fixture('app/controllers/sample_controller.rb'), controller_lines),
|
37
|
-
Coverband::Utils::SourceFile.new("#{FAKE_VENDOR_GEM_PATH}/gem_name.rb", controller_lines)
|
38
|
-
]
|
39
|
-
Coverband.configuration.expects(:gem_paths).at_least_once.returns([FAKE_VENDOR_GEM_PATH])
|
40
|
-
Coverband.configuration.track_gems = true
|
41
|
-
Coverband::Utils::FileGroups.new(files)
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'has app files' do
|
45
|
-
assert_equal 'test/fixtures/sample.rb', subject.grouped_results['App'].first.short_name
|
46
|
-
end
|
47
|
-
|
48
|
-
it "doesn't include vendor gems in app files app files" do
|
49
|
-
assert_nil subject.grouped_results['App'].select { |files| files.short_name.match(/gem_name/) }.first
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'does has gem files' do
|
53
|
-
assert_equal 'gem_name.rb', subject.grouped_results['Gems'].first.first.short_name
|
54
|
-
end
|
55
|
-
end
|
data/test/rails4_dummy/tmp/.keep
DELETED
File without changes
|
data/test/unique_files.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'securerandom'
|
4
|
-
require 'fileutils'
|
5
|
-
|
6
|
-
UNIQUE_FILES_DIR = "./test/unique_files"
|
7
|
-
|
8
|
-
def require_unique_file(file = 'dog.rb')
|
9
|
-
dir = "#{UNIQUE_FILES_DIR}/#{SecureRandom.uuid}"
|
10
|
-
FileUtils.mkdir_p(dir)
|
11
|
-
temp_file = "#{dir}/#{file}"
|
12
|
-
File.open(temp_file, 'w'){ |w| w.write(File.read("./test/#{file}")) }
|
13
|
-
require temp_file
|
14
|
-
temp_file
|
15
|
-
end
|
16
|
-
|
17
|
-
def remove_unique_files
|
18
|
-
FileUtils.rm_r(UNIQUE_FILES_DIR) if File.exist?(UNIQUE_FILES_DIR)
|
19
|
-
end
|
20
|
-
|
21
|
-
Minitest.after_run do
|
22
|
-
remove_unique_files
|
23
|
-
end
|
data/views/settings.erb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
<html xmlns='http://www.w3.org/1999/xhtml'>
|
3
|
-
<head>
|
4
|
-
<title>Coverband Info: <%= Coverband::VERSION %></title>
|
5
|
-
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
|
6
|
-
<script src='<%= assets_path('application.js') %>' type='text/javascript'></script>
|
7
|
-
<link href='<%= assets_path('application.css') %>' media='screen, projection, print' rel='stylesheet' type='text/css'>
|
8
|
-
<link rel="icon" type="image/png" href="<%= assets_path('favicon.png') %>" />
|
9
|
-
</head>
|
10
|
-
|
11
|
-
<body>
|
12
|
-
<div id="wrapper" style="">
|
13
|
-
<div id="header">
|
14
|
-
<a href='<%= base_path %>'>Coverband Admin</a>
|
15
|
-
<a href='<%= base_path %>settings'>Info</a>
|
16
|
-
</div>
|
17
|
-
<div id="content">
|
18
|
-
<dl>
|
19
|
-
<% Coverband.configuration.to_h.each_pair do |key,value| %>
|
20
|
-
<dt><%= key %></dt>
|
21
|
-
<dd><%= value %></dd>
|
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>
|
28
|
-
</dl>
|
29
|
-
</div>
|
30
|
-
<div id="footer">
|
31
|
-
Generated by <a href="http://github.com/danmayer/coverband">Coverband</a> v<%= Coverband::VERSION %>
|
32
|
-
</div>
|
33
|
-
</div>
|
34
|
-
</body>
|
35
|
-
</html>
|