danger-cobertura 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1e6fa67d8f8fec2cba6c8e40ad5439c24e65f9809b5318a599730a67d5ff09a2
4
- data.tar.gz: 3654409caf400866f143fc18fb8f0eb45c185c7b50831e3d624963601baee55d
3
+ metadata.gz: 54cd31fcfbf7c468f938017681d52dc70fcdd505cd33c528b020692767ce6719
4
+ data.tar.gz: 107b6c289fbfec276e74b89d1320f7cfe65c3ffd65f645bca41788be495788cc
5
5
  SHA512:
6
- metadata.gz: 93123d1eaa127811dfa0546fa2d81ddc03e1ea65f69e69addbce48e90f8ef7d911cc869107fc35023945ad8ed79a0d4e0fbea5b3ddeb8d84a0f61be5136e6300
7
- data.tar.gz: 99ce509910af575ceeb1ad729aa1ff145e03de7dea945a1c50aa570db1cce3ba083851a15f25fb4aaf7b80b2b38243584e6fd80e7feb1b0e8f62b7237cb3e31a
6
+ metadata.gz: 57536d735a2acc38c2a6ae4e1c9a2d4ee5dec0599aa161e71e7583430bec64fc91ee6862d1ae48cf65ca6a436b2c1909c3e9875da7633159f26c148ec7f53bf0
7
+ data.tar.gz: f970cb6bbf6359721e5195797cc4ed28abe2520d1381ce26ee5a639dc61317bf8e3cebf334789ed8724bc8f5dfd59de467e769111b0e44d61eed9781d70ab4f7
@@ -4,7 +4,9 @@ All notable changes to this project will be documented in this file.
4
4
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
5
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
- ## [Unreleased]
7
+ ## [1.3.0] - 2019-02-07
8
+ ### Added
9
+ - `fail_if_file_less_than(percentage:)` Create a danger errors if a file has a lower coverage than defined
8
10
 
9
11
  ## [1.2.0] - 2019-01-21
10
12
  ### Changed
data/README.md CHANGED
@@ -18,6 +18,24 @@ This plugin allows parsing of an xml coverage report generated by __cobertura__
18
18
  _It inspects only modified and added files, deleted ones are not considered useful for this report._
19
19
 
20
20
  ## How it looks like
21
+ ### Errors about file coverage
22
+ <table>
23
+ <thead>
24
+ <tr>
25
+ <th width="50"></th>
26
+ <th width="100%">
27
+ 1 Error
28
+ </th>
29
+ </tr>
30
+ </thead>
31
+ <tbody>
32
+ <tr>
33
+ <td><g-emoji alias="no_entry_sign" fallback-src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f6ab.png">🚫</g-emoji></td>
34
+ <td>example.py has less than 50% coverage</td>
35
+ </tr>
36
+ </tbody>
37
+ </table>
38
+
21
39
  ### Warnings about file coverage
22
40
  <table>
23
41
  <thead>
@@ -95,7 +113,8 @@ cobertura.show_coverage
95
113
  <blockquote>Combine all reports
96
114
  <pre>
97
115
  cobertura.report = build/reports/coverage.xml
98
- cobertura.warn_if_file_less_than(percentage: 50.0)
116
+ cobertura.warn_if_file_less_than(percentage: 60.0)
117
+ cobertura.warn_if_file_less_than(percentage: 30.0)
99
118
  cobertura.show_coverage
100
119
  </pre>
101
120
  </blockquote>
@@ -112,6 +131,8 @@ __`filename_prefix`__ - Path prefix to be added to both, the cobertura issue fil
112
131
 
113
132
  __`warn_if_file_less_than(percentage:)`__ - Add a danger warning for each file with a lower total coverage as given.
114
133
 
134
+ __`fail_if_file_less_than(percentage:)`__ - Add a danger error for each file with a lower total coverage as given.
135
+
115
136
  __`show_coverage`__ - Show a markdown table including the coverage for all (modified / added) files.
116
137
 
117
138
  ## Development
@@ -1,3 +1,3 @@
1
1
  module Cobertura
2
- VERSION = "1.2.0".freeze
2
+ VERSION = "1.3.0".freeze
3
3
  end
@@ -44,6 +44,18 @@ module Danger
44
44
  end
45
45
  end
46
46
 
47
+ # Fail if a modified file has a lower total coverage than defined.
48
+ #
49
+ # @param percentage [Float] The minimum code coverage required for a file.
50
+ # @return [Array<String>] Fail warnings of files with a lower coverage.
51
+ def fail_if_file_less_than(percentage:)
52
+ filtered_items.each do |item|
53
+ next unless item.total_percentage < percentage
54
+
55
+ fail "#{item.name} has less than #{percentage}% coverage"
56
+ end
57
+ end
58
+
47
59
  # Show markdown table of modified and added files.
48
60
  # TODO remove * wildcard to accept all parameter: `danger local` bug - https://github.com/danger/danger/issues/1041
49
61
  # @return [Array<String>] A markdown report of modified files and their coverage report.
@@ -264,6 +264,109 @@ module Danger
264
264
  expect(@dangerfile.status_report[:markdowns]).not_to be_empty
265
265
  end
266
266
  end
267
+
268
+ describe "fail_if_file_less_than" do
269
+ it "raises error if file attribute is nil" do
270
+ @my_plugin.report = nil
271
+ expect do
272
+ @my_plugin.fail_if_file_less_than(percentage: 50.0)
273
+ end.to raise_error(DangerCobertura::ERROR_FILE_NOT_SET)
274
+ end
275
+
276
+ it "raises error if file attribute is empty" do
277
+ @my_plugin.report = ""
278
+ expect do
279
+ @my_plugin.fail_if_file_less_than(percentage: 50.0)
280
+ end.to raise_error(DangerCobertura::ERROR_FILE_NOT_SET)
281
+ end
282
+
283
+ it "raises error if file is not found" do
284
+ @my_plugin.report = "cant/find/my/file.xml"
285
+ expect do
286
+ @my_plugin.fail_if_file_less_than(percentage: 50.0)
287
+ end.to raise_error(/#{@my_plugin.report}/)
288
+ end
289
+
290
+ it "adds fail if total coverage lower than given" do
291
+ @dangerfile.git.stubs(:modified_files).returns(%w(sub_folder/sub_two.py top_level_one.py))
292
+ @my_plugin.fail_if_file_less_than(percentage: 90.0)
293
+
294
+ expect(@dangerfile.status_report[:errors]).to include(SUB_TWO_WARNING)
295
+ expect(@dangerfile.status_report[:errors]).not_to include("top_level_one.py has less than 90.0% coverage")
296
+ end
297
+
298
+ it "does not add warn if coverage not" do
299
+ @dangerfile.git.stubs(:modified_files).returns(SUB_TWO)
300
+ @my_plugin.fail_if_file_less_than(percentage: 10.0)
301
+
302
+ expect(@dangerfile.status_report[:errors]).to be_empty
303
+ end
304
+
305
+ it "adds warn for modified files" do
306
+ @dangerfile.git.stubs(:modified_files).returns(SUB_TWO)
307
+ @my_plugin.fail_if_file_less_than(percentage: 90.0)
308
+
309
+ expect(@dangerfile.status_report[:errors]).to include(SUB_TWO_WARNING)
310
+ end
311
+
312
+ it "adds warn for added files" do
313
+ @dangerfile.git.stubs(:added_files).returns(SUB_TWO)
314
+ @my_plugin.fail_if_file_less_than(percentage: 90.0)
315
+
316
+ expect(@dangerfile.status_report[:errors]).to include(SUB_TWO_WARNING)
317
+ end
318
+
319
+ it "adds warn for added and modified files" do
320
+ @dangerfile.git.stubs(:added_files).returns(SUB_TWO)
321
+ @dangerfile.git.stubs(:modified_files).returns(SUB_ONE)
322
+ @my_plugin.fail_if_file_less_than(percentage: 90.0)
323
+
324
+ expect(@dangerfile.status_report[:errors]).to include(SUB_TWO_WARNING)
325
+ expect(@dangerfile.status_report[:errors]).to include("sub_one.py has less than 90.0% coverage")
326
+ end
327
+
328
+ it "does not add if filename missing prefix" do
329
+ # sub_folder/sub_two.py in xml
330
+ @dangerfile.git.stubs(:added_files).returns(%w(not_including/sub_folder/sub_two.py))
331
+ expect(@my_plugin.filename_prefix).to be_nil
332
+
333
+ @my_plugin.fail_if_file_less_than(percentage: 90.0)
334
+
335
+ expect(@dangerfile.status_report[:errors]).not_to include(SUB_TWO_WARNING)
336
+ end
337
+
338
+ it "does add if issue filename prefix set" do
339
+ @dangerfile.git.stubs(:added_files).returns(PREFIX_TWO)
340
+ @my_plugin.filename_prefix = PREFIX
341
+ @my_plugin.fail_if_file_less_than(percentage: 90.0)
342
+
343
+ expect(@dangerfile.status_report[:errors]).to include(SUB_TWO_WARNING)
344
+ end
345
+
346
+ it "does add if git filename prefix set" do
347
+ @dangerfile.git.stubs(:added_files).returns(SUB_TWO)
348
+ @my_plugin.filename_prefix = PREFIX
349
+ @my_plugin.fail_if_file_less_than(percentage: 90.0)
350
+
351
+ expect(@dangerfile.status_report[:errors]).to include(SUB_TWO_WARNING)
352
+ end
353
+
354
+ it "ignores filename prefix slash" do
355
+ @dangerfile.git.stubs(:added_files).returns(PREFIX_TWO)
356
+ @my_plugin.filename_prefix = "#{PREFIX}/"
357
+ @my_plugin.fail_if_file_less_than(percentage: 90.0)
358
+
359
+ expect(@dangerfile.status_report[:errors]).to include(SUB_TWO_WARNING)
360
+ end
361
+
362
+ it "should not add name with $" do
363
+ @dangerfile.git.stubs(:added_files).returns(SUB_THREE)
364
+ @my_plugin.fail_if_file_less_than(percentage: 90.0)
365
+
366
+ expect(@dangerfile.status_report[:errors]).to include("sub_three.py has less than 90.0% coverage")
367
+ expect(@dangerfile.status_report[:errors]).not_to include("sub_three$.py has less than 90.0% coverage")
368
+ end
369
+ end
267
370
  end
268
371
  end
269
372
  end
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.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyaak
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-21 00:00:00.000000000 Z
11
+ date: 2019-02-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: danger-plugin-api