simplecov-json 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,48 +2,57 @@ require 'simplecov'
2
2
  require 'json'
3
3
 
4
4
  class SimpleCov::Formatter::JSONFormatter
5
+
5
6
  def format(result)
6
- puts result.inspect
7
7
  data = {}
8
8
  data[:timestamp] = result.created_at.to_i
9
9
  data[:command_name] = result.command_name
10
10
  data[:files] = []
11
- result.original_result.each do |filename,coverage|
12
- next unless result.filenames.include? filename
11
+ result.files.each do |sourceFile|
12
+ next unless result.filenames.include? sourceFile.filename
13
13
  data[:files] << {
14
- filename: filename,
15
- coverage: coverage,
14
+ filename: sourceFile.filename,
15
+ covered_percent: sourceFile.covered_percent,
16
+ coverage: sourceFile.coverage,
17
+ covered_strength: sourceFile.covered_strength.nan? ? 0.0 : sourceFile.covered_strength,
18
+ covered_lines: sourceFile.covered_lines.count,
19
+ lines_of_code: sourceFile.lines_of_code,
16
20
  }
17
21
  end
18
- data[:groups] = result.groups
19
22
  data[:metrics] = {
20
23
  covered_percent: result.covered_percent,
21
- covered_strength: result.covered_strength,
24
+ covered_strength: result.covered_strength.nan? ? 0.0 : result.covered_strength,
22
25
  covered_lines: result.covered_lines,
23
- total_lines: result.total_lines,
26
+ total_lines: result.total_lines
24
27
  }
25
- File.open(File.join(output_path, output_filename), "w+") do |file|
26
- file.puts data.to_json
28
+
29
+ json = data.to_json
30
+
31
+ File.open(output_filepath, "w+") do |file|
32
+ file.puts json
27
33
  end
34
+
28
35
  puts output_message(result)
29
- data.to_json
36
+
37
+ json
30
38
  end
31
-
39
+
32
40
  def output_filename
33
41
  'coverage.json'
34
42
  end
35
-
43
+
36
44
  def output_filepath
37
45
  File.join(output_path, output_filename)
38
46
  end
39
-
47
+
40
48
  def output_message(result)
41
49
  "Coverage report generated for #{result.command_name} to #{output_filepath}. #{result.covered_lines} / #{result.total_lines} LOC (#{result.covered_percent.round(2)}%) covered."
42
50
  end
43
-
44
- private
51
+
52
+ private
45
53
 
46
54
  def output_path
47
55
  SimpleCov.coverage_path
48
56
  end
57
+
49
58
  end
@@ -4,7 +4,7 @@ require 'simplecov'
4
4
  require 'simplecov-json'
5
5
 
6
6
  require 'test/unit'
7
- require 'mocha'
7
+ require 'mocha/setup'
8
8
 
9
9
  class Test::Unit::TestCase
10
10
  end
@@ -4,21 +4,36 @@ class TestSimpleCovHtml < Test::Unit::TestCase
4
4
  def test_format
5
5
  formatter = SimpleCov::Formatter::JSONFormatter.new
6
6
  result = mock()
7
+ foo = mock()
8
+ bar = mock()
7
9
  created_at = DateTime.now.to_s
8
-
9
10
  result.expects(:created_at).returns(created_at)
10
11
  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'])
12
+
13
+ fooLineList = mock()
14
+ fooLineList.expects(:count).returns(2)
15
+
16
+ barLineList = mock()
17
+ barLineList.expects(:count).returns(5)
18
+
19
+ foo.expects(:filename).twice.returns('/lib/foo.rb')
20
+ foo.expects(:covered_percent).returns(50.0)
21
+ foo.expects(:coverage).returns([1, nil, 0, 0, nil, 1, nil])
22
+ foo.expects(:covered_strength).twice.returns(0.50)
23
+ foo.expects(:covered_lines).returns(fooLineList)
24
+ foo.expects(:lines_of_code).returns(4)
25
+
26
+ bar.expects(:filename).twice.returns('/lib/bar.rb')
27
+ bar.expects(:covered_percent).returns(71.42)
28
+ bar.expects(:coverage).returns([nil, 1, nil, 1, 1, 1, 0, 0, nil, 1, nil])
29
+ bar.expects(:covered_strength).twice.returns(0.71)
30
+ bar.expects(:covered_lines).returns(barLineList)
31
+ bar.expects(:lines_of_code).returns(7)
32
+
33
+ result.expects(:files).returns([foo, bar])
34
+ result.expects(:filenames).twice.returns(['/lib/foo.rb', '/lib/bar.rb'])
20
35
  result.expects(:covered_percent).returns(73.33)
21
- result.expects(:covered_strength).returns(0.87)
36
+ result.expects(:covered_strength).twice.returns(0.87)
22
37
  result.expects(:covered_lines).returns(11)
23
38
  result.expects(:total_lines).returns(15)
24
39
 
@@ -27,14 +42,32 @@ class TestSimpleCovHtml < Test::Unit::TestCase
27
42
  result.expects(:total_lines).returns(15)
28
43
  result.expects(:covered_percent).returns(73.33)
29
44
 
45
+
46
+ # filename
47
+ # covered_percent
48
+ # coverage
49
+ # covered_strength
50
+ # covered_lines
51
+ # lines_of_code
30
52
  assert_equal(formatter.format(result), {
31
53
  'timestamp' => created_at.to_i,
32
54
  'command_name' => 'RSpec',
33
55
  '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]},
56
+ {'filename' => '/lib/foo.rb',
57
+ 'covered_percent' => 50.0,
58
+ 'coverage' => [1, nil, 0, 0, nil, 1, nil],
59
+ 'covered_strength' => 0.50,
60
+ 'covered_lines' => 2,
61
+ 'lines_of_code' => 4
62
+ },
63
+ {'filename' => '/lib/bar.rb',
64
+ 'covered_percent' => 71.42,
65
+ 'coverage' => [nil, 1, nil, 1, 1, 1, 0, 0, nil, 1, nil],
66
+ 'covered_strength' => 0.71,
67
+ 'covered_lines' => 5,
68
+ 'lines_of_code' => 7
69
+ },
36
70
  ],
37
- 'groups' =>['controllers', 'models'],
38
71
  'metrics' => {
39
72
  'covered_percent' => 73.33,
40
73
  'covered_strength' => 0.87,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplecov-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: '0.2'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-24 00:00:00.000000000 Z
12
+ date: 2013-07-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: simplecov
16
- requirement: &18020520 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *18020520
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: json
27
- requirement: &18019880 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,7 +37,28 @@ dependencies:
32
37
  version: '0'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *18019880
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: rake
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
36
62
  description: JSON formatter for SimpleCov code coverage tool for ruby 1.9+
37
63
  email:
38
64
  - villosil@gmail.com
@@ -55,15 +81,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
55
81
  - - ! '>='
56
82
  - !ruby/object:Gem::Version
57
83
  version: '0'
84
+ segments:
85
+ - 0
86
+ hash: 884864916759468203
58
87
  required_rubygems_version: !ruby/object:Gem::Requirement
59
88
  none: false
60
89
  requirements:
61
90
  - - ! '>='
62
91
  - !ruby/object:Gem::Version
63
92
  version: '0'
93
+ segments:
94
+ - 0
95
+ hash: 884864916759468203
64
96
  requirements: []
65
97
  rubyforge_project: simplecov-json
66
- rubygems_version: 1.8.10
98
+ rubygems_version: 1.8.25
67
99
  signing_key:
68
100
  specification_version: 3
69
101
  summary: JSON formatter for SimpleCov code coverage tool for ruby 1.9+