danger-slather 0.0.5 → 0.0.6

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
  SHA1:
3
- metadata.gz: 0cca0c4afa507eb7bd73fd601ff4e97337d69b34
4
- data.tar.gz: c2c51b1c82fb386547c377da813ea9aa19b0b2e3
3
+ metadata.gz: ba3f7cf814e5c7c34df8ba4dc7eaf2a2a4feb131
4
+ data.tar.gz: 022e6952680d03141cae1a2784fc4e8480f751a6
5
5
  SHA512:
6
- metadata.gz: f797ddccc437deecb8f81bbdb7542387dabe93a377b489b1a2b8244ce401c009b49547ffa928cc262cf41bf1aa6300b4dcf822131877eed044e81cc2239fa9ea
7
- data.tar.gz: 5d0f6df048d4d9c4f1696d8d79281e309dba257333faf1a4da97461dbd8e397c6ec822a03b552462a446698958c5f3302e7c17f6b54e3ca3fccf5591a89d0f12
6
+ metadata.gz: 94caa281818749952ac7dba39aca501650b39881cb0df8fcf3860e3d00b969b8f20e64c2cece449f79b31a2da6ee9fe80774cf1221039da9ed5ba028051ae9ed
7
+ data.tar.gz: e36e75e82569157ab01f3e385b88bdad1898658877635f84f4e93cd3864f34e4f8d3ad49ada13186e42e218bcab03b56ed2ef19e7166068e9f4e29270112b929
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- danger-slather (0.0.3)
4
+ danger-slather (0.0.6)
5
5
  danger-plugin-api (~> 1.0)
6
6
  slather (~> 2.3)
7
7
 
@@ -1,3 +1,3 @@
1
1
  module Slather
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '0.0.6'.freeze
3
3
  end
@@ -78,8 +78,8 @@ module Danger
78
78
  minimum_coverage = options[:minimum_coverage]
79
79
  notify_level = options[:notify_level] || :fail
80
80
 
81
- if modified_files_coverage.count > 0
82
- files_to_notify = modified_files_coverage.select do |file|
81
+ if all_modified_files_coverage.count > 0
82
+ files_to_notify = all_modified_files_coverage.select do |file|
83
83
  file.percentage_lines_tested < minimum_coverage
84
84
  end
85
85
  notify_messages = files_to_notify.map do |file|
@@ -117,10 +117,10 @@ module Danger
117
117
  def modified_files_coverage_table
118
118
  unless @project.nil?
119
119
  line = ''
120
- if modified_files_coverage.count > 0
120
+ if all_modified_files_coverage.count > 0
121
121
  line << "File | Coverage\n"
122
122
  line << "-----|-----\n"
123
- modified_files_coverage.each do |coverage_file|
123
+ all_modified_files_coverage.each do |coverage_file|
124
124
  file_name = coverage_file.source_file_pathname_relative_to_repo_root.to_s
125
125
  percentage = @project.decimal_f([coverage_file.percentage_lines_tested])
126
126
  line << "#{file_name} | **`#{percentage}%`**\n"
@@ -152,14 +152,21 @@ module Danger
152
152
 
153
153
  # Array of files that we have coverage information and was modified
154
154
  # @return [Array<File>]
155
- def modified_files_coverage
155
+ def all_modified_files_coverage
156
156
  unless @project.nil?
157
- @project.coverage_files.select do |file|
158
- git.modified_files.include? file.source_file_pathname_relative_to_repo_root.to_s
157
+ all_modified_files_coverage ||= begin
158
+ modified_files = git.modified_files.nil? ? [] : git.modified_files
159
+ added_files = git.added_files.nil? ? [] : git.added_files
160
+ all_changed_files = modified_files | added_files
161
+ @project.coverage_files.select do |file|
162
+ all_changed_files.include? file.source_file_pathname_relative_to_repo_root.to_s
163
+ end
159
164
  end
165
+
166
+ all_modified_files_coverage
160
167
  end
161
168
  end
162
169
 
163
- private :modified_files_coverage, :total_coverage_markdown
170
+ private :all_modified_files_coverage, :total_coverage_markdown
164
171
  end
165
172
  end
@@ -32,6 +32,7 @@ module Danger
32
32
  describe 'notify_if_modified_file_is_less_than' do
33
33
  it 'Should only fails on modified files' do
34
34
  @dangerfile.git.stubs(:modified_files).returns(['AppDelegate.swift'])
35
+ @dangerfile.git.stubs(:added_files).returns([])
35
36
 
36
37
  @project_mock.stubs(:coverage_files).returns(
37
38
  [
@@ -52,6 +53,7 @@ module Danger
52
53
 
53
54
  it 'Should not fail if coverage is higher than parameter' do
54
55
  @dangerfile.git.stubs(:modified_files).returns(['AppDelegate.swift'])
56
+ @dangerfile.git.stubs(:added_files).returns([])
55
57
 
56
58
  @project_mock.stubs(:coverage_files).returns(
57
59
  [
@@ -66,6 +68,7 @@ module Danger
66
68
 
67
69
  it 'Should add warning if notify_level is warning' do
68
70
  @dangerfile.git.stubs(:modified_files).returns(['AppDelegate.swift'])
71
+ @dangerfile.git.stubs(:added_files).returns([])
69
72
 
70
73
  @project_mock.stubs(:coverage_files).returns(
71
74
  [
@@ -82,6 +85,28 @@ module Danger
82
85
  ]
83
86
  )
84
87
  end
88
+
89
+ it 'Should count new files' do
90
+ @dangerfile.git.stubs(:modified_files).returns(['AppDelegate.swift'])
91
+ @dangerfile.git.stubs(:added_files).returns(['ViewController.swift'])
92
+
93
+ @project_mock.stubs(:coverage_files).returns(
94
+ [
95
+ mock_file('AppDelegate.swift', 10),
96
+ mock_file('ViewController.swift', 10)
97
+ ]
98
+ )
99
+
100
+ @my_plugin.notify_if_modified_file_is_less_than(minimum_coverage: 50, notify_level: :warning)
101
+
102
+ expect(@dangerfile.status_report[:errors]).to eq([])
103
+ expect(@dangerfile.status_report[:warnings]).to eq(
104
+ [
105
+ 'AppDelegate.swift has less than 50% code coverage',
106
+ 'ViewController.swift has less than 50% code coverage'
107
+ ]
108
+ )
109
+ end
85
110
  end
86
111
 
87
112
  describe 'notify_if_coverage_is_less_than' do
@@ -155,7 +180,11 @@ module Danger
155
180
  [
156
181
  'AppDelegate.swift',
157
182
  'ViewController.swift',
158
- 'ViewController2.swift',
183
+ 'ViewController2.swift'
184
+ ]
185
+ )
186
+ @dangerfile.git.stubs(:added_files).returns(
187
+ [
159
188
  'ViewController3.swift',
160
189
  'ViewController4.swift'
161
190
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: danger-slather
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Mazzo