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 8cd7513

Browse files
author
Federico Moya
committed
Consder converage's branch method disable
1 parent f951119 commit 8cd7513

File tree

5 files changed

+66
-10
lines changed

5 files changed

+66
-10
lines changed

‎lib/simplecov_json_formatter/source_file_formatter.rb

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,27 @@ def initialize(source_file)
77
end
88

99
def format
10+
if SimpleCov.branch_coverage?
11+
line_coverage.merge(branch_coverage)
12+
else
13+
line_coverage
14+
end
15+
end
16+
17+
private
18+
19+
def line_coverage
20+
@line_coverage || {
21+
lines: lines
22+
}
23+
end
24+
25+
def branch_coverage
1026
{
11-
lines: lines,
1227
branches: branches
1328
}
1429
end
1530

16-
private
17-
1831
def lines
1932
lines = []
2033
@source_file.lines.each do |line|

‎spec/fixtures/sample.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
"ignored",
2222
"ignored",
2323
null
24-
],
25-
"branches": [
26-
2724
]
2825
}
2926
}

‎spec/fixtures/sample_with_branch.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"meta": {
3+
"simplecov_version": "0.18.5"
4+
},
5+
"coverage": {
6+
"/gem/spec/fixtures/sample.rb": {
7+
"lines": [
8+
null,
9+
1,
10+
1,
11+
1,
12+
null,
13+
null,
14+
1,
15+
1,
16+
null,
17+
null,
18+
"ignored",
19+
"ignored",
20+
"ignored",
21+
"ignored",
22+
"ignored",
23+
null
24+
],
25+
"branches": [
26+
27+
]
28+
}
29+
}
30+
}

‎spec/simplecov_json_formatter_spec.rb

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# frozen_string_literal: true
22

33
require 'spec_helper'
4-
require 'byebug'
54

65
describe SimpleCov::Formatter::JSONFormatter do
76
let(:result) do
@@ -11,9 +10,22 @@
1110
end
1211

1312
describe 'format' do
14-
it 'works' do
15-
subject.format(result)
16-
expect(json_ouput).to eq(json_result('sample'))
13+
context 'whit line coverage' do
14+
it 'works' do
15+
subject.format(result)
16+
expect(json_ouput).to eq(json_result('sample'))
17+
end
18+
end
19+
20+
context 'whit branch coverage' do
21+
before do
22+
enable_branch_coverage
23+
end
24+
25+
it 'works' do
26+
subject.format(result)
27+
expect(json_ouput).to eq(json_result('sample_with_branch'))
28+
end
1729
end
1830
end
1931
end

‎spec/spec_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
SimpleCov.coverage_dir('tmp/coverage')
88

9+
def enable_branch_coverage
10+
allow(SimpleCov).to receive(:branch_coverage?).and_return(true)
11+
end
12+
913
def source_fixture(filename)
1014
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', filename))
1115
end

0 commit comments

Comments
(0)

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