simplecov-oj 0.18.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +13 -0
- data/LICENSE +21 -0
- data/README.md +64 -0
- data/lib/simple_cov/formatter/oj_formatter.rb +51 -0
- data/lib/simple_cov/oj/output_message.rb +57 -0
- data/lib/simple_cov/oj/result_to_hash.rb +61 -0
- data/lib/simple_cov/oj/result_wrapper.rb +63 -0
- data/lib/simple_cov/oj/source_file_wrapper.rb +89 -0
- data/lib/simple_cov/oj/version.rb +14 -0
- data/lib/simplecov-oj.rb +12 -0
- data/lib/tasks/changelog.rake +24 -0
- data/spec/simple_cov/formatter/oj_formatter_spec.rb +91 -0
- data/spec/spec_helper.rb +41 -0
- metadata +245 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: c79725e77c65ffc720f386f1fc92a5bb131c3ed85253f5020b211397cf51c864
|
4
|
+
data.tar.gz: 41c1cf717b408c4b6e8e7abf1504178d2d020b662d6a256cd55b7477d301ab4c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: ea9788ab04d7a288938cfd83298991d94b24801acfe9397809345a0c200ad5e2c05ffde92e6079477bdbe2806cdac203f59c9f9767998c94ec6a5d1f91a92f1f
|
7
|
+
data.tar.gz: 1a5cc01c0056abada359228d2681fb50d67c2a17f75597241908e33b4004d06c5b3804ed60b353489105cad1ff81dd98cc3108c4fe1d1ae412433e5406deec9a
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
## [v0.18.0](https://github.com/mhenrixon/simplecov-oj/tree/v0.18.0) (2020-01-29)
|
4
|
+
|
5
|
+
[Full Changelog](https://github.com/mhenrixon/simplecov-oj/compare/v0.2...v0.18.0)
|
6
|
+
|
7
|
+
## [v0.2](https://github.com/mhenrixon/simplecov-oj/tree/v0.2) (2013-07-20)
|
8
|
+
|
9
|
+
[Full Changelog](https://github.com/mhenrixon/simplecov-oj/compare/aa3f4993ad39ba63229938d23ac2470b6f2cee3e...v0.2)
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2010-2020 Mikael Henriksson http://mhenrixon.com
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# simplecov-json
|
2
|
+
|
3
|
+
JSON formatter for the ruby 1.9+ code coverage gem SimpleCov
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
1. Add simplecov-json to your `Gemfile` and `bundle install`:
|
8
|
+
|
9
|
+
gem 'simplecov-json', :require => false, :group => :test
|
10
|
+
|
11
|
+
2. Require simplecov-json and set it up as SimpleCov's formatter:
|
12
|
+
|
13
|
+
require 'simplecov-json'
|
14
|
+
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
|
15
|
+
|
16
|
+
## Result
|
17
|
+
|
18
|
+
Generated JSON can be found in coverage/coverage.json
|
19
|
+
|
20
|
+
The format you can expect is:
|
21
|
+
```json
|
22
|
+
{
|
23
|
+
"timestamp": 1348489587,
|
24
|
+
"command_name": "RSpec",
|
25
|
+
"files": [
|
26
|
+
{
|
27
|
+
"filename": "/home/user/rails/environment.rb",
|
28
|
+
"covered_percent": 50.0,
|
29
|
+
"coverage": [
|
30
|
+
null,
|
31
|
+
1,
|
32
|
+
null,
|
33
|
+
null,
|
34
|
+
1
|
35
|
+
],
|
36
|
+
"covered_strength": 0.50,
|
37
|
+
"covered_lines": 2,
|
38
|
+
"lines_of_code": 4
|
39
|
+
},
|
40
|
+
...
|
41
|
+
],
|
42
|
+
"metrics": {
|
43
|
+
"covered_percent": 81.70731707317073,
|
44
|
+
"covered_strength": 0.8170731707317073,
|
45
|
+
"covered_lines": 67,
|
46
|
+
"total_lines": 82
|
47
|
+
}
|
48
|
+
}
|
49
|
+
```
|
50
|
+
|
51
|
+
## Making Contributions
|
52
|
+
|
53
|
+
If you want to contribute, please:
|
54
|
+
|
55
|
+
* Fork the project.
|
56
|
+
* Make your feature addition or bug fix.
|
57
|
+
* Add tests for it. This is important so I don't break it in a future version unintentionally.
|
58
|
+
* Send me a pull request on Github.
|
59
|
+
* Check that travis build passes for your pull request.
|
60
|
+
|
61
|
+
|
62
|
+
## Copyright
|
63
|
+
|
64
|
+
Copyright (c) 2013 Mikael Llongo. See LICENSE for details.
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# @see SimpleCov https://github.com/colszowka/simplecov
|
4
|
+
module SimpleCov
|
5
|
+
# @see SimpleCov::Formatter https://github.com/colszowka/simplecov
|
6
|
+
module Formatter
|
7
|
+
#
|
8
|
+
# Formats Simplecov Results into a json file `coverage.json`
|
9
|
+
#
|
10
|
+
# @author Mikael Henriksson <mikael@mhenrixon.se>
|
11
|
+
#
|
12
|
+
class OjFormatter
|
13
|
+
#
|
14
|
+
# @return [String] name of the file with coverage.json data
|
15
|
+
FILE_NAME = 'coverage.json'
|
16
|
+
|
17
|
+
#
|
18
|
+
# Formats the result as a hash, dump it to json with Oj and then save it to disk
|
19
|
+
#
|
20
|
+
# @param [SimpleCov::Result] result
|
21
|
+
#
|
22
|
+
# @return [<type>] <description>
|
23
|
+
#
|
24
|
+
def format(result)
|
25
|
+
json = dump_json(result)
|
26
|
+
puts SimpleCov::Oj::OutputMessage.new(result, output_filepath)
|
27
|
+
|
28
|
+
json
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# @private
|
34
|
+
def dump_json(result)
|
35
|
+
data = SimpleCov::Oj::ResultToHash.new(result).to_h
|
36
|
+
json = ::Oj.dump(data, mode: :compat)
|
37
|
+
|
38
|
+
File.open(output_filepath, 'w+') do |file|
|
39
|
+
file.puts json
|
40
|
+
end
|
41
|
+
|
42
|
+
json
|
43
|
+
end
|
44
|
+
|
45
|
+
# @private
|
46
|
+
def output_filepath
|
47
|
+
File.join(SimpleCov.coverage_path, FILE_NAME)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleCov
|
4
|
+
module Oj
|
5
|
+
#
|
6
|
+
# Generates a nicely formatted string about generated coverage
|
7
|
+
#
|
8
|
+
# @author Mikael Henriksson <mikael@mhenrixon.se>
|
9
|
+
#
|
10
|
+
class OutputMessage
|
11
|
+
#
|
12
|
+
# Initialize a new OutputMessage
|
13
|
+
#
|
14
|
+
# @param [SimplCov::Result] result the final simplecov result
|
15
|
+
# @param [String] output_filepath path to the filename
|
16
|
+
#
|
17
|
+
def initialize(result, output_filepath)
|
18
|
+
@result = result
|
19
|
+
@output_filepath = output_filepath
|
20
|
+
end
|
21
|
+
|
22
|
+
#
|
23
|
+
# Returns a nicely formatted string about the generated coverage data
|
24
|
+
#
|
25
|
+
#
|
26
|
+
# @return [String]
|
27
|
+
#
|
28
|
+
def to_s
|
29
|
+
'Coverage report generated' \
|
30
|
+
" for #{command_name}" \
|
31
|
+
" to #{output_filepath}." \
|
32
|
+
" #{covered_lines} / #{total_lines} LOC (#{covered_percent.round(2)}%) covered."
|
33
|
+
end
|
34
|
+
alias inspect to_s
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :result, :output_filepath
|
39
|
+
|
40
|
+
def command_name
|
41
|
+
result.command_name
|
42
|
+
end
|
43
|
+
|
44
|
+
def covered_lines
|
45
|
+
result.total_lines
|
46
|
+
end
|
47
|
+
|
48
|
+
def total_lines
|
49
|
+
result.total_lines
|
50
|
+
end
|
51
|
+
|
52
|
+
def covered_percent
|
53
|
+
result.covered_percent
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleCov
|
4
|
+
module Oj
|
5
|
+
#
|
6
|
+
# Massage result into a hash that can be dumped to json by OJ
|
7
|
+
#
|
8
|
+
# @author Mikael Henriksson <mikael@mhenrixon.se>
|
9
|
+
#
|
10
|
+
class ResultToHash
|
11
|
+
#
|
12
|
+
# Initialize a new ResultToHash
|
13
|
+
#
|
14
|
+
# @param [SimpleCov::Result] result the final result from simplecov
|
15
|
+
#
|
16
|
+
def initialize(result)
|
17
|
+
@result = result
|
18
|
+
@data = {
|
19
|
+
timestamp: result.created_at.to_i,
|
20
|
+
command_name: result.command_name,
|
21
|
+
files: []
|
22
|
+
}
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# Create a hash from the result that can be used for JSON dumping
|
27
|
+
#
|
28
|
+
#
|
29
|
+
# @return [Hash]
|
30
|
+
#
|
31
|
+
def to_h
|
32
|
+
extract_files
|
33
|
+
extract_metrics
|
34
|
+
data
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
attr_reader :result, :data
|
40
|
+
|
41
|
+
# @private
|
42
|
+
def extract_files
|
43
|
+
data[:files] = source_file_collection
|
44
|
+
end
|
45
|
+
|
46
|
+
# @private
|
47
|
+
def source_file_collection
|
48
|
+
result.files.each_with_object([]) do |source_file, memo|
|
49
|
+
next unless result.filenames.include?(source_file.filename)
|
50
|
+
|
51
|
+
memo << SourceFileWrapper.new(source_file).to_h
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# @private
|
56
|
+
def extract_metrics
|
57
|
+
data[:metrics] = ResultWrapper.new(result).to_h
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleCov
|
4
|
+
module Oj
|
5
|
+
#
|
6
|
+
# Representation of the simplecov result including it's coverage data, source code,
|
7
|
+
# source lines and featuring helpers to interpret that data.
|
8
|
+
#
|
9
|
+
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
10
|
+
#
|
11
|
+
class ResultWrapper
|
12
|
+
#
|
13
|
+
# Wrap the SimpleCov::Result to enable hash conversion without monkey patching
|
14
|
+
#
|
15
|
+
# @param [SimpleCov::Result] result the simplecov result to generate hash for
|
16
|
+
#
|
17
|
+
def initialize(result)
|
18
|
+
@result = result
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Returns a nicely formatted hash from the simplecov result data
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# @return [Hash]
|
26
|
+
#
|
27
|
+
def to_h
|
28
|
+
{
|
29
|
+
covered_percent: covered_percent,
|
30
|
+
covered_strength: covered_strength,
|
31
|
+
covered_lines: covered_lines,
|
32
|
+
total_lines: total_lines
|
33
|
+
}
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :result
|
39
|
+
|
40
|
+
# @private
|
41
|
+
def covered_strength
|
42
|
+
return 0.0 unless (coverage = result.covered_strength)
|
43
|
+
|
44
|
+
coverage.nan? ? 0.0 : coverage
|
45
|
+
end
|
46
|
+
|
47
|
+
# @private
|
48
|
+
def covered_percent
|
49
|
+
result.covered_percent
|
50
|
+
end
|
51
|
+
|
52
|
+
# @private
|
53
|
+
def covered_lines
|
54
|
+
result.covered_lines
|
55
|
+
end
|
56
|
+
|
57
|
+
# @private
|
58
|
+
def total_lines
|
59
|
+
result.total_lines
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,89 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleCov
|
4
|
+
module Oj
|
5
|
+
#
|
6
|
+
# Representation of a source file including it's coverage data, source code,
|
7
|
+
# source lines and featuring helpers to interpret that data.
|
8
|
+
#
|
9
|
+
# @author Mikael Henriksson <mikael@mhenrixon.com>
|
10
|
+
#
|
11
|
+
class SourceFileWrapper
|
12
|
+
#
|
13
|
+
# Wrap the SimpleCov::SourceFile to enable hash conversion without monkey patching
|
14
|
+
#
|
15
|
+
# @param [SimpleCov::SourceFile] source_file the source file to generate hash for
|
16
|
+
#
|
17
|
+
def initialize(source_file)
|
18
|
+
@source_file = source_file
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# Returns a nicely formatted hash from the source file data
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# @return [Hash]
|
26
|
+
#
|
27
|
+
def to_h
|
28
|
+
{ filename: filename,
|
29
|
+
covered_percent: covered_percent,
|
30
|
+
coverage: coverage_data,
|
31
|
+
covered_strength: covered_strength,
|
32
|
+
covered_lines: covered_lines_count,
|
33
|
+
lines_of_code: lines_of_code }
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
attr_reader :source_file
|
39
|
+
|
40
|
+
# @private
|
41
|
+
def coverage_data
|
42
|
+
return coverage if coverage.is_a?(Array)
|
43
|
+
|
44
|
+
coverage['lines']
|
45
|
+
end
|
46
|
+
|
47
|
+
def coverage
|
48
|
+
@coverage ||=
|
49
|
+
if SimpleCov::SourceFile.instance_methods.include?(:coverage_data)
|
50
|
+
source_file.coverage_data
|
51
|
+
else
|
52
|
+
source_file.coverage
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
# @private
|
57
|
+
def covered_lines
|
58
|
+
source_file.covered_lines
|
59
|
+
end
|
60
|
+
|
61
|
+
# @private
|
62
|
+
def covered_lines_count
|
63
|
+
covered_lines.count
|
64
|
+
end
|
65
|
+
|
66
|
+
# @private
|
67
|
+
def covered_percent
|
68
|
+
source_file.covered_percent
|
69
|
+
end
|
70
|
+
|
71
|
+
# @private
|
72
|
+
def covered_strength
|
73
|
+
return 0.0 unless (coverage = source_file.covered_strength)
|
74
|
+
|
75
|
+
coverage.nan? ? 0.0 : coverage
|
76
|
+
end
|
77
|
+
|
78
|
+
# @private
|
79
|
+
def filename
|
80
|
+
source_file.filename
|
81
|
+
end
|
82
|
+
|
83
|
+
# @private
|
84
|
+
def lines_of_code
|
85
|
+
source_file.lines_of_code
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SimpleCov
|
4
|
+
#
|
5
|
+
# Module Oj provides formatting of simplecov results as JSON using the oj gem
|
6
|
+
#
|
7
|
+
# @author Mikael Henriksson <mikael@zoolutions.se>
|
8
|
+
#
|
9
|
+
module Oj
|
10
|
+
#
|
11
|
+
# @return [String] the current version of the gem
|
12
|
+
VERSION = '0.18.3'
|
13
|
+
end
|
14
|
+
end
|
data/lib/simplecov-oj.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'simplecov'
|
4
|
+
require 'oj'
|
5
|
+
|
6
|
+
require 'simple_cov/oj/result_wrapper'
|
7
|
+
require 'simple_cov/oj/source_file_wrapper'
|
8
|
+
require 'simple_cov/oj/result_to_hash'
|
9
|
+
require 'simple_cov/oj/result_to_hash'
|
10
|
+
require 'simple_cov/oj/output_message'
|
11
|
+
require 'simple_cov/oj/version'
|
12
|
+
require 'simple_cov/formatter/oj_formatter'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
desc 'Generate a Changelog'
|
4
|
+
task :changelog do
|
5
|
+
# rubocop:disable Style/MutableConstant
|
6
|
+
CHANGELOG_CMD ||= %w[
|
7
|
+
github_changelog_generator
|
8
|
+
--no-verbose
|
9
|
+
--no-http-cache
|
10
|
+
--user
|
11
|
+
mhenrixon
|
12
|
+
--project
|
13
|
+
simplecov-oj
|
14
|
+
--token
|
15
|
+
]
|
16
|
+
ADD_CHANGELOG_CMD ||= 'git add --all'
|
17
|
+
COMMIT_CHANGELOG_CMD ||= "git commit -a -m 'Update changelog'"
|
18
|
+
# rubocop:enable Style/MutableConstant
|
19
|
+
|
20
|
+
sh('git checkout master')
|
21
|
+
sh(*CHANGELOG_CMD.push(ENV['CHANGELOG_GITHUB_TOKEN']))
|
22
|
+
sh(ADD_CHANGELOG_CMD)
|
23
|
+
sh(COMMIT_CHANGELOG_CMD)
|
24
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
RSpec.describe SimpleCov::Formatter::OjFormatter do
|
4
|
+
let(:formatter) { described_class.new }
|
5
|
+
let(:result) { instance_double(SimpleCov::Result) }
|
6
|
+
let(:command_name) { 'RSpec' }
|
7
|
+
let(:created_at) { Time.now.to_s }
|
8
|
+
let(:foo) { instance_double(SimpleCov::SourceFile) }
|
9
|
+
let(:foo_line_list) { instance_double(Array) }
|
10
|
+
let(:foo_coverage_data) { [1, nil, 0, 0, nil, 1, nil] }
|
11
|
+
let(:bar) { instance_double(SimpleCov::SourceFile) }
|
12
|
+
let(:bar_line_list) { instance_double(Array) }
|
13
|
+
let(:bar_coverage_data) { [nil, 1, nil, 1, 1, 1, 0, 0, nil, 1, nil] }
|
14
|
+
|
15
|
+
describe '#format' do
|
16
|
+
subject(:format) { formatter.format(result) }
|
17
|
+
|
18
|
+
let(:expected_hash) do
|
19
|
+
{
|
20
|
+
'timestamp' => created_at.to_i,
|
21
|
+
'command_name' => 'RSpec',
|
22
|
+
'files' => [
|
23
|
+
{ 'filename' => '/lib/foo.rb',
|
24
|
+
'covered_percent' => 50.0,
|
25
|
+
'coverage' => [1, nil, 0, 0, nil, 1, nil],
|
26
|
+
'covered_strength' => 0.50,
|
27
|
+
'covered_lines' => 2,
|
28
|
+
'lines_of_code' => 4 },
|
29
|
+
{ 'filename' => '/lib/bar.rb',
|
30
|
+
'covered_percent' => 71.42,
|
31
|
+
'coverage' => [nil, 1, nil, 1, 1, 1, 0, 0, nil, 1, nil],
|
32
|
+
'covered_strength' => 0.71,
|
33
|
+
'covered_lines' => 5,
|
34
|
+
'lines_of_code' => 7 }
|
35
|
+
],
|
36
|
+
'metrics' => {
|
37
|
+
'covered_percent' => 73.33,
|
38
|
+
'covered_strength' => 0.87,
|
39
|
+
'covered_lines' => 11,
|
40
|
+
'total_lines' => 15
|
41
|
+
}
|
42
|
+
}.to_json
|
43
|
+
end
|
44
|
+
|
45
|
+
before do
|
46
|
+
allow(result).to receive(:created_at).and_return(created_at)
|
47
|
+
allow(result).to receive(:command_name).and_return(command_name)
|
48
|
+
allow(result).to receive(:covered_lines).and_return(11)
|
49
|
+
allow(result).to receive(:covered_percent).and_return(73.33)
|
50
|
+
allow(result).to receive(:covered_strength).twice.and_return(0.87)
|
51
|
+
allow(result).to receive(:files).and_return([foo, bar])
|
52
|
+
allow(result).to receive(:filenames).twice.and_return(['/lib/foo.rb', '/lib/bar.rb'])
|
53
|
+
allow(result).to receive(:total_lines).and_return(15)
|
54
|
+
|
55
|
+
allow(foo).to receive(:filename).twice.and_return('/lib/foo.rb')
|
56
|
+
allow(foo).to receive(:covered_percent).and_return(50.0)
|
57
|
+
if SimpleCov::SourceFile.instance_methods.include?(:coverage_data)
|
58
|
+
allow(foo).to receive(:coverage_data).and_return(foo_coverage_data)
|
59
|
+
else
|
60
|
+
allow(foo).to receive(:coverage).and_return(foo_coverage_data)
|
61
|
+
end
|
62
|
+
allow(foo).to receive(:covered_strength).twice.and_return(0.50)
|
63
|
+
allow(foo).to receive(:covered_lines).and_return(foo_line_list)
|
64
|
+
allow(foo).to receive(:lines_of_code).and_return(4)
|
65
|
+
|
66
|
+
allow(foo_line_list).to receive(:count).and_return(2)
|
67
|
+
|
68
|
+
allow(bar).to receive(:filename).twice.and_return('/lib/bar.rb')
|
69
|
+
allow(bar).to receive(:covered_percent).and_return(71.42)
|
70
|
+
if SimpleCov::SourceFile.instance_methods.include?(:coverage_data)
|
71
|
+
allow(bar).to receive(:coverage_data).and_return(bar_coverage_data)
|
72
|
+
else
|
73
|
+
allow(bar).to receive(:coverage).and_return(bar_coverage_data)
|
74
|
+
end
|
75
|
+
allow(bar).to receive(:covered_strength).twice.and_return(0.71)
|
76
|
+
allow(bar).to receive(:covered_lines).and_return(bar_line_list)
|
77
|
+
allow(bar).to receive(:lines_of_code).and_return(7)
|
78
|
+
|
79
|
+
allow(bar_line_list).to receive(:count).and_return(5)
|
80
|
+
end
|
81
|
+
|
82
|
+
it { is_expected.to be_json_eql(expected_hash) }
|
83
|
+
|
84
|
+
context 'when coverage_data is a hash with the key `lines:`' do
|
85
|
+
let(:foo_coverage_data) { { lines: [1, nil, 0, 0, nil, 1, nil] } }
|
86
|
+
let(:bar_coverage_data) { { lines: [nil, 1, nil, 1, 1, 1, 0, 0, nil, 1, nil] } }
|
87
|
+
|
88
|
+
it { is_expected.to be_json_eql(expected_hash) }
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'simplecov'
|
5
|
+
|
6
|
+
require 'pry'
|
7
|
+
require 'rspec'
|
8
|
+
require 'json_spec'
|
9
|
+
|
10
|
+
require 'simplecov-oj'
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
config.include JsonSpec::Helpers
|
14
|
+
end
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.define_derived_metadata do |meta|
|
18
|
+
meta[:aggregate_failures] = true
|
19
|
+
end
|
20
|
+
|
21
|
+
config.expect_with :rspec do |expectations|
|
22
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
23
|
+
end
|
24
|
+
|
25
|
+
config.mock_with :rspec do |mocks|
|
26
|
+
mocks.verify_partial_doubles = true
|
27
|
+
end
|
28
|
+
|
29
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
30
|
+
config.filter_run_when_matching :focus
|
31
|
+
config.example_status_persistence_file_path = 'spec/.rspec-status'
|
32
|
+
config.disable_monkey_patching!
|
33
|
+
config.warnings = true
|
34
|
+
config.default_formatter = 'doc' if config.files_to_run.one?
|
35
|
+
config.profile_examples = 10
|
36
|
+
config.order = :random
|
37
|
+
|
38
|
+
Kernel.srand config.seed
|
39
|
+
end
|
40
|
+
|
41
|
+
RSpec::Support::ObjectFormatter.default_instance.max_formatted_output_length = 10_000
|
metadata
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplecov-oj
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.18.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Mikael Henriksson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-02-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: oj
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '5.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.0'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '5.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: simplecov
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0.14'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.0'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - "~>"
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0.14'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '1.0'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: appraisal
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
name: bundler
|
69
|
+
requirement: !ruby/object:Gem::Requirement
|
70
|
+
requirements:
|
71
|
+
- - "~>"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '2.1'
|
74
|
+
type: :development
|
75
|
+
prerelease: false
|
76
|
+
version_requirements: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - "~>"
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '2.1'
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
name: gem-release
|
83
|
+
requirement: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - "~>"
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '2.0'
|
88
|
+
type: :development
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - "~>"
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '2.0'
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
name: json_spec
|
97
|
+
requirement: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
- !ruby/object:Gem::Dependency
|
110
|
+
name: rake
|
111
|
+
requirement: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - "~>"
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '13.0'
|
116
|
+
type: :development
|
117
|
+
prerelease: false
|
118
|
+
version_requirements: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - "~>"
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: '13.0'
|
123
|
+
- !ruby/object:Gem::Dependency
|
124
|
+
name: rspec
|
125
|
+
requirement: !ruby/object:Gem::Requirement
|
126
|
+
requirements:
|
127
|
+
- - "~>"
|
128
|
+
- !ruby/object:Gem::Version
|
129
|
+
version: '3.9'
|
130
|
+
type: :development
|
131
|
+
prerelease: false
|
132
|
+
version_requirements: !ruby/object:Gem::Requirement
|
133
|
+
requirements:
|
134
|
+
- - "~>"
|
135
|
+
- !ruby/object:Gem::Version
|
136
|
+
version: '3.9'
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: simplecov-json
|
139
|
+
requirement: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - ">="
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
type: :development
|
145
|
+
prerelease: false
|
146
|
+
version_requirements: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
- !ruby/object:Gem::Dependency
|
152
|
+
name: github-markup
|
153
|
+
requirement: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - "~>"
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '3.0'
|
158
|
+
type: :development
|
159
|
+
prerelease: false
|
160
|
+
version_requirements: !ruby/object:Gem::Requirement
|
161
|
+
requirements:
|
162
|
+
- - "~>"
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '3.0'
|
165
|
+
- !ruby/object:Gem::Dependency
|
166
|
+
name: github_changelog_generator
|
167
|
+
requirement: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - "~>"
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '1.14'
|
172
|
+
type: :development
|
173
|
+
prerelease: false
|
174
|
+
version_requirements: !ruby/object:Gem::Requirement
|
175
|
+
requirements:
|
176
|
+
- - "~>"
|
177
|
+
- !ruby/object:Gem::Version
|
178
|
+
version: '1.14'
|
179
|
+
- !ruby/object:Gem::Dependency
|
180
|
+
name: yard
|
181
|
+
requirement: !ruby/object:Gem::Requirement
|
182
|
+
requirements:
|
183
|
+
- - "~>"
|
184
|
+
- !ruby/object:Gem::Version
|
185
|
+
version: '0.9'
|
186
|
+
type: :development
|
187
|
+
prerelease: false
|
188
|
+
version_requirements: !ruby/object:Gem::Requirement
|
189
|
+
requirements:
|
190
|
+
- - "~>"
|
191
|
+
- !ruby/object:Gem::Version
|
192
|
+
version: '0.9'
|
193
|
+
description: 'Oj formatter for SimpleCov code coverage tool for ruby 2.4+
|
194
|
+
|
195
|
+
'
|
196
|
+
email:
|
197
|
+
- mikael@mhenrixon.com
|
198
|
+
executables: []
|
199
|
+
extensions: []
|
200
|
+
extra_rdoc_files: []
|
201
|
+
files:
|
202
|
+
- CHANGELOG.md
|
203
|
+
- LICENSE
|
204
|
+
- README.md
|
205
|
+
- lib/simple_cov/formatter/oj_formatter.rb
|
206
|
+
- lib/simple_cov/oj/output_message.rb
|
207
|
+
- lib/simple_cov/oj/result_to_hash.rb
|
208
|
+
- lib/simple_cov/oj/result_wrapper.rb
|
209
|
+
- lib/simple_cov/oj/source_file_wrapper.rb
|
210
|
+
- lib/simple_cov/oj/version.rb
|
211
|
+
- lib/simplecov-oj.rb
|
212
|
+
- lib/tasks/changelog.rake
|
213
|
+
- spec/simple_cov/formatter/oj_formatter_spec.rb
|
214
|
+
- spec/spec_helper.rb
|
215
|
+
homepage: https://github.com/mhenrixon/simplecov-oj
|
216
|
+
licenses:
|
217
|
+
- MIT
|
218
|
+
metadata:
|
219
|
+
homepage_uri: https://github.com/mhenrixon/simplecov-oj
|
220
|
+
bug_tracker_uri: https://github.com/mhenrixon/mhenrixon/issues
|
221
|
+
documentation_uri: https://mhenrixon.github.io/simplecov-oj
|
222
|
+
source_code_uri: https://github.com/mhenrixon/simplecov-oj
|
223
|
+
changelog_uri: https://github.com/mhenrixon/simplecov-oj/CHANGELOG.md
|
224
|
+
post_install_message:
|
225
|
+
rdoc_options: []
|
226
|
+
require_paths:
|
227
|
+
- lib
|
228
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
229
|
+
requirements:
|
230
|
+
- - ">="
|
231
|
+
- !ruby/object:Gem::Version
|
232
|
+
version: '0'
|
233
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
234
|
+
requirements:
|
235
|
+
- - ">="
|
236
|
+
- !ruby/object:Gem::Version
|
237
|
+
version: '0'
|
238
|
+
requirements: []
|
239
|
+
rubygems_version: 3.1.2
|
240
|
+
signing_key:
|
241
|
+
specification_version: 4
|
242
|
+
summary: Oj formatter for SimpleCov code coverage tool for ruby 2.4+
|
243
|
+
test_files:
|
244
|
+
- spec/spec_helper.rb
|
245
|
+
- spec/simple_cov/formatter/oj_formatter_spec.rb
|