coverband 1.3.1 → 1.5.0
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.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/README.md +39 -6
- data/changes.md +23 -0
- data/coverband.gemspec +2 -1
- data/lib/coverband.rb +12 -11
- data/lib/coverband/adapters/file_store.rb +59 -0
- data/lib/coverband/adapters/memory_cache_store.rb +46 -0
- data/lib/coverband/adapters/redis_store.rb +101 -0
- data/lib/coverband/base.rb +4 -7
- data/lib/coverband/baseline.rb +35 -0
- data/lib/coverband/configuration.rb +20 -5
- data/lib/coverband/reporters/base.rb +150 -0
- data/lib/coverband/reporters/console_report.rb +17 -0
- data/lib/coverband/reporters/simple_cov_report.rb +46 -0
- data/lib/coverband/s3_report_writer.rb +6 -1
- data/lib/coverband/tasks.rb +26 -16
- data/lib/coverband/version.rb +1 -1
- data/test/benchmarks/benchmark.rake +57 -7
- data/test/test_helper.rb +20 -0
- data/test/unit/adapters_file_store_test.rb +41 -0
- data/test/unit/{memory_cache_store_test.rb → adapters_memory_cache_store_test.rb} +12 -12
- data/test/unit/adapters_redis_store_test.rb +164 -0
- data/test/unit/base_test.rb +8 -7
- data/test/unit/baseline_test.rb +50 -0
- data/test/unit/middleware_test.rb +8 -8
- data/test/unit/reports_base_test.rb +140 -0
- data/test/unit/reports_console_test.rb +37 -0
- data/test/unit/reports_simple_cov_test.rb +68 -0
- data/test/unit/s3_report_writer_test.rb +1 -0
- metadata +37 -24
- data/lib/coverband/memory_cache_store.rb +0 -42
- data/lib/coverband/redis_store.rb +0 -57
- data/lib/coverband/reporter.rb +0 -223
- data/test/unit/redis_store_test.rb +0 -107
- data/test/unit/reporter_test.rb +0 -207
@@ -1,107 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class RedisTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
def setup
|
6
|
-
@redis = Redis.new
|
7
|
-
@redis.flushdb
|
8
|
-
@store = Coverband::RedisStore.new(@redis)
|
9
|
-
end
|
10
|
-
|
11
|
-
def test_covered_lines_for_file
|
12
|
-
@redis.sadd('coverband.dog.rb', 1)
|
13
|
-
@redis.sadd('coverband.dog.rb', 2)
|
14
|
-
assert_equal @store.covered_lines_for_file('dog.rb').sort, [1, 2]
|
15
|
-
end
|
16
|
-
|
17
|
-
def test_covered_lines_when_null
|
18
|
-
assert_equal @store.covered_lines_for_file('dog.rb'), []
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def test_data
|
24
|
-
{
|
25
|
-
"/Users/danmayer/projects/cover_band_server/app.rb" => { 54 => 1, 55 => 2 },
|
26
|
-
"/Users/danmayer/projects/cover_band_server/server.rb" => { 5 => 1 }
|
27
|
-
}
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
class RedisStoreTestV3 < RedisTest
|
32
|
-
|
33
|
-
def setup
|
34
|
-
@redis = Redis.current.tap { |redis|
|
35
|
-
redis.stubs(:sadd).with(anything, anything)
|
36
|
-
redis.stubs(:info).returns({'redis_version' => 3.0})
|
37
|
-
}
|
38
|
-
|
39
|
-
@store = Coverband::RedisStore.new(@redis)
|
40
|
-
end
|
41
|
-
|
42
|
-
test "it stores the files into coverband" do
|
43
|
-
@redis.expects(:sadd).with('coverband', [
|
44
|
-
'/Users/danmayer/projects/cover_band_server/app.rb',
|
45
|
-
'/Users/danmayer/projects/cover_band_server/server.rb'
|
46
|
-
])
|
47
|
-
|
48
|
-
@store.store_report(test_data)
|
49
|
-
end
|
50
|
-
|
51
|
-
test "it stores the file lines of the file app.rb" do
|
52
|
-
@redis.expects(:sadd).with(
|
53
|
-
'coverband./Users/danmayer/projects/cover_band_server/app.rb',
|
54
|
-
[54, 55]
|
55
|
-
)
|
56
|
-
|
57
|
-
@store.store_report(test_data)
|
58
|
-
end
|
59
|
-
|
60
|
-
test "it stores the file lines of the file server.rb" do
|
61
|
-
@redis.expects(:sadd).with(
|
62
|
-
'coverband./Users/danmayer/projects/cover_band_server/server.rb',
|
63
|
-
[5]
|
64
|
-
)
|
65
|
-
|
66
|
-
@store.store_report(test_data)
|
67
|
-
end
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
class RedisStoreTestV223 < RedisTest
|
72
|
-
|
73
|
-
def setup
|
74
|
-
@redis = Redis.current.tap { |redis|
|
75
|
-
redis.stubs(:sadd).with(anything, anything)
|
76
|
-
redis.stubs(:info).returns({'redis_version' => "2.2.3"})
|
77
|
-
}
|
78
|
-
|
79
|
-
@store = Coverband::RedisStore.new(@redis)
|
80
|
-
end
|
81
|
-
|
82
|
-
test "it store the files with separate calls into coverband" do
|
83
|
-
@redis.expects(:sadd).with('coverband', '/Users/danmayer/projects/cover_band_server/app.rb')
|
84
|
-
@redis.expects(:sadd).with('coverband', '/Users/danmayer/projects/cover_band_server/server.rb')
|
85
|
-
|
86
|
-
@store.store_report(test_data)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
class RedisStoreTestV222 < RedisTest
|
91
|
-
|
92
|
-
def setup
|
93
|
-
@redis = Redis.current.tap { |redis|
|
94
|
-
redis.stubs(:sadd).with(anything, anything)
|
95
|
-
redis.stubs(:info).returns({'redis_version' => "2.2.2"})
|
96
|
-
}
|
97
|
-
|
98
|
-
@store = Coverband::RedisStore.new(@redis)
|
99
|
-
end
|
100
|
-
|
101
|
-
test "it store the files with separate calls into coverband" do
|
102
|
-
@redis.expects(:sadd).with('coverband', '/Users/danmayer/projects/cover_band_server/app.rb')
|
103
|
-
@redis.expects(:sadd).with('coverband', '/Users/danmayer/projects/cover_band_server/server.rb')
|
104
|
-
|
105
|
-
@store.store_report(test_data)
|
106
|
-
end
|
107
|
-
end
|
data/test/unit/reporter_test.rb
DELETED
@@ -1,207 +0,0 @@
|
|
1
|
-
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
-
|
3
|
-
class ReporterTest < Test::Unit::TestCase
|
4
|
-
|
5
|
-
test "record baseline" do
|
6
|
-
Coverage.expects(:start).returns(true).at_least_once
|
7
|
-
Coverage.expects(:result).returns({'fake' => [0,1]}).at_least_once
|
8
|
-
File.expects(:open).once
|
9
|
-
|
10
|
-
Coverband::Reporter.stubs(:puts)
|
11
|
-
|
12
|
-
Coverband::Reporter.baseline{
|
13
|
-
#nothing
|
14
|
-
}
|
15
|
-
end
|
16
|
-
|
17
|
-
test "report data" do
|
18
|
-
Coverband.configure do |config|
|
19
|
-
config.redis = fake_redis
|
20
|
-
config.reporter = 'std_out'
|
21
|
-
end
|
22
|
-
|
23
|
-
Coverband::Reporter.expects(:current_root).returns('/root_dir')
|
24
|
-
fake_redis.expects(:smembers).with('coverband').returns(fake_coverband_members)
|
25
|
-
|
26
|
-
fake_coverband_members.each do |key|
|
27
|
-
fake_redis.expects(:smembers).with("coverband.#{key}").returns(["54", "55"])
|
28
|
-
end
|
29
|
-
|
30
|
-
matchers = [regexp_matches(/tester/),
|
31
|
-
regexp_matches(/application_controller/),
|
32
|
-
regexp_matches(/account/),
|
33
|
-
regexp_matches(/54/)]
|
34
|
-
|
35
|
-
Coverband.configuration.logger.expects('info').with(all_of(*matchers))
|
36
|
-
|
37
|
-
Coverband::Reporter.report
|
38
|
-
end
|
39
|
-
|
40
|
-
test "report data with scov" do
|
41
|
-
Coverband.configure do |config|
|
42
|
-
config.redis = fake_redis
|
43
|
-
config.reporter = 'scov'
|
44
|
-
config.s3_bucket = nil
|
45
|
-
end
|
46
|
-
|
47
|
-
Coverband::Reporter.expects(:current_root).at_least_once.returns('/root_dir')
|
48
|
-
fake_redis.expects(:smembers).with('coverband').returns(fake_coverband_members)
|
49
|
-
|
50
|
-
fake_coverband_members.each do |key|
|
51
|
-
File.expects(:exists?).with(key).returns(true)
|
52
|
-
File.expects(:foreach).with(key).returns(['a','b','c'])
|
53
|
-
fake_redis.expects(:smembers).with("coverband.#{key}").returns(["54", "55"])
|
54
|
-
end
|
55
|
-
|
56
|
-
Coverband.configuration.logger.stubs('info')
|
57
|
-
|
58
|
-
Coverband::Reporter.report(open_report: false)
|
59
|
-
end
|
60
|
-
|
61
|
-
####
|
62
|
-
# TODO
|
63
|
-
# attempting to write some tests around this reporter
|
64
|
-
# shows that it has become a disaster of self methods relying on side effects.
|
65
|
-
# Fix to standard class and methods.
|
66
|
-
####
|
67
|
-
test "filename_from_key fix filename from a key with a swappable path" do
|
68
|
-
Coverband.configure do |config|
|
69
|
-
config.redis = fake_redis
|
70
|
-
config.reporter = 'std_out'
|
71
|
-
config.root = '/full/remote_app/path'
|
72
|
-
end
|
73
|
-
|
74
|
-
key = "/app/is/a/path.rb"
|
75
|
-
#the code takes config.root expands and adds a '/' for the final path in roots
|
76
|
-
roots = ["/app/", '/full/remote_app/path/']
|
77
|
-
|
78
|
-
assert_equal "/full/remote_app/path/is/a/path.rb", Coverband::Reporter.filename_from_key(key, roots)
|
79
|
-
end
|
80
|
-
|
81
|
-
test "filename_from_key fix filename a changing deploy path with double quotes" do
|
82
|
-
Coverband.configure do |config|
|
83
|
-
config.redis = fake_redis
|
84
|
-
config.reporter = 'std_out'
|
85
|
-
config.root = '/full/remote_app/path'
|
86
|
-
end
|
87
|
-
|
88
|
-
key = "/box/apps/app_name/releases/20140725203539/app/models/user.rb"
|
89
|
-
# the code takes config.root expands and adds a '/' for the final path in roots
|
90
|
-
# note to get regex to work for changing deploy directories it must be double escaped in double quotes or use single qoutes
|
91
|
-
roots = ["/box/apps/app_name/releases/\\d+/", '/full/remote_app/path/']
|
92
|
-
|
93
|
-
assert_equal "/full/remote_app/path/app/models/user.rb", Coverband::Reporter.filename_from_key(key, roots)
|
94
|
-
end
|
95
|
-
|
96
|
-
test "filename_from_key fix filename a changing deploy path with single quotes" do
|
97
|
-
Coverband.configure do |config|
|
98
|
-
config.redis = fake_redis
|
99
|
-
config.reporter = 'std_out'
|
100
|
-
config.root = '/full/remote_app/path'
|
101
|
-
end
|
102
|
-
|
103
|
-
key = "/box/apps/app_name/releases/20140725203539/app/models/user.rb"
|
104
|
-
# the code takes config.root expands and adds a '/' for the final path in roots
|
105
|
-
# note to get regex to work for changing deploy directories it must be double escaped in double quotes or use single qoutes
|
106
|
-
roots = ['/box/apps/app_name/releases/\d+/', '/full/remote_app/path/']
|
107
|
-
|
108
|
-
assert_equal "/full/remote_app/path/app/models/user.rb", Coverband::Reporter.filename_from_key(key, roots)
|
109
|
-
end
|
110
|
-
|
111
|
-
test "filename_from_key leave filename from a key with a local path" do
|
112
|
-
Coverband.configure do |config|
|
113
|
-
config.redis = fake_redis
|
114
|
-
config.reporter = 'std_out'
|
115
|
-
config.root = '/full/remote_app/path'
|
116
|
-
end
|
117
|
-
|
118
|
-
key = "/full/remote_app/path/is/a/path.rb"
|
119
|
-
#the code takes config.root expands and adds a '/' for the final path in roots
|
120
|
-
roots = ["/app/", '/full/remote_app/path/']
|
121
|
-
|
122
|
-
assert_equal "/full/remote_app/path/is/a/path.rb", Coverband::Reporter.filename_from_key(key, roots)
|
123
|
-
end
|
124
|
-
|
125
|
-
test "line_hash gets correct hash entry for a line key" do
|
126
|
-
Coverband.configure do |config|
|
127
|
-
config.redis = fake_redis
|
128
|
-
config.reporter = 'std_out'
|
129
|
-
config.root = '/full/remote_app/path'
|
130
|
-
end
|
131
|
-
|
132
|
-
key = "/full/remote_app/path/is/a/path.rb"
|
133
|
-
#the code takes config.root expands and adds a '/'
|
134
|
-
roots = ["/app/", '/full/remote_app/path/']
|
135
|
-
|
136
|
-
current_redis = fake_redis
|
137
|
-
lines_hit = ['1','3','6']
|
138
|
-
current_redis.stubs(:smembers).returns(lines_hit)
|
139
|
-
#expects to show hit counts on 1,3,6
|
140
|
-
expected = {"/full/remote_app/path/is/a/path.rb" => [1,0,1,0,0,1]}
|
141
|
-
File.stubs(:exists?).returns(true)
|
142
|
-
File.stubs(:foreach).returns(['line 1','line2','line3','line4','line5','line6'])
|
143
|
-
|
144
|
-
assert_equal expected, Coverband::Reporter.line_hash(current_redis, key, roots)
|
145
|
-
end
|
146
|
-
|
147
|
-
test "line_hash adjusts relative paths" do
|
148
|
-
Coverband.configure do |config|
|
149
|
-
config.redis = fake_redis
|
150
|
-
config.reporter = 'std_out'
|
151
|
-
config.root = '/full/remote_app/path'
|
152
|
-
end
|
153
|
-
|
154
|
-
key = "./is/a/path.rb"
|
155
|
-
#the code takes config.root expands and adds a '/'
|
156
|
-
roots = ["/app/", '/full/remote_app/path/']
|
157
|
-
|
158
|
-
current_redis = fake_redis
|
159
|
-
lines_hit = ['1','3','6']
|
160
|
-
current_redis.stubs(:smembers).returns(lines_hit)
|
161
|
-
#expects to show hit counts on 1,3,6
|
162
|
-
expected = {"/full/remote_app/path/is/a/path.rb" => [1,0,1,0,0,1]}
|
163
|
-
File.stubs(:exists?).returns(true)
|
164
|
-
File.stubs(:foreach).returns(['line 1','line2','line3','line4','line5','line6'])
|
165
|
-
|
166
|
-
assert_equal expected, Coverband::Reporter.line_hash(current_redis, key, roots)
|
167
|
-
end
|
168
|
-
|
169
|
-
test "#merge_arrays basic merge preserves order and counts" do
|
170
|
-
first = [0,0,1,0,1]
|
171
|
-
second = [nil,0,1,0,0]
|
172
|
-
expects = [0,0,1,0,1]
|
173
|
-
|
174
|
-
assert_equal expects, Coverband::Reporter.merge_arrays(first, second)
|
175
|
-
end
|
176
|
-
|
177
|
-
test "#merge_arrays basic merge preserves order and counts different lenths" do
|
178
|
-
first = [0,0,1,0,1]
|
179
|
-
second = [nil,0,1,0,0,0,0,1]
|
180
|
-
expects = [0,0,1,0,1,0,0,1]
|
181
|
-
|
182
|
-
assert_equal expects, Coverband::Reporter.merge_arrays(first, second)
|
183
|
-
end
|
184
|
-
|
185
|
-
private
|
186
|
-
|
187
|
-
def fake_redis
|
188
|
-
@redis ||= begin
|
189
|
-
redis = OpenStruct.new()
|
190
|
-
def redis.smembers(key)
|
191
|
-
end
|
192
|
-
redis
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
def fake_coverband_members
|
197
|
-
["/Users/danmayer/projects/hearno/script/tester.rb",
|
198
|
-
"/Users/danmayer/projects/hearno/app/controllers/application_controller.rb",
|
199
|
-
"/Users/danmayer/projects/hearno/app/models/account.rb"
|
200
|
-
]
|
201
|
-
end
|
202
|
-
|
203
|
-
def fake_coverage_report
|
204
|
-
{"/Users/danmayer/projects/hearno/script/tester.rb"=>[1, nil, 1, 1, nil, nil, nil]}
|
205
|
-
end
|
206
|
-
|
207
|
-
end
|