oneshot_cov 0.3.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +35 -0
- data/README.md +54 -1
- data/lib/oneshot_cov.rb +8 -3
- data/lib/oneshot_cov/logger/each_file_logger.rb +18 -0
- data/lib/oneshot_cov/logger/line_by_line_logger.rb +20 -0
- data/lib/oneshot_cov/logger/replace_logger.rb +35 -0
- data/lib/oneshot_cov/reporter.rb +2 -2
- data/lib/oneshot_cov/version.rb +1 -1
- metadata +6 -3
- data/lib/oneshot_cov/logger.rb +0 -33
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 69b518feccec2167f23f4966fa6555025c439117b07004ca96292796b206397a
|
4
|
+
data.tar.gz: 155e225c25569b761bc8863f459177ddcf58eda2abe266db1da460014cb5649c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 84e8913cf76ca73cd6f2624bca634892fbb626b57549b7eab3ed555c4e13098ea7b5b4867cb6815cac585991c6012436511cdad596daf6b799f46426f8680eb2
|
7
|
+
data.tar.gz: a8d6da794ebbb580ec28cf6822d465965a2d4ae0b227b1078eda758028969b3139dbf40158a4cc5d4a59ce45fbc599b9a8176c4d20da5d9079acdade685959fc
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
oneshot_cov (1.0.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.9.0)
|
12
|
+
rspec-core (~> 3.9.0)
|
13
|
+
rspec-expectations (~> 3.9.0)
|
14
|
+
rspec-mocks (~> 3.9.0)
|
15
|
+
rspec-core (3.9.2)
|
16
|
+
rspec-support (~> 3.9.3)
|
17
|
+
rspec-expectations (3.9.2)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.9.0)
|
20
|
+
rspec-mocks (3.9.1)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.9.0)
|
23
|
+
rspec-support (3.9.3)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.17)
|
30
|
+
oneshot_cov!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.17.2
|
data/README.md
CHANGED
@@ -22,7 +22,60 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
Create a configuration file to run `OneshotCov.configure` and` OneshotCov.start`
|
26
|
+
The logger sample will be described later.
|
27
|
+
|
28
|
+
```ruby:config/initializers/oneshot_cov.rb
|
29
|
+
logger = Rails.application.config.oneshot_cov_logger
|
30
|
+
|
31
|
+
OneshotCov.configure(
|
32
|
+
logger: OneshotCov::Logger::LineByLineLogger.new(logger),
|
33
|
+
emit_term: 600,
|
34
|
+
)
|
35
|
+
OneshotCov.start
|
36
|
+
```
|
37
|
+
|
38
|
+
### Sample loggers
|
39
|
+
|
40
|
+
* LineByLineLogger(logger)
|
41
|
+
|
42
|
+
The logger passed to the argument is set in the application config
|
43
|
+
please
|
44
|
+
|
45
|
+
```ruby:config/application.rb
|
46
|
+
config.oneshot_cov_logger = Logger.new(Rails.root.join('log/oneshot_cov.log'))
|
47
|
+
config.oneshot_cov_logger.formatter = proc { |_, _, _, msg| "#{msg}\n" }
|
48
|
+
```
|
49
|
+
|
50
|
+
```
|
51
|
+
app/controllers/users/user?controller.rb: 2
|
52
|
+
app/controllers/users/user?controller.rb: 3
|
53
|
+
app/controllers/users/user?controller.rb: 4
|
54
|
+
```
|
55
|
+
|
56
|
+
* EachFileLogger(logger)
|
57
|
+
|
58
|
+
The logger passed to the argument is set in the application config
|
59
|
+
please
|
60
|
+
|
61
|
+
```ruby:config/application.rb
|
62
|
+
config.oneshot_cov_logger = Logger.new(Rails.root.join('log/oneshot_cov.log'))
|
63
|
+
config.oneshot_cov_logger.formatter = proc { |_, _, _, msg| "#{msg}\n" }
|
64
|
+
```
|
65
|
+
|
66
|
+
```ruby:config/initializers/oneshot_cov.rb
|
67
|
+
logger = Rails.application.config.oneshot_cov_logger
|
68
|
+
|
69
|
+
OneshotCov.configure(
|
70
|
+
logger: OneshotCov::Logger::EachFileLogger.new(logger),
|
71
|
+
emit_term: 600,
|
72
|
+
)
|
73
|
+
OneshotCov.start
|
74
|
+
```
|
75
|
+
|
76
|
+
```
|
77
|
+
app/controllers/users/user?controller.rb: 2,3,4
|
78
|
+
```
|
26
79
|
|
27
80
|
## Development
|
28
81
|
|
data/lib/oneshot_cov.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "coverage"
|
2
2
|
|
3
|
-
require "oneshot_cov/logger"
|
3
|
+
require "oneshot_cov/logger/line_by_line_logger"
|
4
|
+
require "oneshot_cov/logger/replace_logger"
|
5
|
+
require "oneshot_cov/logger/each_file_logger"
|
4
6
|
require "oneshot_cov/middleware"
|
5
7
|
require "oneshot_cov/reporter"
|
6
8
|
require "oneshot_cov/railtie" if defined?(Rails)
|
@@ -18,11 +20,14 @@ module OneshotCov
|
|
18
20
|
end
|
19
21
|
|
20
22
|
def emit(force_emit: false)
|
21
|
-
OneshotCov.configure if @reporter.nil?
|
22
23
|
@reporter.emit(force_emit)
|
23
24
|
end
|
24
25
|
|
25
|
-
def configure(target_path: Rails.root, logger:
|
26
|
+
def configure(target_path: Rails.root, logger: nil, emit_term: nil)
|
27
|
+
if logger.nil?
|
28
|
+
raise ArgumentError.new("Specifying logger in `OneshotCov.configure` is mandatory`")
|
29
|
+
end
|
30
|
+
|
26
31
|
target_path_by_pathname =
|
27
32
|
if target_path.is_a? Pathname
|
28
33
|
target_path
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module OneshotCov
|
2
|
+
module Logger
|
3
|
+
class EachFileLogger
|
4
|
+
def initialize(logger)
|
5
|
+
@logger = logger
|
6
|
+
end
|
7
|
+
|
8
|
+
def post(new_logs)
|
9
|
+
new_logs.each do |new_log|
|
10
|
+
log_path = new_log.path
|
11
|
+
lines = new_log.lines.join(",")
|
12
|
+
|
13
|
+
@logger.info("#{log_path}: #{lines}")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module OneshotCov
|
2
|
+
module Logger
|
3
|
+
class LineByLineLogger
|
4
|
+
def initialize(logger)
|
5
|
+
@logger = logger
|
6
|
+
end
|
7
|
+
|
8
|
+
def post(new_logs)
|
9
|
+
new_logs.each do |new_log|
|
10
|
+
log_path = new_log.path
|
11
|
+
oneshot_lines = new_log.lines
|
12
|
+
|
13
|
+
oneshot_lines.each do |line|
|
14
|
+
@logger.info("#{log_path}: #{line}")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module OneshotCov
|
4
|
+
module Logger
|
5
|
+
class ReplaceLogger
|
6
|
+
def initialize(log_path)
|
7
|
+
@log_path = log_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def post(new_logs)
|
11
|
+
current_coverage = fetch
|
12
|
+
|
13
|
+
new_logs.each do |new_log|
|
14
|
+
key = "#{new_log.path}"
|
15
|
+
|
16
|
+
logged_lines = current_coverage.fetch(key, [])
|
17
|
+
current_coverage[key] = logged_lines | new_log.lines
|
18
|
+
end
|
19
|
+
save(current_coverage)
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def fetch
|
25
|
+
JSON.load(File.read(@log_path))
|
26
|
+
rescue Errno::ENOENT
|
27
|
+
{}
|
28
|
+
end
|
29
|
+
|
30
|
+
def save(data)
|
31
|
+
File.write(@log_path, JSON.dump(data))
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/lib/oneshot_cov/reporter.rb
CHANGED
@@ -27,7 +27,7 @@ module OneshotCov
|
|
27
27
|
Coverage.result(clear: true, stop: false).
|
28
28
|
select { |k, v| is_target?(k, v) }.
|
29
29
|
map do |filepath, v|
|
30
|
-
OneshotLog.new(relative_path(filepath), v)
|
30
|
+
OneshotLog.new(relative_path(filepath), v[:oneshot_lines])
|
31
31
|
end
|
32
32
|
|
33
33
|
if logs.size > 0
|
@@ -49,7 +49,7 @@ module OneshotCov
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def is_target?(filepath, value)
|
52
|
-
return false if value.empty?
|
52
|
+
return false if value[:oneshot_lines].empty?
|
53
53
|
return false if !filepath.start_with?(@target_path)
|
54
54
|
return false if @bundler_path && filepath.start_with?(@bundler_path)
|
55
55
|
true
|
data/lib/oneshot_cov/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oneshot_cov
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- soartec-lab
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -64,13 +64,16 @@ files:
|
|
64
64
|
- ".travis.yml"
|
65
65
|
- CODE_OF_CONDUCT.md
|
66
66
|
- Gemfile
|
67
|
+
- Gemfile.lock
|
67
68
|
- LICENSE.txt
|
68
69
|
- README.md
|
69
70
|
- Rakefile
|
70
71
|
- bin/console
|
71
72
|
- bin/setup
|
72
73
|
- lib/oneshot_cov.rb
|
73
|
-
- lib/oneshot_cov/logger.rb
|
74
|
+
- lib/oneshot_cov/logger/each_file_logger.rb
|
75
|
+
- lib/oneshot_cov/logger/line_by_line_logger.rb
|
76
|
+
- lib/oneshot_cov/logger/replace_logger.rb
|
74
77
|
- lib/oneshot_cov/middleware.rb
|
75
78
|
- lib/oneshot_cov/railtie.rb
|
76
79
|
- lib/oneshot_cov/reporter.rb
|
data/lib/oneshot_cov/logger.rb
DELETED
@@ -1,33 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
|
-
module OneshotCov
|
4
|
-
class Logger
|
5
|
-
def initialize(log_path)
|
6
|
-
@log_path = log_path
|
7
|
-
end
|
8
|
-
|
9
|
-
def post(new_logs)
|
10
|
-
current_coverage = fetch
|
11
|
-
|
12
|
-
new_logs.each do |new_log|
|
13
|
-
key = "#{new_log.path}"
|
14
|
-
|
15
|
-
logged_lines = current_coverage.fetch(key, [])
|
16
|
-
current_coverage[key] = logged_lines | new_log.lines
|
17
|
-
end
|
18
|
-
save(current_coverage)
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def fetch
|
24
|
-
JSON.load(File.read(@log_path))
|
25
|
-
rescue Errno::ENOENT
|
26
|
-
{}
|
27
|
-
end
|
28
|
-
|
29
|
-
def save(data)
|
30
|
-
File.write(@log_path, JSON.dump(data))
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|