Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5cfb07f

Browse files
authored
Group support (#2)
* small README formatting fix * Make tests run independent of work directory Nicer dev experience, to avoid using docker for a relatively simple gem. * fix typos * run against newest SimpleCov * Report groups overall coverage percentage * Accomodate for multiple coverage types * force ci * rubocop autofix * ah missed on instance of paths
1 parent 6302299 commit 5cfb07f

File tree

8 files changed

+116
-22
lines changed

8 files changed

+116
-22
lines changed

‎Gemfile.lock

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ GEM
44
ast (2.4.1)
55
byebug (11.1.3)
66
diff-lcs (1.4.4)
7-
docile (1.3.2)
7+
docile (1.4.0)
88
parallel (1.19.2)
99
parser (2.7.1.4)
1010
ast (~> 2.4.1)
@@ -37,10 +37,12 @@ GEM
3737
rubocop-ast (0.3.0)
3838
parser (>= 2.7.1.4)
3939
ruby-progressbar (1.10.1)
40-
simplecov (0.18.5)
40+
simplecov (0.21.2)
4141
docile (~> 1.1)
4242
simplecov-html (~> 0.11)
43-
simplecov-html (0.12.2)
43+
simplecov_json_formatter (~> 0.1)
44+
simplecov-html (0.12.3)
45+
simplecov_json_formatter (0.1.3)
4446
unicode-display_width (1.7.0)
4547

4648
PLATFORMS
@@ -54,4 +56,4 @@ DEPENDENCIES
5456
simplecov (~> 0.18)
5557

5658
BUNDLED WITH
57-
2.1.0
59+
2.3.4

‎README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
***Note: To learn more about SimpleCov, check out the main repo at [https://github.com/simplecov-ruby/simplecov](https://github.com/colszowka/simplecov***)***
44

5-
Generates a formatted JSON report of your [SimpleCov](https://github.com/simplecov-ruby/simplecov) ruby code coverage results on ruby 2.4+. Originally intended to add `simplecov`'s results reading capacity to CI tools.
5+
Generates a formatted JSON report of your [SimpleCov](https://github.com/simplecov-ruby/simplecov) ruby code coverage results on ruby 2.4+. Originally intended to add `simplecov`'s results reading capacity to CI tools.
66

77
## Overview
88

9-
You can expect for this gem to produce a `coverage.json` file, located at the `coverage` folder.
9+
You can expect for this gem to produce a `coverage.json` file, located at the `coverage` folder.
1010

1111
Depending on your `SimpleCoV`'s settings you will experiment different outcomes. Particularly depending on which type of coverage are you running `SimpleCov` with:
1212

@@ -15,13 +15,14 @@ Depending on your `SimpleCoV`'s settings you will experiment different outcomes.
1515

1616
## Development
1717

18-
We encourage you to use docker for common operations like running tests, or debugging your code. Running `make sh` will start a new container instance based on the `Dockerfile` provided at root, finally a shell prompt will be displayed on your terminal. Also, syncronization with your local files will be already set.
18+
We encourage you to use docker for common operations like running tests, or debugging your code. Running `make sh` will start a new container instance based on the `Dockerfile` provided at root, finally a shell prompt will be displayed on your terminal. Also, syncronization with your local files will be already set.
19+
1920
### Tests
2021
`make test` will trigger the excution of both running tests and running rubocop as linter, by simply running `rake`, this actions will be run inside a new container but using your local files.
2122

2223
### Format
2324

24-
`make format` will run `rubocop -a` which stands for _autocorrect_ and format your code according to the `.rubocop.yml` config file.
25+
`make format` will run `rubocop -a` which stands for _autocorrect_ and format your code according to the `.rubocop.yml` config file.
2526

2627
## Copyright
2728

‎lib/simplecov_json_formatter/result_hash_formatter.rb

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,38 @@ def initialize(result)
99
end
1010

1111
def format
12+
format_files
13+
format_groups
14+
15+
formatted_result
16+
end
17+
18+
private
19+
20+
def format_files
1221
@result.files.each do |source_file|
1322
formatted_result[:coverage][source_file.filename] =
1423
format_source_file(source_file)
1524
end
16-
17-
formatted_result
1825
end
1926

20-
private
27+
def format_groups
28+
@result.groups.each do |name, file_list|
29+
formatted_result[:groups][name] = {
30+
lines: {
31+
covered_percent: file_list.covered_percent
32+
}
33+
}
34+
end
35+
end
2136

2237
def formatted_result
2338
@formatted_result ||= {
2439
meta: {
2540
simplecov_version: SimpleCov::VERSION
2641
},
27-
coverage: {}
42+
coverage: {},
43+
groups: {}
2844
}
2945
end
3046

‎spec/fixtures/sample.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"meta": {
3-
"simplecov_version": "0.18.5"
3+
"simplecov_version": "0.21.2"
44
},
55
"coverage": {
6-
"/gem/spec/fixtures/sample.rb": {
6+
"/STUB_WORKING_DIRECTORY/spec/fixtures/sample.rb": {
77
"lines": [
88
null,
99
1,
@@ -32,5 +32,6 @@
3232
null
3333
]
3434
}
35-
}
36-
}
35+
},
36+
"groups": {}
37+
}

‎spec/fixtures/sample_groups.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"meta": {
3+
"simplecov_version": "0.21.2"
4+
},
5+
"coverage": {
6+
"/STUB_WORKING_DIRECTORY/spec/fixtures/sample.rb": {
7+
"lines": [
8+
null,
9+
1,
10+
1,
11+
1,
12+
1,
13+
null,
14+
null,
15+
1,
16+
1,
17+
null,
18+
null,
19+
1,
20+
1,
21+
0,
22+
null,
23+
1,
24+
null,
25+
null,
26+
null,
27+
"ignored",
28+
"ignored",
29+
"ignored",
30+
"ignored",
31+
"ignored",
32+
null
33+
]
34+
}
35+
},
36+
"groups": {
37+
"My Group": {
38+
"lines": {
39+
"covered_percent": 80.0
40+
}
41+
}
42+
}
43+
}

‎spec/fixtures/sample_with_branch.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"meta": {
3-
"simplecov_version": "0.18.5"
3+
"simplecov_version": "0.21.2"
44
},
55
"coverage": {
6-
"/gem/spec/fixtures/sample.rb": {
6+
"/STUB_WORKING_DIRECTORY/spec/fixtures/sample.rb": {
77
"lines": [
88
null,
99
1,
@@ -46,5 +46,6 @@
4646
}
4747
]
4848
}
49-
}
50-
}
49+
},
50+
"groups": {}
51+
}

‎spec/simplecov_json_formatter_spec.rb

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
end
1515

1616
describe 'format' do
17-
context 'whit line coverage' do
17+
context 'with line coverage' do
1818
it 'works' do
1919
subject.format(result)
2020
expect(json_ouput).to eq(json_result('sample'))
2121
end
2222
end
2323

24-
context 'whit branch coverage' do
24+
context 'with branch coverage' do
2525
let(:original_lines) do
2626
[nil, 1, 1, 1, 1, nil, nil, 1, 1,
2727
nil, nil, 1, 1, 0, nil, 1, nil,
@@ -55,5 +55,26 @@
5555
expect(json_ouput).to eq(json_result('sample_with_branch'))
5656
end
5757
end
58+
59+
context 'with groups' do
60+
let(:result) do
61+
res = SimpleCov::Result.new({
62+
source_fixture('sample.rb') => { 'lines' => [
63+
nil, 1, 1, 1, 1, nil, nil, 1, 1, nil, nil,
64+
1, 1, 0, nil, 1, nil, nil, nil, nil, 1, 0, nil, nil, nil
65+
] }
66+
})
67+
68+
# right now SimpleCov works mostly on global state, hence setting the groups that way
69+
# would be global state --> Mocking is better here
70+
allow(res).to receive_messages(groups: { 'My Group' => double('File List', covered_percent: 80.0) })
71+
res
72+
end
73+
74+
it 'displays groups correctly in the JSON' do
75+
subject.format(result)
76+
expect(json_ouput).to eq(json_result('sample_groups'))
77+
end
78+
end
5879
end
5980
end

‎spec/spec_helper.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,14 @@ def json_ouput
2020

2121
def json_result(filename)
2222
file = File.read(source_fixture("#{filename}.json"))
23+
file = use_current_working_directory(file)
2324
JSON.parse(file)
2425
end
26+
27+
DEFAULT_WORKING_DIRECTORY = 'STUB_WORKING_DIRECTORY'
28+
def use_current_working_directory(file)
29+
current_working_directory = File.expand_path('..', File.dirname(__FILE__))
30+
file.gsub!("/#{DEFAULT_WORKING_DIRECTORY}/", "#{current_working_directory}/")
31+
32+
file
33+
end

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /