danger-slather 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c0c4a2ede587c8cb03b3fef63b3328ed62a03c7c
4
+ data.tar.gz: 8b0ad6fe348f9bc5a4c3684de4c00dce09391242
5
+ SHA512:
6
+ metadata.gz: a5f9dd555b450283e6e9888dfffcc9ec5f827acd32bab5700aaeae36eaeafcaa76bae523248fb549e74e0e9895d19abe5d7ca8de9d2878a75fb2937263c9beb8
7
+ data.tar.gz: 0d72e097ee957bfff4a78181bc96e65d330e5ae9fa665c6bd058c2e042a905b3a42a406b4e528d39f67e71b9a94ce2a38dba2a11beb6dcab9557cbe5f47d322e
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ .yardoc
data/.rubocop.yml ADDED
@@ -0,0 +1,88 @@
1
+ # kind_of? is a good way to check a type
2
+ Style/ClassCheck:
3
+ EnforcedStyle: kind_of?
4
+
5
+ # It's better to be more explicit about the type
6
+ Style/BracesAroundHashParameters:
7
+ Enabled: false
8
+
9
+ # specs sometimes have useless assignments, which is fine
10
+ Lint/UselessAssignment:
11
+ Exclude:
12
+ - '**/spec/**/*'
13
+
14
+ # HoundCI doesn't like this rule
15
+ Style/DotPosition:
16
+ Enabled: false
17
+
18
+ # Cop supports --auto-correct.
19
+ Lint/UnusedBlockArgument:
20
+ Enabled: false
21
+
22
+ # We want to allow class Fastlane::Class
23
+ Style/ClassAndModuleChildren:
24
+ Enabled: false
25
+
26
+ Metrics/AbcSize:
27
+ Max: 60
28
+
29
+ # The %w might be confusing for new users
30
+ Style/WordArray:
31
+ MinSize: 19
32
+
33
+ # raise and fail are both okay
34
+ Style/SignalException:
35
+ Enabled: false
36
+
37
+ # Better too much 'return' than one missing
38
+ Style/RedundantReturn:
39
+ Enabled: false
40
+
41
+ # Having if in the same line might not always be good
42
+ Style/IfUnlessModifier:
43
+ Enabled: false
44
+
45
+ # Configuration parameters: CountComments.
46
+ Metrics/ClassLength:
47
+ Max: 320
48
+
49
+ Metrics/ModuleLength:
50
+ Max: 320
51
+
52
+ Metrics/CyclomaticComplexity:
53
+ Max: 17
54
+
55
+ # Configuration parameters: AllowURI, URISchemes.
56
+ Metrics/LineLength:
57
+ Max: 120
58
+
59
+ # Configuration parameters: CountKeywordArgs.
60
+ Metrics/ParameterLists:
61
+ Max: 10
62
+
63
+ Metrics/PerceivedComplexity:
64
+ Max: 18
65
+
66
+ # Sometimes it's easier to read without guards
67
+ Style/GuardClause:
68
+ Enabled: false
69
+
70
+ # something = if something_else
71
+ # that's confusing
72
+ Style/ConditionalAssignment:
73
+ Enabled: false
74
+
75
+ # Better to have too much self than missing a self
76
+ Style/RedundantSelf:
77
+ Enabled: false
78
+
79
+ Metrics/MethodLength:
80
+ Max: 60
81
+
82
+ # We're not there yet
83
+ Style/Documentation:
84
+ Enabled: false
85
+
86
+ # Adds complexity
87
+ Style/IfInsideElse:
88
+ Enabled: false
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: objective-c
2
+ osx_image: xcode7.3
3
+
4
+ cache:
5
+ directories:
6
+ - bundle
7
+
8
+ rvm:
9
+ - 2.0
10
+ - 2.1.3
11
+ - 2.3.1
12
+
13
+ script:
14
+ - bundle exec rake spec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in danger-slather.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,166 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ danger-slather (0.0.1)
5
+ danger-plugin-api (~> 1.0)
6
+ slather (~> 2.3)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ CFPropertyList (2.3.4)
12
+ activesupport (4.2.7.1)
13
+ i18n (~> 0.7)
14
+ json (~> 1.7, >= 1.7.7)
15
+ minitest (~> 5.1)
16
+ thread_safe (~> 0.3, >= 0.3.4)
17
+ tzinfo (~> 1.1)
18
+ addressable (2.5.0)
19
+ public_suffix (~> 2.0, >= 2.0.2)
20
+ ast (2.3.0)
21
+ claide (1.0.1)
22
+ claide-plugins (0.9.2)
23
+ cork
24
+ nap
25
+ open4 (~> 1.3)
26
+ clamp (0.6.5)
27
+ coderay (1.1.1)
28
+ colored (1.2)
29
+ cork (0.2.0)
30
+ colored (~> 1.2)
31
+ danger (4.0.1)
32
+ claide (~> 1.0)
33
+ claide-plugins (>= 0.9.2)
34
+ colored (~> 1.2)
35
+ cork (~> 0.1)
36
+ faraday (~> 0.9)
37
+ faraday-http-cache (~> 1.0)
38
+ git (~> 1)
39
+ kramdown (~> 1.5)
40
+ octokit (~> 4.2)
41
+ terminal-table (~> 1)
42
+ danger-plugin-api (1.0.0)
43
+ danger (> 2.0)
44
+ diff-lcs (1.2.5)
45
+ faraday (0.10.0)
46
+ multipart-post (>= 1.2, < 3)
47
+ faraday-http-cache (1.3.1)
48
+ faraday (~> 0.8)
49
+ ffi (1.9.14)
50
+ formatador (0.2.5)
51
+ git (1.3.0)
52
+ guard (2.14.0)
53
+ formatador (>= 0.2.4)
54
+ listen (>= 2.7, < 4.0)
55
+ lumberjack (~> 1.0)
56
+ nenv (~> 0.1)
57
+ notiffany (~> 0.0)
58
+ pry (>= 0.9.12)
59
+ shellany (~> 0.0)
60
+ thor (>= 0.18.1)
61
+ guard-compat (1.2.1)
62
+ guard-rspec (4.7.3)
63
+ guard (~> 2.1)
64
+ guard-compat (~> 1.1)
65
+ rspec (>= 2.99.0, < 4.0)
66
+ i18n (0.7.0)
67
+ json (1.8.3)
68
+ kramdown (1.13.1)
69
+ listen (3.0.7)
70
+ rb-fsevent (>= 0.9.3)
71
+ rb-inotify (>= 0.9.7)
72
+ lumberjack (1.0.10)
73
+ metaclass (0.0.4)
74
+ method_source (0.8.2)
75
+ mini_portile2 (2.1.0)
76
+ minitest (5.9.1)
77
+ mocha (1.2.1)
78
+ metaclass (~> 0.0.1)
79
+ multipart-post (2.0.0)
80
+ nanaimo (0.2.2)
81
+ nap (1.1.0)
82
+ nenv (0.3.0)
83
+ nokogiri (1.6.8.1)
84
+ mini_portile2 (~> 2.1.0)
85
+ notiffany (0.1.1)
86
+ nenv (~> 0.1)
87
+ shellany (~> 0.0)
88
+ octokit (4.6.2)
89
+ sawyer (~> 0.8.0, >= 0.5.3)
90
+ open4 (1.3.4)
91
+ parser (2.3.2.0)
92
+ ast (~> 2.2)
93
+ powerpack (0.1.1)
94
+ pry (0.10.4)
95
+ coderay (~> 1.1.0)
96
+ method_source (~> 0.8.1)
97
+ slop (~> 3.4)
98
+ public_suffix (2.0.4)
99
+ rainbow (2.1.0)
100
+ rake (10.5.0)
101
+ rb-fsevent (0.9.8)
102
+ rb-inotify (0.9.7)
103
+ ffi (>= 0.5.0)
104
+ rspec (3.5.0)
105
+ rspec-core (~> 3.5.0)
106
+ rspec-expectations (~> 3.5.0)
107
+ rspec-mocks (~> 3.5.0)
108
+ rspec-core (3.5.4)
109
+ rspec-support (~> 3.5.0)
110
+ rspec-expectations (3.5.0)
111
+ diff-lcs (>= 1.2.0, < 2.0)
112
+ rspec-support (~> 3.5.0)
113
+ rspec-mocks (3.5.0)
114
+ diff-lcs (>= 1.2.0, < 2.0)
115
+ rspec-support (~> 3.5.0)
116
+ rspec-support (3.5.0)
117
+ rubocop (0.45.0)
118
+ parser (>= 2.3.1.1, < 3.0)
119
+ powerpack (~> 0.1)
120
+ rainbow (>= 1.99.1, < 3.0)
121
+ ruby-progressbar (~> 1.7)
122
+ unicode-display_width (~> 1.0, >= 1.0.1)
123
+ ruby-progressbar (1.8.1)
124
+ sawyer (0.8.1)
125
+ addressable (>= 2.3.5, < 2.6)
126
+ faraday (~> 0.8, < 1.0)
127
+ shellany (0.0.1)
128
+ slather (2.3.0)
129
+ activesupport (>= 4.0.2, < 5)
130
+ clamp (~> 0.6)
131
+ nokogiri (~> 1.6.3)
132
+ xcodeproj (>= 0.20, < 2.0.0)
133
+ slop (3.6.0)
134
+ terminal-table (1.7.3)
135
+ unicode-display_width (~> 1.1.1)
136
+ thor (0.19.1)
137
+ thread_safe (0.3.5)
138
+ tzinfo (1.2.2)
139
+ thread_safe (~> 0.1)
140
+ unicode-display_width (1.1.1)
141
+ xcodeproj (1.4.1)
142
+ CFPropertyList (~> 2.3.3)
143
+ activesupport (>= 3)
144
+ claide (>= 1.0.1, < 2.0)
145
+ colored (~> 1.2)
146
+ nanaimo (~> 0.2.0)
147
+ yard (0.9.5)
148
+
149
+ PLATFORMS
150
+ ruby
151
+
152
+ DEPENDENCIES
153
+ bundler (~> 1.3)
154
+ danger-slather!
155
+ guard (~> 2.14)
156
+ guard-rspec (~> 4.7)
157
+ listen (= 3.0.7)
158
+ mocha
159
+ pry
160
+ rake (~> 10.0)
161
+ rspec (~> 3.4)
162
+ rubocop (~> 0.41)
163
+ yard (~> 0.8)
164
+
165
+ BUNDLED WITH
166
+ 1.13.6
data/Guardfile ADDED
@@ -0,0 +1,19 @@
1
+ # A guardfile for making Danger Plugins
2
+ # For more info see https://github.com/guard/guard#readme
3
+
4
+ # To run, use `bundle exec guard`.
5
+
6
+ guard :rspec, cmd: 'bundle exec rspec' do
7
+ require 'guard/rspec/dsl'
8
+ dsl = Guard::RSpec::Dsl.new(self)
9
+
10
+ # RSpec files
11
+ rspec = dsl.rspec
12
+ watch(rspec.spec_helper) { rspec.spec_dir }
13
+ watch(rspec.spec_support) { rspec.spec_dir }
14
+ watch(rspec.spec_files)
15
+
16
+ # Ruby files
17
+ ruby = dsl.ruby
18
+ dsl.watch_spec_files_for(ruby.lib_files)
19
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Bruno Mazzo <mazzo.bruno@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # Danger-slather
2
+
3
+ A [Danger](http://danger.systems/) plugin that show code coverage of a Xcode project and file by file using [Slather](https://github.com/SlatherOrg/slather). Add warnings or fail the build if a minimum coverage are not achieved. It uses Slather Framework for calculate coverage, so it's required to configure the slather object before using it.
4
+
5
+ ## How does it look?
6
+ <table>
7
+ <thead>
8
+ <tr>
9
+ <th width="50"></th>
10
+ <th width="100%">
11
+ 1 Error
12
+ </th>
13
+ </tr>
14
+ </thead>
15
+ <tbody>
16
+ <tr>
17
+ <td><g-emoji alias="no_entry_sign" fallback-src="https://assets-cdn.github.com/images/icons/emoji/unicode/1f6ab.png">🚫</g-emoji></td>
18
+ <td>
19
+ Total coverage less than 80%
20
+ </td>
21
+ </tr>
22
+ </tbody>
23
+ </table>
24
+
25
+ <table>
26
+ <thead>
27
+ <tr>
28
+ <th width="50"></th>
29
+ <th width="100%">
30
+ 1 Warnings
31
+ </th>
32
+ </tr>
33
+ </thead>
34
+ <tbody>
35
+ <tr>
36
+ <td><g-emoji alias="warning" fallback-src="https://assets-cdn.github.com/images/icons/emoji/unicode/26a0.png">⚠️</g-emoji></td>
37
+ <td>AppDelegate.swift has less than 50% code coverage
38
+ </td>
39
+ </tr>
40
+ </tbody>
41
+ </table>
42
+
43
+ ## Code coverage
44
+ Total coverage: 35.0
45
+
46
+ File | Coverage
47
+ -----|-----
48
+ AppDelegate.swift | 10.00
49
+ ViewController.swift | 20.00
50
+ ViewController2.swift | 30.00
51
+ ViewController3.swift | 40.00
52
+ ViewController4.swift | 50.00
53
+ ViewController5.swift | 60.00
54
+ > Powered by [Slather](https://github.com/SlatherOrg/slather)
55
+
56
+ ## Installation
57
+
58
+ $ gem install danger-slather
59
+
60
+ ## Usage
61
+
62
+ Just add this line to your `Dangerfile`:
63
+
64
+ slather.configure("Path/to/my/project.xcodeproj", "MyScheme")
65
+ slather.notify_if_coverage_is_less_than(minimum_coverage: 60)
66
+ slather.notify_if_modified_file_is_less_than(minimum_coverage: 30)
67
+ slather.show_coverage
68
+
69
+ ## Development
70
+
71
+ 1. Clone this repo
72
+ 2. Run `bundle install` to setup dependencies.
73
+ 3. Run `bundle exec rake spec` to run the tests.
74
+ 4. Use `bundle exec guard` to automatically have tests run as you make changes.
75
+ 5. Make your changes.
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
4
+
5
+ RSpec::Core::RakeTask.new(:specs)
6
+
7
+ task default: :specs
8
+
9
+ task :spec do
10
+ Rake::Task['specs'].invoke
11
+ Rake::Task['rubocop'].invoke
12
+ Rake::Task['spec_docs'].invoke
13
+ end
14
+
15
+ desc 'Run RuboCop on the lib/specs directory'
16
+ RuboCop::RakeTask.new(:rubocop) do |task|
17
+ task.patterns = ['lib/**/*.rb', 'spec/**/*.rb']
18
+ end
19
+
20
+ desc 'Ensure that the plugin passes `danger plugins lint`'
21
+ task :spec_docs do
22
+ sh 'bundle exec danger plugins lint'
23
+ end
@@ -0,0 +1,55 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'slather/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'danger-slather'
8
+ spec.version = Slather::VERSION
9
+ spec.authors = ['Bruno Mazzo']
10
+ spec.email = ['mazzo.bruno@gmail.com']
11
+ spec.description = %q{Danger plugin to Slather code coverage framework}
12
+ spec.summary = %q{A Danger plugin that show code coverage of the project and by file.
13
+ Add warnings or fail the build if a minimum coverage
14
+ are not achieved. It uses Slather Framework for calculate
15
+ coverage, so it's required to configurate the slather
16
+ object before using it.}
17
+ spec.homepage = 'https://github.com/BrunoMazzo/danger-slather'
18
+ spec.license = 'MIT'
19
+
20
+ spec.files = `git ls-files`.split($/)
21
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
22
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
23
+ spec.require_paths = ['lib']
24
+
25
+ spec.add_runtime_dependency 'danger-plugin-api', '~> 1.0'
26
+ spec.add_runtime_dependency 'slather', '~> 2.3'
27
+
28
+ # General ruby development
29
+ spec.add_development_dependency 'bundler', '~> 1.3'
30
+ spec.add_development_dependency 'rake', '~> 10.0'
31
+
32
+ # Testing support
33
+ spec.add_development_dependency 'rspec', '~> 3.4'
34
+ spec.add_development_dependency 'mocha', '~> 1.2'
35
+
36
+ # Linting code and docs
37
+ spec.add_development_dependency "rubocop", "~> 0.41"
38
+ spec.add_development_dependency "yard", "~> 0.8"
39
+
40
+ # Makes testing easy via `bundle exec guard`
41
+ spec.add_development_dependency 'guard', '~> 2.14'
42
+ spec.add_development_dependency 'guard-rspec', '~> 4.7'
43
+
44
+ # If you want to work on older builds of ruby
45
+ spec.add_development_dependency 'listen', '3.0.7'
46
+
47
+ # This gives you the chance to run a REPL inside your tests
48
+ # via:
49
+ #
50
+ # require 'pry'
51
+ # binding.pry
52
+ #
53
+ # This will stop test execution and let you inspect the results
54
+ spec.add_development_dependency 'pry', '~> 0.9'
55
+ end
@@ -0,0 +1 @@
1
+ require 'slather/plugin'
@@ -0,0 +1 @@
1
+ require 'slather/gem_version'
@@ -0,0 +1,3 @@
1
+ module Slather
2
+ VERSION = '0.0.1'.freeze
3
+ end
@@ -0,0 +1,147 @@
1
+ require 'slather'
2
+
3
+ module Danger
4
+ # Show code coverage of the project and by file. Add warnings or fail the
5
+ # Build if a minimum coverage are not achieved. It uses Slather Framework for
6
+ # calculate coverage, so it's required to configurate the slather object
7
+ # before using it.
8
+ #
9
+ # @example Require a minimum file coverage of 30%, a project coverage of 60% and show all modified files coverage
10
+ #
11
+ # slather.configure("Path/to/my/project.xcodeproj", "MyScheme")
12
+ # slather.notify_if_coverage_is_less_than(minimum_coverage: 60)
13
+ # slather.notify_if_modified_file_is_less_than(minimum_coverage: 30)
14
+ # slather.show_coverage
15
+ #
16
+ # @see Bruno Mazzo/danger-slather
17
+ # @tags slather, code coverage
18
+ class DangerSlather < Plugin
19
+ # Total coverage of the project
20
+ # @return [Float]
21
+ def total_coverage
22
+ unless @project.nil?
23
+ @total_coverage ||= begin
24
+ total_project_lines = 0
25
+ total_project_lines_tested = 0
26
+ @project.coverage_files.each do |coverage_file|
27
+ total_project_lines_tested += coverage_file.num_lines_tested
28
+ total_project_lines += coverage_file.num_lines_testable
29
+ end
30
+ @total_coverage = (total_project_lines_tested / total_project_lines.to_f) * 100.0
31
+ end
32
+ end
33
+ end
34
+
35
+ # Required method to configure slather. It's required at least the path
36
+ # to the project and the scheme used with code coverage enabled
37
+ # @return [void]
38
+ def configure(xcodeproj_path, scheme, options: {})
39
+ @project = Slather::Project.open(xcodeproj_path)
40
+ @project.scheme = scheme
41
+ @project.workspace = options[:workspace]
42
+ @project.build_directory = options[:build_directory]
43
+ @project.ignore_list = options[:ignore_list]
44
+ @project.ci_service = options[:ci_service]
45
+ @project.coverage_access_token = options[:coverage_access_token]
46
+ @project.coverage_service = options[:coverage_service] || :terminal
47
+ @project.source_directory = options[:source_directory]
48
+ @project.output_directory = options[:output_directory]
49
+ @project.input_format = options[:input_format]
50
+ @project.binary_file = options[:binary_file]
51
+ @project.decimals = options[:decimals]
52
+ @project.configure
53
+ @project.post if options[:post]
54
+ end
55
+
56
+ # Method to check if the coverage of the project is at least a minumum
57
+ # @param options [Hash] a hash with the options
58
+ # @option options [Float] :minimum_coverage the minimum code coverage required
59
+ # @option options [Symbol] :notify_level the level of notification
60
+ # @return [Array<String>]
61
+ def notify_if_coverage_is_less_than(options)
62
+ minimum_coverage = options[:minimum_coverage]
63
+ notify_level = options[:notify_level] || :fail
64
+ if total_coverage < minimum_coverage
65
+ notify_message = "Total coverage less than #{minimum_coverage}%"
66
+ if notify_level == :fail
67
+ fail notify_message
68
+ else
69
+ warn notify_message
70
+ end
71
+ end
72
+ end
73
+
74
+ # Method to check if the coverage of modified files is at least a minumum
75
+ # @param options [Hash] a hash with the options
76
+ # @option options [Float] :minimum_coverage the minimum code coverage required for a file
77
+ # @option options [Symbol] :notify_level the level of notification
78
+ # @return [Array<String>]
79
+ def notify_if_modified_file_is_less_than(options)
80
+ minimum_coverage = options[:minimum_coverage]
81
+ notify_level = options[:notify_level] || :fail
82
+
83
+ modified_files_coverage = @project.coverage_files.select do |file|
84
+ git.modified_files.include? file.source_file_pathname_relative_to_repo_root.to_s
85
+ end
86
+ if modified_files_coverage.count > 0
87
+ files_to_notify = modified_files_coverage.select do |file|
88
+ file.percentage_lines_tested < minimum_coverage
89
+ end
90
+ notify_messages = files_to_notify.map do |file|
91
+ "#{file.source_file_pathname_relative_to_repo_root} has less than #{minimum_coverage}% code coverage"
92
+ end
93
+
94
+ notify_messages.each do |message|
95
+ if notify_level == :fail
96
+ fail message
97
+ else
98
+ warn message
99
+ end
100
+ end
101
+ end
102
+ end
103
+
104
+ # Show a header with the total coverage of the project
105
+ # @return [Array<String>]
106
+ def show_total_coverage
107
+ unless @project.nil?
108
+ markdown "# Coverage #{@project.decimal_f([total_coverage])}%"
109
+ end
110
+ end
111
+
112
+ # Build a coverage markdown table of the modified files coverage
113
+ # @return [String]
114
+ def modified_files_coverage_table
115
+ unless @project.nil?
116
+ line = "File | Coverage\n"
117
+ line << "-----|-----\n"
118
+ @project.coverage_files.each do |coverage_file|
119
+ file_name = coverage_file.source_file_pathname_relative_to_repo_root.to_s
120
+ percentage = @project.decimal_f([coverage_file.percentage_lines_tested])
121
+ line << "#{file_name} | #{percentage}\n"
122
+ end
123
+ return line
124
+ end
125
+ end
126
+
127
+ # Show the table build by modified_files_coverage_table
128
+ # @return [Array<String>]
129
+ def show_modified_files_coverage
130
+ unless @project.nil?
131
+ markdown modified_files_coverage_table
132
+ end
133
+ end
134
+
135
+ # Show a header with the total coverage and coverage table
136
+ # @return [Array<String>]
137
+ def show_coverage
138
+ unless @project.nil?
139
+ line = "## Code coverage\n"
140
+ line << "Total coverage: #{total_coverage}\n\n"
141
+ line << modified_files_coverage_table
142
+ line << '> Powered by [Slather](https://github.com/SlatherOrg/slather)'
143
+ markdown line
144
+ end
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,195 @@
1
+ require File.expand_path('../spec_helper', __FILE__)
2
+
3
+ require 'slather'
4
+
5
+ module Danger
6
+ describe Danger::DangerSlather do
7
+ def mock_file(name, coverage)
8
+ mock("File #{name}") do
9
+ stubs(:source_file_pathname_relative_to_repo_root).returns(name)
10
+ stubs(:num_lines_tested).returns(coverage)
11
+ stubs(:num_lines_testable).returns(100)
12
+ stubs(:percentage_lines_tested).returns(coverage)
13
+ end
14
+ end
15
+
16
+ it 'should be a plugin' do
17
+ expect(Danger::DangerSlather.new(nil)).to be_a Danger::Plugin
18
+ end
19
+
20
+ describe 'with Dangerfile' do
21
+ before do
22
+ @dangerfile = testing_dangerfile
23
+ @my_plugin = @dangerfile.slather
24
+
25
+ @project_mock = Slather::Project.new('')
26
+ @project_mock.stubs(:configure)
27
+ @project_mock.stubs(:post)
28
+ Slather::Project.stubs(:open).returns(@project_mock)
29
+ @my_plugin.configure('XcodeProject.xcodeproj', 'Danger-Slather')
30
+ end
31
+
32
+ describe 'notify_if_modified_file_is_less_than' do
33
+ it 'Should only fails on modified files' do
34
+ @dangerfile.git.stubs(:modified_files).returns(['AppDelegate.swift'])
35
+
36
+ @project_mock.stubs(:coverage_files).returns(
37
+ [
38
+ mock_file('AppDelegate.swift', 10),
39
+ mock_file('ViewController2.swift', 20),
40
+ mock_file('ViewController.swift', 80)
41
+ ]
42
+ )
43
+
44
+ @my_plugin.notify_if_modified_file_is_less_than(minimum_coverage: 50)
45
+
46
+ expect(@dangerfile.status_report[:errors]).to eq(
47
+ [
48
+ 'AppDelegate.swift has less than 50% code coverage'
49
+ ]
50
+ )
51
+ end
52
+
53
+ it 'Should not fail if coverage is higher than parameter' do
54
+ @dangerfile.git.stubs(:modified_files).returns(['AppDelegate.swift'])
55
+
56
+ @project_mock.stubs(:coverage_files).returns(
57
+ [
58
+ mock_file('AppDelegate.swift', 80)
59
+ ]
60
+ )
61
+
62
+ @my_plugin.notify_if_modified_file_is_less_than(minimum_coverage: 50)
63
+
64
+ expect(@dangerfile.status_report[:errors]).to eq([])
65
+ end
66
+
67
+ it 'Should add warning if notify_level is warning' do
68
+ @dangerfile.git.stubs(:modified_files).returns(['AppDelegate.swift'])
69
+
70
+ @project_mock.stubs(:coverage_files).returns(
71
+ [
72
+ mock_file('AppDelegate.swift', 10)
73
+ ]
74
+ )
75
+
76
+ @my_plugin.notify_if_modified_file_is_less_than(minimum_coverage: 50, notify_level: :warning)
77
+
78
+ expect(@dangerfile.status_report[:errors]).to eq([])
79
+ expect(@dangerfile.status_report[:warnings]).to eq(
80
+ [
81
+ 'AppDelegate.swift has less than 50% code coverage'
82
+ ]
83
+ )
84
+ end
85
+ end
86
+
87
+ describe 'notify_if_coverage_is_less_than' do
88
+ it 'Should fails if total coverage is less than minimum' do
89
+ @project_mock.stubs(:coverage_files).returns(
90
+ [
91
+ mock_file('AppDelegate.swift', 10),
92
+ mock_file('ViewController2.swift', 20),
93
+ mock_file('ViewController.swift', 20)
94
+ ]
95
+ )
96
+
97
+ @my_plugin.notify_if_coverage_is_less_than(minimum_coverage: 50)
98
+
99
+ expect(@dangerfile.status_report[:errors]).to eq(
100
+ [
101
+ 'Total coverage less than 50%'
102
+ ]
103
+ )
104
+ end
105
+
106
+ it 'Should not fails if total coverage is greather than minimum' do
107
+ @project_mock.stubs(:coverage_files).returns(
108
+ [
109
+ mock_file('AppDelegate.swift', 50),
110
+ mock_file('ViewController2.swift', 80),
111
+ mock_file('ViewController.swift', 80)
112
+ ]
113
+ )
114
+
115
+ @my_plugin.notify_if_coverage_is_less_than(minimum_coverage: 50)
116
+
117
+ expect(@dangerfile.status_report[:errors]).to eq([])
118
+ end
119
+
120
+ it 'Should not fails if total coverage is greather than minimum and has files with less than total minimum' do
121
+ @project_mock.stubs(:coverage_files).returns(
122
+ [
123
+ mock_file('AppDelegate.swift', 20),
124
+ mock_file('ViewController2.swift', 80),
125
+ mock_file('ViewController.swift', 80)
126
+ ]
127
+ )
128
+
129
+ @my_plugin.notify_if_coverage_is_less_than(minimum_coverage: 50)
130
+
131
+ expect(@dangerfile.status_report[:errors]).to eq([])
132
+ end
133
+
134
+ it 'Should add warning if notify_level is warning' do
135
+ @project_mock.stubs(:coverage_files).returns(
136
+ [
137
+ mock_file('AppDelegate.swift', 10)
138
+ ]
139
+ )
140
+
141
+ @my_plugin.notify_if_coverage_is_less_than(minimum_coverage: 50, notify_level: :warning)
142
+
143
+ expect(@dangerfile.status_report[:errors]).to eq([])
144
+ expect(@dangerfile.status_report[:warnings]).to eq(
145
+ [
146
+ 'Total coverage less than 50%'
147
+ ]
148
+ )
149
+ end
150
+ end
151
+
152
+ describe 'show_coverage' do
153
+ it 'Should add warning if notify_level is warning' do
154
+ @dangerfile.git.stubs(:modified_files).returns(
155
+ [
156
+ 'AppDelegate.swift',
157
+ 'ViewController.swift',
158
+ 'ViewController2.swift',
159
+ 'ViewController3.swift',
160
+ 'ViewController4.swift'
161
+ ]
162
+ )
163
+
164
+ @project_mock.stubs(:coverage_files).returns(
165
+ [
166
+ mock_file('AppDelegate.swift', 10),
167
+ mock_file('ViewController.swift', 20),
168
+ mock_file('ViewController2.swift', 30),
169
+ mock_file('ViewController3.swift', 40),
170
+ mock_file('ViewController4.swift', 50),
171
+ mock_file('ViewController5.swift', 60)
172
+ ]
173
+ )
174
+
175
+ @my_plugin.show_coverage
176
+
177
+ expect(@dangerfile.status_report[:markdowns][0].message).to eq(
178
+ "## Code coverage
179
+ Total coverage: 35.0
180
+
181
+ File | Coverage
182
+ -----|-----
183
+ AppDelegate.swift | 10.00
184
+ ViewController.swift | 20.00
185
+ ViewController2.swift | 30.00
186
+ ViewController3.swift | 40.00
187
+ ViewController4.swift | 50.00
188
+ ViewController5.swift | 60.00
189
+ > Powered by [Slather](https://github.com/SlatherOrg/slather)"
190
+ )
191
+ end
192
+ end
193
+ end
194
+ end
195
+ end
@@ -0,0 +1,62 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $LOAD_PATH.unshift((ROOT + 'lib').to_s)
4
+ $LOAD_PATH.unshift((ROOT + 'spec').to_s)
5
+
6
+ require 'bundler/setup'
7
+ require 'pry'
8
+
9
+ require 'rspec'
10
+ require 'danger'
11
+ require 'mocha'
12
+
13
+ # Use coloured output, it's the best.
14
+ RSpec.configure do |config|
15
+ config.filter_gems_from_backtrace 'bundler'
16
+ config.color = true
17
+ config.tty = true
18
+ config.mock_with :mocha
19
+ end
20
+
21
+ require 'danger_plugin'
22
+
23
+ # These functions are a subset of https://github.com/danger/danger/blob/master/spec/spec_helper.rb
24
+ # If you are expanding these files, see if it's already been done ^.
25
+
26
+ # A silent version of the user interface,
27
+ # it comes with an extra function `.string` which will
28
+ # strip all ANSI colours from the string.
29
+
30
+ # rubocop:disable Lint/NestedMethodDefinition
31
+ def testing_ui
32
+ @output = StringIO.new
33
+ def @output.winsize
34
+ [20, 9999]
35
+ end
36
+
37
+ cork = Cork::Board.new(out: @output)
38
+ def cork.string
39
+ out.string.gsub(/\e\[([;\d]+)?m/, '')
40
+ end
41
+ cork
42
+ end
43
+ # rubocop:enable Lint/NestedMethodDefinition
44
+
45
+ # Example environment (ENV) that would come from
46
+ # running a PR on TravisCI
47
+ def testing_env
48
+ {
49
+ 'HAS_JOSH_K_SEAL_OF_APPROVAL' => 'true',
50
+ 'TRAVIS_PULL_REQUEST' => '800',
51
+ 'TRAVIS_REPO_SLUG' => 'artsy/eigen',
52
+ 'TRAVIS_COMMIT_RANGE' => '759adcbd0d8f...13c4dc8bb61d',
53
+ 'DANGER_GITHUB_API_TOKEN' => '123sbdq54erfsd3422gdfio'
54
+
55
+ }
56
+ end
57
+
58
+ # A stubbed out Dangerfile for use in tests
59
+ def testing_dangerfile
60
+ env = Danger::EnvironmentManager.new(testing_env)
61
+ Danger::Dangerfile.new(env, testing_ui)
62
+ end
metadata ADDED
@@ -0,0 +1,233 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: danger-slather
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Bruno Mazzo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: danger-plugin-api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: slather
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.3'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.4'
83
+ - !ruby/object:Gem::Dependency
84
+ name: mocha
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.2'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.2'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.41'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.41'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '2.14'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '2.14'
139
+ - !ruby/object:Gem::Dependency
140
+ name: guard-rspec
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '4.7'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '4.7'
153
+ - !ruby/object:Gem::Dependency
154
+ name: listen
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - '='
158
+ - !ruby/object:Gem::Version
159
+ version: 3.0.7
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - '='
165
+ - !ruby/object:Gem::Version
166
+ version: 3.0.7
167
+ - !ruby/object:Gem::Dependency
168
+ name: pry
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: '0.9'
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: '0.9'
181
+ description: Danger plugin to Slather code coverage framework
182
+ email:
183
+ - mazzo.bruno@gmail.com
184
+ executables: []
185
+ extensions: []
186
+ extra_rdoc_files: []
187
+ files:
188
+ - ".gitignore"
189
+ - ".rubocop.yml"
190
+ - ".travis.yml"
191
+ - Gemfile
192
+ - Gemfile.lock
193
+ - Guardfile
194
+ - LICENSE.txt
195
+ - README.md
196
+ - Rakefile
197
+ - danger-slather.gemspec
198
+ - lib/danger_plugin.rb
199
+ - lib/danger_slather.rb
200
+ - lib/slather/gem_version.rb
201
+ - lib/slather/plugin.rb
202
+ - spec/slather_spec.rb
203
+ - spec/spec_helper.rb
204
+ homepage: https://github.com/BrunoMazzo/danger-slather
205
+ licenses:
206
+ - MIT
207
+ metadata: {}
208
+ post_install_message:
209
+ rdoc_options: []
210
+ require_paths:
211
+ - lib
212
+ required_ruby_version: !ruby/object:Gem::Requirement
213
+ requirements:
214
+ - - ">="
215
+ - !ruby/object:Gem::Version
216
+ version: '0'
217
+ required_rubygems_version: !ruby/object:Gem::Requirement
218
+ requirements:
219
+ - - ">="
220
+ - !ruby/object:Gem::Version
221
+ version: '0'
222
+ requirements: []
223
+ rubyforge_project:
224
+ rubygems_version: 2.5.1
225
+ signing_key:
226
+ specification_version: 4
227
+ summary: A Danger plugin that show code coverage of the project and by file. Add warnings
228
+ or fail the build if a minimum coverage are not achieved. It uses Slather Framework
229
+ for calculate coverage, so it's required to configurate the slather object before
230
+ using it.
231
+ test_files:
232
+ - spec/slather_spec.rb
233
+ - spec/spec_helper.rb