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 f951119

Browse files
author
Federico Moya
committed
Add first specs
1 parent 130dc91 commit f951119

File tree

12 files changed

+123
-24
lines changed

12 files changed

+123
-24
lines changed

‎.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.byebug_history
2+
tmp
3+

‎.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
AllCops:
2+
Exclude:
3+
- 'spec/fixtures/**/*'
24
TargetRubyVersion: 2.4
35

46
Style/Documentation:

‎Gemfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ source 'https://rubygems.org'
55
group :development do
66
gem 'byebug'
77
gem 'rake', '~> 12.0'
8+
gem 'rspec', '~> 3.2'
89
gem 'rubocop'
9-
gem 'test-unit'
10+
end
11+
12+
group :test do
13+
gem 'simplecov', '~> 0.18'
1014
end

‎Gemfile.lock

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,28 @@ GEM
33
specs:
44
ast (2.4.1)
55
byebug (11.1.3)
6+
diff-lcs (1.4.4)
7+
docile (1.3.2)
68
parallel (1.19.2)
79
parser (2.7.1.4)
810
ast (~> 2.4.1)
9-
power_assert (1.2.0)
1011
rainbow (3.0.0)
1112
rake (12.3.3)
1213
regexp_parser (1.7.1)
1314
rexml (3.2.4)
15+
rspec (3.9.0)
16+
rspec-core (~> 3.9.0)
17+
rspec-expectations (~> 3.9.0)
18+
rspec-mocks (~> 3.9.0)
19+
rspec-core (3.9.2)
20+
rspec-support (~> 3.9.3)
21+
rspec-expectations (3.9.2)
22+
diff-lcs (>= 1.2.0, < 2.0)
23+
rspec-support (~> 3.9.0)
24+
rspec-mocks (3.9.1)
25+
diff-lcs (>= 1.2.0, < 2.0)
26+
rspec-support (~> 3.9.0)
27+
rspec-support (3.9.3)
1428
rubocop (0.89.1)
1529
parallel (~> 1.10)
1630
parser (>= 2.7.1.1)
@@ -23,8 +37,10 @@ GEM
2337
rubocop-ast (0.3.0)
2438
parser (>= 2.7.1.4)
2539
ruby-progressbar (1.10.1)
26-
test-unit (3.3.6)
27-
power_assert
40+
simplecov (0.18.5)
41+
docile (~> 1.1)
42+
simplecov-html (~> 0.11)
43+
simplecov-html (0.12.2)
2844
unicode-display_width (1.7.0)
2945

3046
PLATFORMS
@@ -33,8 +49,9 @@ PLATFORMS
3349
DEPENDENCIES
3450
byebug
3551
rake (~> 12.0)
52+
rspec (~> 3.2)
3653
rubocop
37-
test-unit
54+
simplecov (~>0.18)
3855

3956
BUNDLED WITH
4057
2.1.0

‎Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
.PHONY: image test sh
1+
.PHONY: image test format sh
22

33
image:
44
docker image build -t simplecov-json-formatter .
55

66
test:
77
./bin/run-image rake
88

9+
format:
10+
./bin/run-image rubocop -a
11+
912
sh:
1013
./bin/run-image sh
1114

‎Rakefile

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
require 'bundler/setup'
44
require 'rake/testtask'
5+
require 'rspec/core/rake_task'
56

6-
Rake::TestTask.new(:test) do |t|
7-
t.libs << 'test'
8-
t.libs << 'lib'
9-
t.test_files = FileList['test/**/*_test.rb']
10-
end
7+
RSpec::Core::RakeTask.new(:spec)
118

129
begin
1310
require 'rubocop/rake_task'
@@ -18,4 +15,4 @@ rescue LoadError
1815
end
1916
end
2017

21-
task default: %i[rubocop test]
18+
task default: %i[rubocop spec]

‎spec/fixtures/sample.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/fixtures/sample.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Foo class
2+
class Foo
3+
def initialize
4+
@foo = "baz"
5+
end
6+
7+
def bar
8+
@foo
9+
end
10+
11+
#:nocov:
12+
def skipped
13+
@foo * 2
14+
end
15+
#:nocov:
16+
end

‎spec/simplecov_json_formatter_spec.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
require 'byebug'
5+
6+
describe SimpleCov::Formatter::JSONFormatter do
7+
let(:result) do
8+
SimpleCov::Result.new({
9+
source_fixture('sample.rb') => { 'lines' => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil] }
10+
})
11+
end
12+
13+
describe 'format' do
14+
it 'works' do
15+
subject.format(result)
16+
expect(json_ouput).to eq(json_result('sample'))
17+
end
18+
end
19+
end

‎spec/spec_helper.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
require 'rspec'
4+
require 'simplecov'
5+
require 'simplecov_json_formatter'
6+
7+
SimpleCov.coverage_dir('tmp/coverage')
8+
9+
def source_fixture(filename)
10+
File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', filename))
11+
end
12+
13+
def json_ouput
14+
JSON.parse(File.read('tmp/coverage/coverage.json'))
15+
end
16+
17+
def json_result(filename)
18+
file = File.read(source_fixture("#{filename}.json"))
19+
JSON.parse(file)
20+
end

0 commit comments

Comments
(0)

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