simplecov-json 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simplecov-json.rb +49 -0
- data/test/helper.rb +10 -0
- data/test/test_simplecov_json.rb +46 -0
- metadata +72 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
class SimpleCov::Formatter::JSONFormatter
|
5
|
+
def format(result)
|
6
|
+
puts result.inspect
|
7
|
+
data = {}
|
8
|
+
data[:timestamp] = result.created_at.to_i
|
9
|
+
data[:command_name] = result.command_name
|
10
|
+
data[:files] = []
|
11
|
+
result.original_result.each do |filename,coverage|
|
12
|
+
next unless result.filenames.include? filename
|
13
|
+
data[:files] << {
|
14
|
+
filename: filename,
|
15
|
+
coverage: coverage,
|
16
|
+
}
|
17
|
+
end
|
18
|
+
data[:groups] = result.groups
|
19
|
+
data[:metrics] = {
|
20
|
+
covered_percent: result.covered_percent,
|
21
|
+
covered_strength: result.covered_strength,
|
22
|
+
covered_lines: result.covered_lines,
|
23
|
+
total_lines: result.total_lines,
|
24
|
+
}
|
25
|
+
File.open(File.join(output_path, output_filename), "w+") do |file|
|
26
|
+
file.puts data.to_json
|
27
|
+
end
|
28
|
+
puts output_message(result)
|
29
|
+
data.to_json
|
30
|
+
end
|
31
|
+
|
32
|
+
def output_filename
|
33
|
+
'coverage.json'
|
34
|
+
end
|
35
|
+
|
36
|
+
def output_filepath
|
37
|
+
File.join(output_path, output_filename)
|
38
|
+
end
|
39
|
+
|
40
|
+
def output_message(result)
|
41
|
+
"Coverage report generated for #{result.command_name} to #{output_filepath}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def output_path
|
47
|
+
SimpleCov.coverage_path
|
48
|
+
end
|
49
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestSimpleCovHtml < Test::Unit::TestCase
|
4
|
+
def test_format
|
5
|
+
formatter = SimpleCov::Formatter::JSONFormatter.new
|
6
|
+
result = mock()
|
7
|
+
created_at = DateTime.now.to_s
|
8
|
+
|
9
|
+
result.expects(:created_at).returns(created_at)
|
10
|
+
result.expects(:command_name).returns('RSpec')
|
11
|
+
result.expects(:original_result).returns({
|
12
|
+
'/lib/foo.rb' => [1, nil, 0, 0, nil, 1, nil],
|
13
|
+
'/lib/bar.rb' => [nil, 1, nil, 1, 1, 1, 0, 0, nil, 1, nil],
|
14
|
+
'/test/test.rb' => [nil, 1, 1, 1, 1]
|
15
|
+
})
|
16
|
+
result.expects(:filenames).returns(['/lib/foo.rb', '/lib/bar.rb'])
|
17
|
+
result.expects(:filenames).returns(['/lib/foo.rb', '/lib/bar.rb'])
|
18
|
+
result.expects(:filenames).returns(['/lib/foo.rb', '/lib/bar.rb'])
|
19
|
+
result.expects(:groups).returns(['controllers', 'models'])
|
20
|
+
result.expects(:covered_percent).returns(73.33)
|
21
|
+
result.expects(:covered_strength).returns(0.87)
|
22
|
+
result.expects(:covered_lines).returns(11)
|
23
|
+
result.expects(:total_lines).returns(15)
|
24
|
+
|
25
|
+
result.expects(:command_name).returns('RSpec')
|
26
|
+
result.expects(:covered_lines).returns(11)
|
27
|
+
result.expects(:total_lines).returns(15)
|
28
|
+
result.expects(:covered_percent).returns(73.33)
|
29
|
+
|
30
|
+
assert_equal(formatter.format(result), {
|
31
|
+
'timestamp' => created_at.to_i,
|
32
|
+
'command_name' => 'RSpec',
|
33
|
+
'files' => [
|
34
|
+
{'filename' => '/lib/foo.rb', 'coverage' => [1, nil, 0, 0, nil, 1, nil]},
|
35
|
+
{'filename' => '/lib/bar.rb', 'coverage' => [nil, 1, nil, 1, 1, 1, 0, 0, nil, 1, nil]},
|
36
|
+
],
|
37
|
+
'groups' =>['controllers', 'models'],
|
38
|
+
'metrics' => {
|
39
|
+
'covered_percent' => 73.33,
|
40
|
+
'covered_strength' => 0.87,
|
41
|
+
'covered_lines' => 11,
|
42
|
+
'total_lines' => 15,
|
43
|
+
}
|
44
|
+
}.to_json)
|
45
|
+
end
|
46
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplecov-json
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vicent Llongo
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: simplecov
|
16
|
+
requirement: &18020520 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *18020520
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: json
|
27
|
+
requirement: &18019880 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *18019880
|
36
|
+
description: JSON formatter for SimpleCov code coverage tool for ruby 1.9+
|
37
|
+
email:
|
38
|
+
- villosil@gmail.com
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- lib/simplecov-json.rb
|
44
|
+
- test/helper.rb
|
45
|
+
- test/test_simplecov_json.rb
|
46
|
+
homepage: https://github.com/vicentllongo/simplecov-json
|
47
|
+
licenses: []
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
require_paths:
|
51
|
+
- lib
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ! '>='
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
58
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
59
|
+
none: false
|
60
|
+
requirements:
|
61
|
+
- - ! '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project: simplecov-json
|
66
|
+
rubygems_version: 1.8.10
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: JSON formatter for SimpleCov code coverage tool for ruby 1.9+
|
70
|
+
test_files:
|
71
|
+
- test/helper.rb
|
72
|
+
- test/test_simplecov_json.rb
|