Skip to content

Commit 255214d

Browse files
author
Federico Moya
committed
Improve tests
1 parent 8cd7513 commit 255214d

File tree

6 files changed

+74
-4
lines changed

6 files changed

+74
-4
lines changed

.rubocop.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ AllCops:
55

66
Style/Documentation:
77
Enabled: false
8+
9+
Metrics/BlockLength:
10+
Exclude:
11+
- 'spec/**/*'

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM ruby:2.4
1+
FROM ruby:2.5
22

33
WORKDIR /gem
44

spec/fixtures/sample.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@
99
1,
1010
1,
1111
1,
12+
1,
13+
null,
14+
null,
15+
1,
16+
1,
1217
null,
1318
null,
1419
1,
1520
1,
21+
0,
22+
null,
23+
1,
24+
null,
1625
null,
1726
null,
1827
"ignored",

spec/fixtures/sample.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
# Foo class
22
class Foo
33
def initialize
4-
@foo = "baz"
4+
@foo = 'bar'
5+
@bar = 'foo'
56
end
67

78
def bar
89
@foo
910
end
1011

12+
def foo(param)
13+
if param
14+
@bar
15+
else
16+
@foo
17+
end
18+
end
19+
1120
#:nocov:
1221
def skipped
1322
@foo * 2

spec/fixtures/sample_with_branch.json

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,19 @@
99
1,
1010
1,
1111
1,
12+
1,
13+
null,
14+
null,
15+
1,
16+
1,
1217
null,
1318
null,
1419
1,
1520
1,
21+
0,
22+
null,
23+
1,
24+
null,
1625
null,
1726
null,
1827
"ignored",
@@ -23,7 +32,18 @@
2332
null
2433
],
2534
"branches": [
26-
35+
{
36+
"type": "then",
37+
"start_line": 14,
38+
"end_line": 14,
39+
"coverage": 0
40+
},
41+
{
42+
"type": "else",
43+
"start_line": 16,
44+
"end_line": 16,
45+
"coverage": 1
46+
}
2747
]
2848
}
2949
}

spec/simplecov_json_formatter_spec.rb

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# frozen_string_literal: true
22

33
require 'spec_helper'
4+
require 'byebug'
45

56
describe SimpleCov::Formatter::JSONFormatter do
67
let(:result) do
78
SimpleCov::Result.new({
8-
source_fixture('sample.rb') => { 'lines' => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil] }
9+
source_fixture('sample.rb') => { 'lines' => [
10+
nil, 1, 1, 1, 1, nil, nil, 1, 1, nil, nil,
11+
1, 1, 0, nil, 1, nil, nil, nil, nil, 1, 0, nil, nil, nil
12+
] }
913
})
1014
end
1115

@@ -18,6 +22,30 @@
1822
end
1923

2024
context 'whit branch coverage' do
25+
let(:original_lines) do
26+
[nil, 1, 1, 1, 1, nil, nil, 1, 1,
27+
nil, nil, 1, 1, 0, nil, 1, nil,
28+
nil, nil, nil, 1, 0, nil, nil, nil]
29+
end
30+
31+
let(:original_branches) do
32+
{
33+
[:if, 0, 13, 4, 17, 7] => {
34+
[:then, 1, 14, 6, 14, 10] => 0,
35+
[:else, 2, 16, 6, 16, 10] => 1
36+
}
37+
}
38+
end
39+
40+
let(:result) do
41+
SimpleCov::Result.new({
42+
source_fixture('sample.rb') => {
43+
'lines' => original_lines,
44+
'branches' => original_branches
45+
}
46+
})
47+
end
48+
2149
before do
2250
enable_branch_coverage
2351
end

0 commit comments

Comments
 (0)