danger-cobertura 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 82b28e2ecb8f0383f89f977bc3a1b073b0be37076a3e5f97e66679abd8790102
4
- data.tar.gz: b44ee503e7b9588a4d385f008cd26a293f32075f34a4ee726053d2dee659b518
3
+ metadata.gz: 581a9da17cf4517347df716589c098c219abcdac2fdd5887a6cb8ac9626119de
4
+ data.tar.gz: 97f48312f384759df2a674ba129501597becba3afb5a3b1a168a8a6697ce41d2
5
5
  SHA512:
6
- metadata.gz: 4616f102f79dbe73922f317efc478cadb10fa5c8584f5d0f214d1b1ae3d869eb2e89163b198d05f883b3f36c885e8f3cb8ac9c6f0410acd4b32f7b8f057fee1b
7
- data.tar.gz: 047a27612a80b13e93410a422574c2b32e39c186eec49b095710cbfaa8d9b8884fec0ef7d0b8e73383d3b8e77bef1a393ab493e35710aa90f3a341bcbfb4cf13
6
+ metadata.gz: 858d10f14d3e5c422787929b97c85a02f0616544ba121788d4a90bc650bf05cb722b758243c51fb4e3e83674dcb94d2abe8161a44a67616f5bd0c527ece52652
7
+ data.tar.gz: a209e03077a94489ac9110048a98f43f9013f9ae85bdebb40e0997afeddf3b46608050b37beca56561babb1b1be9ad9092adbcee39e2c06af40005e84a2715a0
data/.codeclimate.yml ADDED
@@ -0,0 +1,5 @@
1
+ plugins:
2
+ rubocop:
3
+ enabled: true
4
+ config:
5
+ file: .rubocop.yml
data/.gitignore CHANGED
@@ -4,3 +4,4 @@ pkg
4
4
  .yardoc
5
5
  Gemfile.lock
6
6
  .vscode
7
+ coverage
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@
3
3
  # If you don't like these settings, just delete this file :)
4
4
 
5
5
  AllCops:
6
- TargetRubyVersion: 2.5
6
+ TargetRubyVersion: 2.2
7
7
 
8
8
  Style/StringLiterals:
9
9
  EnforcedStyle: double_quotes
@@ -150,3 +150,6 @@ PercentLiteralDelimiters:
150
150
 
151
151
  Security/YAMLLoad:
152
152
  Enabled: false
153
+
154
+ Metrics/ModuleLength:
155
+ Max: 500
data/.travis.yml CHANGED
@@ -5,11 +5,26 @@ cache:
5
5
  - bundle
6
6
 
7
7
  rvm:
8
- - 2.5.2
8
+ - 2.2
9
+ - 2.3
10
+ - 2.4
11
+ - 2.5
12
+
13
+ env:
14
+ global:
15
+ - CC_TEST_REPORTER_ID=7cfcaf05ab26fd0e7088ab0b16e902559a6d0c0c6f6785fa908e20efeba53c64
16
+
17
+ before_script:
18
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
19
+ - chmod +x ./cc-test-reporter
20
+ - ./cc-test-reporter before-build
9
21
 
10
22
  script:
11
23
  - bundle exec rake spec
12
24
 
25
+ after_script:
26
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
27
+
13
28
  deploy:
14
29
  provider: rubygems
15
30
  api_key:
data/CHANGELOG.md CHANGED
@@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [1.1.0] - 2018-11-28
10
+ ### Added
11
+ - Option to add branch and line rate information
12
+ - Add a filename prefix
13
+
14
+ ### Changed
15
+ - Exclude all files with "$" sign in name
16
+ - Support ruby 2.2 - 2.5
17
+
9
18
  ## [1.0.0] - 2018-11-25
10
19
  ### Added
11
20
  - Initial release.
data/README.md CHANGED
@@ -1,3 +1,10 @@
1
+ [![Gem Version](https://badge.fury.io/rb/danger-cobertura.svg)](https://badge.fury.io/rb/danger-cobertura)
2
+ [![Build Status](https://travis-ci.org/Kyaak/danger-cobertura.svg?branch=master)](https://travis-ci.org/Kyaak/danger-cobertura)
3
+ [![Maintainability](https://api.codeclimate.com/v1/badges/2e657e2a49ddf9696ece/maintainability)](https://codeclimate.com/github/Kyaak/danger-cobertura/maintainability)
4
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/2e657e2a49ddf9696ece/test_coverage)](https://codeclimate.com/github/Kyaak/danger-cobertura/test_coverage)
5
+ [![Inline docs](http://inch-ci.org/github/Kyaak/danger-cobertura.svg?branch=master)](http://inch-ci.org/github/Kyaak/danger-cobertura)
6
+ [![Gem](https://img.shields.io/gem/dt/danger-cobertura.svg)](https://rubygems.org/gems/danger-cobertura)
7
+
1
8
  # danger-cobertura
2
9
 
3
10
  A [cobertura](http://cobertura.github.io/cobertura/) report plugin for [danger](https://danger.systems/ruby).
@@ -27,12 +34,20 @@ _It inspects only modified and added files, deleted ones are not considered usef
27
34
 
28
35
  ### Coverage report
29
36
 
30
- File | Coverage
37
+ #### Minimum
38
+
39
+ File | Total
31
40
  -----|-----
32
41
  example_one.py | 50.00
33
42
  example_two.py | 35.60
34
43
  example_three.py | 10.48
35
44
 
45
+ #### Maximum
46
+
47
+ File | Total | Line | Branch
48
+ -----|-----|-----|-----
49
+ example_one.py | 50.00 | 75.00 | 25.00
50
+ example_two.py | 35.50 | 20.50 | 50.50
36
51
 
37
52
  ## Installation
38
53
 
@@ -50,9 +65,25 @@ cobertura.warn_if_file_less_than(percentage: 50.0)
50
65
  </pre>
51
66
  </blockquote>
52
67
 
53
- <blockquote>Show coverage of all files
68
+ <blockquote>Show default coverage of all files
69
+ <pre>
70
+ cobertura.report = build/reports/coverage.xml
71
+ cobertura.show_coverage
72
+ </pre>
73
+ </blockquote>
74
+
75
+ <blockquote>Use filename prefix to find your files - find your files in your filesystem. e.g Java projects are under "src/main/java".
76
+ <pre>
77
+ cobertura.report = build/reports/coverage.xml
78
+ cobertura.filename_prefix = "src/main/java"
79
+ cobertura.show_coverage
80
+ </pre>
81
+ </blockquote>
82
+
83
+ <blockquote>Show coverage of all files including line and branch rate
54
84
  <pre>
55
85
  cobertura.report = build/reports/coverage.xml
86
+ cobertura.additional_headers = [:line, :branch]
56
87
  cobertura.show_coverage
57
88
  </pre>
58
89
  </blockquote>
@@ -68,6 +99,8 @@ cobertura.show_coverage
68
99
  ## Attributes
69
100
 
70
101
  __`report`__ - Path to the cobertura xml report, e.g. `build/reports/coverage.xml`
102
+ __`additional_headers`__ - Array of symbols to include in the coverage report. Available options are `:line`, `:branch`
103
+ __`filename_prefix`__ - Path prefix to be added to the cobertura class filename attribute. e.g. `src/main/java`
71
104
 
72
105
  ## Methods
73
106
 
@@ -19,6 +19,8 @@ Gem::Specification.new do |spec|
19
19
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
20
  spec.require_paths = ["lib"]
21
21
 
22
+ spec.required_ruby_version = ">=2.2.0"
23
+
22
24
  spec.add_runtime_dependency "danger-plugin-api", "~> 1.0"
23
25
  spec.add_runtime_dependency "oga", "~> 2.15"
24
26
 
@@ -29,9 +31,11 @@ Gem::Specification.new do |spec|
29
31
  # Testing support
30
32
  spec.add_development_dependency "mocha", "~> 1.2"
31
33
  spec.add_development_dependency "rspec", "~> 3.4"
34
+ spec.add_development_dependency "simplecov", "~> 0.16"
35
+ spec.add_development_dependency "simplecov-console", "~> 0.4"
32
36
 
33
37
  # Linting code and docs
34
- spec.add_development_dependency "rubocop", "~> 0.6"
38
+ spec.add_development_dependency "rubocop", "~> 0.60"
35
39
  spec.add_development_dependency "yard", "~> 0.9"
36
40
 
37
41
  # Makes testing easy via `bundle exec guard`
@@ -1,26 +1,33 @@
1
- # frozen_string_literal: true
2
-
1
+ # Container item for cobertura <class> entries
3
2
  class CoverageItem
3
+ # Initialize an object using an xml node set containing the class information of a cobertura report.
4
+ #
5
+ # @param node [Oga::XML::NodeSet] NodeSet of a class
4
6
  def initialize(node)
5
7
  @node = node
6
8
  end
7
9
 
10
+ # @return [Float] The combined coverage of branch and line rate
8
11
  def total_percentage
9
- @total_percentage ||= ((branch_rate + line_rate) / 2) * 100
12
+ @total_percentage ||= (branch_rate + line_rate) / 2
10
13
  end
11
14
 
15
+ # @return [Float] The branch coverage rate
12
16
  def branch_rate
13
- @branch_rate ||= @node.attribute("branch-rate").value.to_f
17
+ @branch_rate ||= @node.attribute("branch-rate").value.to_f * 100
14
18
  end
15
19
 
20
+ # @return [Float] The line coverage rate
16
21
  def line_rate
17
- @line_rate ||= @node.attribute("line-rate").value.to_f
22
+ @line_rate ||= @node.attribute("line-rate").value.to_f * 100
18
23
  end
19
24
 
20
- def file_name
21
- @file_name ||= @node.attribute("filename").value.to_s
25
+ # @return [String] Name of the class file with directory path
26
+ def filename
27
+ @filename ||= @node.attribute("filename").value.to_s
22
28
  end
23
29
 
30
+ # @return [String] Name of the class file with package structure
24
31
  def name
25
32
  @name ||= @node.attribute("name").value.to_s
26
33
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Cobertura
4
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0".freeze
5
3
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  module Danger
4
2
  # Show code coverage of modified and added files.
5
3
  # Add warnings if minimum file coverage is not achieved.
@@ -13,19 +11,31 @@ module Danger
13
11
  # @tags cobertura, coverage
14
12
  #
15
13
  class DangerCobertura < Plugin
14
+ require "oga"
16
15
  require_relative "./coverage_item"
17
- ERROR_FILE_NOT_SET = "Cobertura file not set. Use 'cobertura.file = \"path/to/my/report.xml\"'."
18
- ERROR_FILE_NOT_FOUND = "No file found at %s"
16
+
17
+ ERROR_FILE_NOT_SET = "Cobertura file not set. Use 'cobertura.file = \"path/to/my/report.xml\"'.".freeze
18
+ ERROR_FILE_NOT_FOUND = "No file found at %s".freeze
19
+ TABLE_COLUMN_LINE = "-----".freeze
19
20
 
20
21
  # Path to the xml formatted cobertura report.
21
22
  #
22
- # @return [String]
23
+ # @return [String] Report file.
23
24
  attr_accessor :report
25
+ # Array of symbols which allows to extend the markdown report columns.
26
+ # Allowed symbols: :branch, :line
27
+ #
28
+ # @return [Array<Symbol>] Columns to add in the markdown report.
29
+ attr_accessor :additional_headers
30
+ # Path prefix to be added to the cobertura class filename attribute.
31
+ #
32
+ # @return [String] Prefix to add to filename path.
33
+ attr_accessor :filename_prefix
24
34
 
25
35
  # Warn if a modified file has a lower total coverage than defined.
26
36
  #
27
37
  # @param percentage [Float] The minimum code coverage required for a file.
28
- # @return [Array<String>]
38
+ # @return [Array<String>] Warnings of files with a lower coverage.
29
39
  def warn_if_file_less_than(percentage:)
30
40
  filtered_items.each do |item|
31
41
  next unless item.total_percentage < percentage
@@ -36,58 +46,126 @@ module Danger
36
46
 
37
47
  # Show markdown table of modified and added files.
38
48
  #
39
- # @return [Array<String>]
49
+ # @return [Array<String>] A markdown report of modified files and their coverage report.
40
50
  def show_coverage
41
51
  return if filtered_items.empty?
42
52
 
43
- line = +"## Code coverage\n"
44
- line << "File | Coverage\n"
45
- line << "-----|-----\n"
53
+ table = "## Code coverage\n".dup
54
+ table << table_header
55
+ table << table_separation
56
+
46
57
  filtered_items.each do |item|
47
- line << "#{item.name} | #{format('%.2f', item.total_percentage)}\n"
58
+ table << table_entry(item)
48
59
  end
49
- markdown line
60
+ markdown table
50
61
  end
51
62
 
52
63
  private
53
64
 
65
+ # Create the show_coverage column headers.
66
+ #
67
+ # @return [String] Markdown for table headers.
68
+ def table_header
69
+ line = "File|Total".dup
70
+ line << "|Line" if header_line_rate?
71
+ line << "|Branch" if header_branch_rate?
72
+ line << "\n"
73
+ end
74
+
75
+ # Create the show_coverage table header separation line.
76
+ #
77
+ # @return [String] Markdown for table header separation.
78
+ def table_separation
79
+ line = "#{TABLE_COLUMN_LINE}|#{TABLE_COLUMN_LINE}".dup
80
+ line << "|#{TABLE_COLUMN_LINE}" if header_line_rate?
81
+ line << "|#{TABLE_COLUMN_LINE}" if header_branch_rate?
82
+ line << "\n"
83
+ end
84
+
85
+ # Create the show_coverage table rows.
86
+ #
87
+ # @param item [CoverageItem] Coverage item to put information in the table row.
88
+ # @return [String] Markdown for table rows.
89
+ def table_entry(item)
90
+ line = item.name.dup
91
+ line << "|#{format_coverage(item.total_percentage)}"
92
+ line << "|#{format_coverage(item.line_rate)}" if header_line_rate?
93
+ line << "|#{format_coverage(item.branch_rate)}" if header_branch_rate?
94
+ line << "\n"
95
+ end
96
+
97
+ # Check if additional_headers includes symbol :line
98
+ #
99
+ # @return [Boolean] :line header defined.
100
+ def header_line_rate?
101
+ !additional_headers.nil? && additional_headers.include?(:line)
102
+ end
103
+
104
+ # Check if additional_headers includes symbol :branch
105
+ #
106
+ # @return [Boolean] :branch header defined.
107
+ def header_branch_rate?
108
+ !additional_headers.nil? && additional_headers.include?(:branch)
109
+ end
110
+
111
+ # Format coverage output to two decimals.
112
+ #
113
+ # @param coverage [Float] Value to format.
114
+ # @return [String] Formatted coverage string.
115
+ def format_coverage(coverage)
116
+ format("%.2f", coverage)
117
+ end
118
+
54
119
  # Getter for coverage items of targeted files.
120
+ # Only coverage items contained in the targeted files list will be returned.
55
121
  #
56
- # @return [Array<CoverageItem>]
122
+ # @return [Array<CoverageItem>] Filtered array of items
57
123
  def filtered_items
58
124
  @filtered_items ||= coverage_items.select do |item|
59
- target_files.include? item.file_name
125
+ target_files.include?(item_filename(item)) && !item.name.include?("$")
126
+ end
127
+ end
128
+
129
+ # Combine item filename with prefix.
130
+ #
131
+ # @param item [CoverageItem] Coverage item to create the full filename.
132
+ # @return [String] Combined filename.
133
+ def item_filename(item)
134
+ result = "".dup
135
+ if filename_prefix
136
+ result << filename_prefix
137
+ result << "/" unless filename_prefix.chars.last == "/"
60
138
  end
139
+ result << item.filename
61
140
  end
62
141
 
63
- # A getter for current updated files.
142
+ # A getter for current modified and added files.
64
143
  #
65
- # @return [Array<String>]
144
+ # @return [Danger::FileList] Wrapper FileList object.
66
145
  def target_files
67
146
  @target_files ||= git.modified_files + git.added_files
68
147
  end
69
148
 
70
149
  # Parse the defined coverage report file.
71
150
  #
72
- # @return [Oga::XML::Document]
151
+ # @return [Oga::XML::Document] The root xml object.
73
152
  def parse
74
- require "oga"
75
153
  raise ERROR_FILE_NOT_SET if report.nil? || report.empty?
76
154
  raise format(ERROR_FILE_NOT_FOUND, report) unless File.exist?(report)
77
155
 
78
156
  Oga.parse_xml(File.read(report))
79
157
  end
80
158
 
81
- # Get the xml cobertura report.
159
+ # Convenient method to not always parse the report but keep it in the memory.
82
160
  #
83
- # @return [Oga::XML::Document]
161
+ # @return [Oga::XML::Document] The root xml object.
84
162
  def xml_report
85
163
  @xml_report ||= parse
86
164
  end
87
165
 
88
- # Getter for all coverage data.
166
+ # Extract and create all class items from the xml report.
89
167
  #
90
- # @return [Array<CoverageItem>]
168
+ # @return [Array<CoverageItem>] Items with cobertura class information.
91
169
  def coverage_items
92
170
  @coverage_items ||= xml_report.xpath("//class").map do |node|
93
171
  CoverageItem.new(node)
@@ -1,3 +1 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "cobertura/gem_version"
data/lib/danger_plugin.rb CHANGED
@@ -1,3 +1 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "cobertura/plugin"
@@ -277,6 +277,12 @@
277
277
  <line branch="true" condition-coverage="0% (0/2)" hits="0" number="88"/>
278
278
  </lines>
279
279
  </class>
280
+ <class branch-rate="0" complexity="0" filename="sub_folder/sub_three.py" line-rate="0" name="sub_three$.py">
281
+ <methods/>
282
+ <lines>
283
+ <line branch="true" condition-coverage="0% (0/2)" hits="0" number="88"/>
284
+ </lines>
285
+ </class>
280
286
  </classes>
281
287
  </package>
282
288
  </packages>
@@ -53,6 +53,65 @@ module Danger
53
53
 
54
54
  expect(@dangerfile.status_report[:warnings]).to be_empty
55
55
  end
56
+
57
+ it "adds warn for modified files" do
58
+ @dangerfile.git.stubs(:modified_files).returns(%w(sub_folder/sub_two.py))
59
+ @my_plugin.warn_if_file_less_than(percentage: 90.0)
60
+
61
+ expect(@dangerfile.status_report[:warnings]).to include("sub_two.py has less than 90.0% coverage")
62
+ end
63
+
64
+ it "adds warn for added files" do
65
+ @dangerfile.git.stubs(:added_files).returns(%w(sub_folder/sub_two.py))
66
+ @my_plugin.warn_if_file_less_than(percentage: 90.0)
67
+
68
+ expect(@dangerfile.status_report[:warnings]).to include("sub_two.py has less than 90.0% coverage")
69
+ end
70
+
71
+ it "adds warn for added and modified files" do
72
+ @dangerfile.git.stubs(:added_files).returns(%w(sub_folder/sub_two.py))
73
+ @dangerfile.git.stubs(:modified_files).returns(%w(sub_folder/sub_one.py))
74
+ @my_plugin.warn_if_file_less_than(percentage: 90.0)
75
+
76
+ expect(@dangerfile.status_report[:warnings]).to include("sub_two.py has less than 90.0% coverage")
77
+ expect(@dangerfile.status_report[:warnings]).to include("sub_one.py has less than 90.0% coverage")
78
+ end
79
+
80
+ it "does not add if filename missing prefix" do
81
+ # sub_folder/sub_two.py in xml
82
+ @dangerfile.git.stubs(:added_files).returns(%w(my_prefix_dir/sub_folder/sub_two.py))
83
+ expect(@my_plugin.filename_prefix).to be_nil
84
+
85
+ @my_plugin.warn_if_file_less_than(percentage: 90.0)
86
+
87
+ expect(@dangerfile.status_report[:warnings]).not_to include("sub_two.py has less than 90.0% coverage")
88
+ end
89
+
90
+ it "does add if filename prefix set" do
91
+ # sub_folder/sub_two.py in xml
92
+ @dangerfile.git.stubs(:added_files).returns(%w(my_prefix_dir/sub_folder/sub_two.py))
93
+ @my_plugin.filename_prefix = "my_prefix_dir"
94
+ @my_plugin.warn_if_file_less_than(percentage: 90.0)
95
+
96
+ expect(@dangerfile.status_report[:warnings]).to include("sub_two.py has less than 90.0% coverage")
97
+ end
98
+
99
+ it "ignores filename prefix slash" do
100
+ # sub_folder/sub_two.py in xml
101
+ @dangerfile.git.stubs(:added_files).returns(%w(my_prefix_dir/sub_folder/sub_two.py))
102
+ @my_plugin.filename_prefix = "my_prefix_dir/"
103
+ @my_plugin.warn_if_file_less_than(percentage: 90.0)
104
+
105
+ expect(@dangerfile.status_report[:warnings]).to include("sub_two.py has less than 90.0% coverage")
106
+ end
107
+
108
+ it "should not add name with $" do
109
+ @dangerfile.git.stubs(:added_files).returns(%w(sub_folder/sub_three.py))
110
+ @my_plugin.warn_if_file_less_than(percentage: 90.0)
111
+
112
+ expect(@dangerfile.status_report[:warnings]).to include("sub_three.py has less than 90.0% coverage")
113
+ expect(@dangerfile.status_report[:warnings]).not_to include("sub_three$.py has less than 90.0% coverage")
114
+ end
56
115
  end
57
116
 
58
117
  describe "show_coverage" do
@@ -77,13 +136,109 @@ module Danger
77
136
  end.to raise_error(/#{@my_plugin.report}/)
78
137
  end
79
138
 
80
- it "prints coverage" do
139
+ it "adds coverage for modified files" do
140
+ @dangerfile.git.stubs(:modified_files).returns(%w(sub_folder/sub_two.py))
141
+ @my_plugin.show_coverage
142
+
143
+ expect(@dangerfile.status_report[:markdowns]).not_to be_empty
144
+ end
145
+
146
+ it "adds coverage for added files" do
147
+ @dangerfile.git.stubs(:added_files).returns(%w(sub_folder/sub_two.py))
148
+ @my_plugin.show_coverage
149
+
150
+ expect(@dangerfile.status_report[:markdowns]).not_to be_empty
151
+ end
152
+
153
+ it "adds coverage for added and modified files" do
154
+ @dangerfile.git.stubs(:added_files).returns(%w(sub_folder/sub_two.py))
155
+ @dangerfile.git.stubs(:modified_files).returns(%w(sub_folder/sub_one.py))
156
+ @my_plugin.show_coverage
157
+
158
+ expect(@dangerfile.status_report[:markdowns]).not_to be_empty
159
+ end
160
+
161
+ it "default does not add branch and line" do
162
+ @dangerfile.git.stubs(:modified_files).returns(["sub_folder/sub_three.py"])
163
+ @my_plugin.show_coverage
164
+
165
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("File")
166
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("Total")
167
+ expect(@dangerfile.status_report[:markdowns][0].message).to include(table_column_line(2))
168
+ expect(@dangerfile.status_report[:markdowns][0].message).not_to include("Branch")
169
+ expect(@dangerfile.status_report[:markdowns][0].message).not_to include("Line")
170
+ expect(@dangerfile.status_report[:markdowns][0].message).not_to include(table_column_line(4))
171
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("0.00")
172
+ end
173
+
174
+ it "additional_header line adds line rate" do
175
+ @dangerfile.git.stubs(:modified_files).returns(["sub_folder/sub_three.py"])
176
+ @my_plugin.additional_headers = [:line]
177
+ @my_plugin.show_coverage
178
+
179
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("File")
180
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("Total")
181
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("Line")
182
+ expect(@dangerfile.status_report[:markdowns][0].message).to include(table_column_line(3))
183
+ expect(@dangerfile.status_report[:markdowns][0].message).not_to include("Branch")
184
+ expect(@dangerfile.status_report[:markdowns][0].message).not_to include(table_column_line(4))
185
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("0.00")
186
+ end
187
+
188
+ it "additional_header branch adds branch rate" do
81
189
  @dangerfile.git.stubs(:modified_files).returns(["sub_folder/sub_three.py"])
190
+ @my_plugin.additional_headers = [:branch]
82
191
  @my_plugin.show_coverage
83
192
 
84
- expect(@dangerfile.status_report[:markdowns][0].message).to include("sub_three.py")
193
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("File")
194
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("Total")
195
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("Branch")
196
+ expect(@dangerfile.status_report[:markdowns][0].message).to include(table_column_line(3))
197
+ expect(@dangerfile.status_report[:markdowns][0].message).not_to include("Line")
198
+ expect(@dangerfile.status_report[:markdowns][0].message).not_to include(table_column_line(4))
85
199
  expect(@dangerfile.status_report[:markdowns][0].message).to include("0.00")
86
200
  end
201
+
202
+ it "additional_header line and branch adds rate" do
203
+ @dangerfile.git.stubs(:modified_files).returns(["sub_folder/sub_three.py"])
204
+ @my_plugin.additional_headers = %i(branch line)
205
+ @my_plugin.show_coverage
206
+
207
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("File")
208
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("Total")
209
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("Branch")
210
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("Line")
211
+ expect(@dangerfile.status_report[:markdowns][0].message).to include(table_column_line(4))
212
+ expect(@dangerfile.status_report[:markdowns][0].message).to include("0.00")
213
+ end
214
+
215
+ it "does not show coverage if filename prefix missing" do
216
+ # sub_folder/sub_two.py in xml
217
+ @dangerfile.git.stubs(:added_files).returns(%w(my_prefix_dir/sub_folder/sub_two.py))
218
+ expect(@my_plugin.filename_prefix).to be_nil
219
+
220
+ @my_plugin.show_coverage
221
+
222
+ expect(@dangerfile.status_report[:markdowns]).to be_empty
223
+ end
224
+
225
+ it "does show coverage if filename prefix matches" do
226
+ # sub_folder/sub_two.py in xml
227
+ @dangerfile.git.stubs(:added_files).returns(%w(my_prefix_dir/sub_folder/sub_two.py))
228
+ @my_plugin.filename_prefix = "my_prefix_dir"
229
+ @my_plugin.show_coverage
230
+
231
+ expect(@dangerfile.status_report[:markdowns]).not_to be_empty
232
+ end
233
+
234
+ it "ignores filename prefix slash" do
235
+ # sub_folder/sub_two.py in xml
236
+ @dangerfile.git.stubs(:added_files).returns(%w(my_prefix_dir/sub_folder/sub_two.py))
237
+ @my_plugin.filename_prefix = "my_prefix_dir/"
238
+ @my_plugin.show_coverage
239
+
240
+ expect(@dangerfile.status_report[:markdowns]).not_to be_empty
241
+ end
87
242
  end
88
243
  end
89
244
  end
@@ -0,0 +1,12 @@
1
+ module Helpers
2
+ def table_column_line(columns)
3
+ result = "".dup
4
+ (1..columns).each do |i|
5
+ result << "-----"
6
+ if i < columns
7
+ result << "|"
8
+ end
9
+ end
10
+ result
11
+ end
12
+ end
data/spec/spec_helper.rb CHANGED
@@ -11,6 +11,13 @@ require "pry"
11
11
  require "rspec"
12
12
  require "danger"
13
13
  require "mocha"
14
+ require "simplecov"
15
+ require "simplecov-console"
16
+
17
+ require_relative "./helper/cobertura_helper"
18
+
19
+ SimpleCov.formatter = SimpleCov::Formatter::Console
20
+ SimpleCov.start
14
21
 
15
22
  if `git remote -v` == ""
16
23
  puts "You cannot run tests without setting a local git remote on this repo"
@@ -24,6 +31,7 @@ RSpec.configure do |config|
24
31
  config.color = true
25
32
  config.tty = true
26
33
  config.mock_with :mocha
34
+ config.include Helpers
27
35
  end
28
36
 
29
37
  require "danger_plugin"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-cobertura
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyaak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-25 00:00:00.000000000 Z
11
+ date: 2018-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api
@@ -94,20 +94,48 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '3.4'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.16'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov-console
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.4'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.4'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: rubocop
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
129
  - - "~>"
102
130
  - !ruby/object:Gem::Version
103
- version: '0.6'
131
+ version: '0.60'
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
136
  - - "~>"
109
137
  - !ruby/object:Gem::Version
110
- version: '0.6'
138
+ version: '0.60'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: yard
113
141
  requirement: !ruby/object:Gem::Requirement
@@ -185,6 +213,7 @@ executables: []
185
213
  extensions: []
186
214
  extra_rdoc_files: []
187
215
  files:
216
+ - ".codeclimate.yml"
188
217
  - ".gitignore"
189
218
  - ".rubocop.yml"
190
219
  - ".travis.yml"
@@ -202,6 +231,7 @@ files:
202
231
  - lib/danger_plugin.rb
203
232
  - spec/assets/coverage.xml
204
233
  - spec/cobertura_spec.rb
234
+ - spec/helper/cobertura_helper.rb
205
235
  - spec/spec_helper.rb
206
236
  homepage: https://github.com/Kyaak/danger-cobertura
207
237
  licenses:
@@ -215,7 +245,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
215
245
  requirements:
216
246
  - - ">="
217
247
  - !ruby/object:Gem::Version
218
- version: '0'
248
+ version: 2.2.0
219
249
  required_rubygems_version: !ruby/object:Gem::Requirement
220
250
  requirements:
221
251
  - - ">="
@@ -223,7 +253,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
223
253
  version: '0'
224
254
  requirements: []
225
255
  rubyforge_project:
226
- rubygems_version: 2.7.8
256
+ rubygems_version: 2.7.7
227
257
  signing_key:
228
258
  specification_version: 4
229
259
  summary: This plugin allows parsing of an xml coverage report generated by cobertura
@@ -231,4 +261,5 @@ summary: This plugin allows parsing of an xml coverage report generated by cober
231
261
  test_files:
232
262
  - spec/assets/coverage.xml
233
263
  - spec/cobertura_spec.rb
264
+ - spec/helper/cobertura_helper.rb
234
265
  - spec/spec_helper.rb