shadowbq-simplecov-badge 2.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +30 -0
- data/.rspec +2 -0
- data/Gemfile +8 -0
- data/LICENSE +20 -0
- data/README.md +110 -0
- data/Rakefile +16 -0
- data/lib/shadowbq-simplecov-badge/formatter.rb +219 -0
- data/lib/shadowbq-simplecov-badge/version.rb +7 -0
- data/lib/shadowbq-simplecov-badge.rb +8 -0
- data/shadowbq-simplecov-badge.gemspec +20 -0
- data/spec/simplecov-badge_spec.rb +156 -0
- data/spec/spec_helper.rb +15 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f68f4c0a538c93f83b1b63056604ccd304ad0e10
|
4
|
+
data.tar.gz: 8c41198d23870b6edd38a26aa9363b8b631897fa
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 087fdb374c7f9ffeff96c15957d8789d2ce48b550ab4ff94e519dc577e9b4f06bb9e0f29523453f6770269c9a4f14d1e68964876ea7f44312669ecddb53ebe7d
|
7
|
+
data.tar.gz: 398af7712205387a7e15fb8cb39b593766592663a544cbecd6b093114e3c20e4992862fac2d6c7d7c32e25a2414adc37b7998ae98ac940eefb86f8ce79399609
|
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
.rvmrc
|
2
|
+
.ruby-gemset
|
3
|
+
.ruby-version
|
4
|
+
|
5
|
+
.bundle
|
6
|
+
Gemfile.lock
|
7
|
+
|
8
|
+
## MAC OS
|
9
|
+
.DS_Store
|
10
|
+
|
11
|
+
## TEXTMATE
|
12
|
+
*.tmproj
|
13
|
+
tmtags
|
14
|
+
|
15
|
+
## EMACS
|
16
|
+
*~
|
17
|
+
\#*
|
18
|
+
.\#*
|
19
|
+
|
20
|
+
## VIM
|
21
|
+
*.swp
|
22
|
+
|
23
|
+
## PROJECT::GENERAL
|
24
|
+
coverage
|
25
|
+
rdoc
|
26
|
+
pkg
|
27
|
+
.sass-cache
|
28
|
+
*.gem
|
29
|
+
|
30
|
+
## PROJECT::SPECIFIC
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Matt Hale
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# Badge formatter for SimpleCov
|
2
|
+
[ ![Codeship Status for matthew342/simplecov-badge](https://www.codeship.io/projects/c46ee0e0-9da1-0130-7a9e-0e0ae47480c0/status?branch=master)](https://www.codeship.io/projects/3367)
|
3
|
+
[ ![Code Coverage for matthew342/simplecov-badge](https://raw.github.com/matthew342/simplecov-badge/gh-pages/coverage/coverage-badge.png)](http://matthew342.github.io/simplecov-badge/coverage/index.html)
|
4
|
+
|
5
|
+
Generates coverage badges from SimpleCov using ImageMagick. Great for small private repos that don't want to pay for a [hosted service](https://coveralls.io/). Add the badge to your readme, linked to your coverage report for improved test coverage visibility.
|
6
|
+
|
7
|
+
***Note: To learn more about SimpleCov, check out the main repo at https://github.com/colszowka/simplecov***
|
8
|
+
|
9
|
+
## Examples
|
10
|
+
The left side of the badge shows and is color-coded for the percentage of lines covered. The right side is color-coded for the strength of coverage (in terms of hits/line).
|
11
|
+
####Simple
|
12
|
+
----------
|
13
|
+
![Code Coverage for matthew342/simplecov-badge](https://raw.github.com/matthew342/simplecov-badge/gh-pages/coverage/coverage-badge.png)
|
14
|
+
####Including Group sub-badges and timestamp
|
15
|
+
----------
|
16
|
+
![Code Coverage for matthew342/simplecov-badge](https://raw.github.com/matthew342/simplecov-badge/gh-pages/coverage-badge-example.png)
|
17
|
+
|
18
|
+
## Installation
|
19
|
+
Install [ImageMagick](http://www.imagemagick.org/), then:
|
20
|
+
|
21
|
+
# In your gemfile
|
22
|
+
gem 'simplecov-badge', :require => false
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
# Wherever your SimpleCov.start block is (spec_helper.rb, test_helper.rb, or .simplecov)
|
26
|
+
SimpleCov.start 'rails' do
|
27
|
+
require 'simplecov-badge'
|
28
|
+
# add your normal SimpleCov configs
|
29
|
+
add_filter "/app/admin/"
|
30
|
+
# configure any options you want for SimpleCov::Formatter::BadgeFormatter
|
31
|
+
SimpleCov::Formatter::BadgeFormatter.generate_groups = true
|
32
|
+
SimpleCov::Formatter::BadgeFormatter.strength_foreground = true
|
33
|
+
SimpleCov::Formatter::BadgeFormatter.timestamp = true
|
34
|
+
# call SimpleCov::Formatter::BadgeFormatter after the normal HTMLFormatter
|
35
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
36
|
+
SimpleCov::Formatter::HTMLFormatter,
|
37
|
+
SimpleCov::Formatter::BadgeFormatter,
|
38
|
+
]
|
39
|
+
end
|
40
|
+
|
41
|
+
## Use with your CI
|
42
|
+
Your badge will be generated in the /coverage directory of your project folder. From there, you can push it wherever you like. Two common options are to push to S3 or to push to GitHub Pages.
|
43
|
+
|
44
|
+
####If you want to store your coverage reports in GitHub Pages
|
45
|
+
--------
|
46
|
+
You can do something like this as the last step in your build/deploy (assuming you've already created an orphan gh-pages branch):
|
47
|
+
|
48
|
+
mkdir ../tmp-coverage
|
49
|
+
cp -r coverage/ ../tmp-coverage/
|
50
|
+
git config --global user.email "CI@example.com"
|
51
|
+
git config --global user.name "CI Server"
|
52
|
+
cd ..
|
53
|
+
git clone --branch gh-pages git@github.com:matthew342/simplecov-badge.git gh-pages-clone
|
54
|
+
cd gh-pages-clone
|
55
|
+
cp -r ../tmp-coverage/. .
|
56
|
+
rm -r ../tmp-coverage
|
57
|
+
git add .
|
58
|
+
git commit -a -m "CI: Coverage for $COMMIT_ID"
|
59
|
+
git push origin gh-pages:gh-pages
|
60
|
+
|
61
|
+
REMEMBER Gitub Pages are public - so if your repo is private pushing somewhere else might be a better idea.
|
62
|
+
|
63
|
+
####If you want to store your coverage reports in S3
|
64
|
+
--------
|
65
|
+
Use one of the S3 wrappers for your language to automate pushing the files into an access-controlled S3 bucket. I use the [S3 gem](https://github.com/qoobaa/s3).
|
66
|
+
|
67
|
+
## Options
|
68
|
+
Set these in your SimpleCov.start block - see Usage section.
|
69
|
+
<table>
|
70
|
+
<tr>
|
71
|
+
<td>Name</td>
|
72
|
+
<td>Description</td>
|
73
|
+
<td>Default</td>
|
74
|
+
</tr>
|
75
|
+
<tr><td>badge_title</td><td>Center section of badge</td><td> 'TEST COVERAGE'</td></tr>
|
76
|
+
<tr><td>generate_groups </td><td>Whether to generate sub-badges for each group under the main badge</td><td>true</td></tr>
|
77
|
+
<tr><td>timestamp </td><td>Stick a timestamp on the bottom of the badge</td><td> false</td></tr>
|
78
|
+
<tr><td>green </td><td>The specific color to be used for 'green'</td><td> '#4fb151'</td></tr>
|
79
|
+
<tr><td>yellow </td><td>The specific color to be used for 'yellow'</td><td> '#ded443'</td></tr>
|
80
|
+
<tr><td>red </td><td>The specific color to be used for 'red'</td><td> '#a23e3f'</td></tr>
|
81
|
+
<tr><td>number_font </td><td>The font to use for the coverage percentage (for the main badge)</td><td> 'Helvetica-Narrow-Bold'</td></tr>
|
82
|
+
<tr><td>number_font_size </td><td>Size of font to use for the coverage percentage (for the main badge)</td><td> 20</td></tr>
|
83
|
+
<tr><td>name_font </td><td>The font to use for the name portion of the badge (of the main badge)</td><td> 'Helvetica'</td></tr>
|
84
|
+
<tr><td>name_font_size </td><td>Size of font to use for the name portion (of the main badge)</td><td> 17</td></tr>
|
85
|
+
<tr><td>badge_height </td><td>Height of the badge</td><td> 27</td></tr>
|
86
|
+
<tr><td>strength_foreground </td><td>Whether to color the foreground instead of the background when coloring the strength portion of the badge</td><td> false</td></tr>
|
87
|
+
<tr><td>color_code_title</td><td>Whether to color the middle section of the badge. If true, will be colored according to the lowest color of the coverage and strength sections </td><td>true</td></tr>
|
88
|
+
<tr><td>group_number_font </td><td>Same as above, but for group sub-badges</td><td> 'Helvetica-Narrow-Bold'</td></tr>
|
89
|
+
<tr><td>group_number_font_size </td><td>Same as above, but for group sub-badges</td><td> 18</td></tr>
|
90
|
+
<tr><td>group_name_font </td><td>Same as above, but for group sub-badges</td><td> 'Helvetica-Bold'</td></tr>
|
91
|
+
<tr><td>group_name_font_size </td><td>Same as above, but for group sub-badges</td><td> 15</td></tr>
|
92
|
+
<tr><td>group_badge_height </td><td>Same as above, but for group sub-badges</td><td> 22</td></tr>
|
93
|
+
<tr><td>group_strength_foreground </td><td>Same as above, but for group sub-badges</td><td>false</td></tr>
|
94
|
+
<tr><td>group_color_code_title</td><td>Same as above, but for group sub-badges</td><td> true</td></tr>
|
95
|
+
</table>
|
96
|
+
|
97
|
+
#### Note on Patches/Pull Requests
|
98
|
+
|
99
|
+
Pull requests are much appreciated - but please add tests!
|
100
|
+
Run the test suite by cloning down the repo, then:
|
101
|
+
|
102
|
+
bundle install
|
103
|
+
rspec
|
104
|
+
|
105
|
+
|
106
|
+
Copyright
|
107
|
+
---------
|
108
|
+
Adapted from [simplecov-html](https://github.com/colszowka/simplecov-html).
|
109
|
+
Thanks to [Christoph Olszowka](https://github.com/colszowka).
|
110
|
+
Copyright (c) 2013 Matt Hale. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
# See https://github.com/colszowka/simplecov/issues/171
|
5
|
+
desc "Set permissions on all files so they are compatible with both user-local and system-wide installs"
|
6
|
+
task :fix_permissions do
|
7
|
+
system 'bash -c "find . -type f -exec chmod 644 {} \; && find . -type d -exec chmod 755 {} \;"'
|
8
|
+
end
|
9
|
+
# Enforce proper permissions on each build
|
10
|
+
Rake::Task[:build].prerequisites.unshift :fix_permissions
|
11
|
+
|
12
|
+
require 'rspec/core/rake_task'
|
13
|
+
RSpec::Core::RakeTask.new('spec')
|
14
|
+
|
15
|
+
# If you want to make this the default task
|
16
|
+
task :default => :spec
|
@@ -0,0 +1,219 @@
|
|
1
|
+
ImageMagickError = Class.new(StandardError)
|
2
|
+
|
3
|
+
class SimpleCov::Formatter::ShadowbqBadgeFormatter
|
4
|
+
# Set up config variables.
|
5
|
+
options = {:badge_title => 'TEST COVERAGE', :generate_groups => true, :timestamp => false, :green => '#4fb151',
|
6
|
+
:yellow => '#ded443', :red => '#a23e3f', :number_font => 'Helvetica-Narrow-Bold',
|
7
|
+
:number_font_size => 20, :name_font => 'Helvetica', :name_font_size => 17,
|
8
|
+
:badge_height => 27, :strength_foreground => false,
|
9
|
+
:group_number_font => 'Helvetica-Narrow-Bold', :group_number_font_size => 18,
|
10
|
+
:group_name_font => 'Helvetica-Bold', :group_name_font_size => 15,
|
11
|
+
:group_badge_height => 22, :group_strength_foreground => false, :color_code_title => true,
|
12
|
+
:group_color_code_title => true}
|
13
|
+
|
14
|
+
# set up class variables and getters/setters
|
15
|
+
options.each do |opt,v|
|
16
|
+
set = "@@#{opt} = v"
|
17
|
+
getter = "def self.#{opt}; @@#{opt}; end;"
|
18
|
+
setter = "def self.#{opt}=(value); @@#{opt} = value; end;"
|
19
|
+
eval(set)
|
20
|
+
eval(getter)
|
21
|
+
eval(setter)
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(output = nil)
|
25
|
+
@output = output || STDOUT
|
26
|
+
end
|
27
|
+
|
28
|
+
def format(result)
|
29
|
+
begin
|
30
|
+
check_imagemagick
|
31
|
+
generate_header_badge(result)
|
32
|
+
generate_group_badges(result) if @@generate_groups
|
33
|
+
generate_timestamp if @@timestamp
|
34
|
+
@output.puts output_message(result)
|
35
|
+
rescue ImageMagickError => e
|
36
|
+
@output.puts e.message
|
37
|
+
@output.puts "Simplecov-Badge was unable to generate a badge for #{result.command_name}."
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def generate_header_badge(result)
|
44
|
+
overall_cov = result.source_files.covered_percent.round(0)
|
45
|
+
overall_strength = result.covered_strength.round(0)
|
46
|
+
generator(overall_cov, overall_strength, false)
|
47
|
+
end
|
48
|
+
|
49
|
+
def generate_group_badges(result)
|
50
|
+
result.groups.each do |name, files|
|
51
|
+
cov = files.covered_percent.round(0)
|
52
|
+
strength = files.covered_strength.round(0)
|
53
|
+
generator(cov, strength, name)
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def generator(cov, strength, group)
|
58
|
+
command = []
|
59
|
+
command[0] = """
|
60
|
+
convert -size 52x#{get_config('badge_height', group)} xc:'#{coverage_color(cov)}' -pointsize #{get_config('number_font_size', group)} -font \"#{get_config('number_font', group)}\" \
|
61
|
+
-gravity center -fill white -draw \"kerning 2 text +2,-1 '#{cov}%'\" \
|
62
|
+
-pointsize 10 -font \"#{get_config('number_font', group)}\" \
|
63
|
+
-gravity south -fill white -draw \"text 0,-1 'coverage'\" \
|
64
|
+
-alpha set -bordercolor none -border 3 \
|
65
|
+
-gravity North -chop 0x3 \
|
66
|
+
-gravity South -chop 0x3 \
|
67
|
+
-gravity West -chop 3x0 \
|
68
|
+
#{output_path}/tmp.png
|
69
|
+
"""
|
70
|
+
command[1] = """
|
71
|
+
convert #{output_path}/tmp.png \\( -size 260x#{get_config('badge_height', group)} xc:\"#{title_background(cov, strength, get_config('strength_foreground', group), get_config('color_code_title', group))}\" \
|
72
|
+
-pointsize #{get_config('name_font_size', group)} -fill \"#{title_foreground(cov, strength, get_config('strength_foreground', group), get_config('color_code_title', group))}\" -font \"#{get_config('name_font', group)}\" \
|
73
|
+
-draw \"kerning 1 text #{group ? 2 : 4},#{group ? 16 : 19} '#{group ? group.upcase : @@badge_title}'\" \
|
74
|
+
-gravity West -background white -splice 1x0 \
|
75
|
+
-background black -splice 1x0 -trim +repage \
|
76
|
+
-gravity West -chop 1x0 -gravity East \
|
77
|
+
-background \"#{title_background(cov, strength, get_config('strength_foreground', group), get_config('color_code_title', group))}\" -splice 3x0 \\) \
|
78
|
+
-background none +append #{output_path}/tmp.png
|
79
|
+
"""
|
80
|
+
command[2] = """
|
81
|
+
convert #{output_path}/tmp.png \\( -size 52x#{get_config('badge_height', group)} xc:\"#{strength_background(strength, get_config('strength_foreground', group))}\" -pointsize #{get_config('number_font_size', group)} -font \"#{get_config('number_font', group)}\" \
|
82
|
+
-gravity Center -fill white -draw \"kerning 2 text 0,-1 '#{strength}'\" \
|
83
|
+
-pointsize 10 -font \"#{get_config('number_font', group)}\" \
|
84
|
+
-gravity south -fill white -draw \"text 0,-1 'hits/line'\" \
|
85
|
+
-alpha set -bordercolor none -border 3 \
|
86
|
+
-gravity North -chop 0x3 \
|
87
|
+
-gravity South -chop 0x3 \
|
88
|
+
-gravity East -chop 3x0 \\) \
|
89
|
+
-background none +append #{output_path}/tmp.png
|
90
|
+
"""
|
91
|
+
command[3] = """
|
92
|
+
convert #{output_path}/tmp.png -format 'roundrectangle 1,1 %[fx:w+4],%[fx:h+4] 10,10' \
|
93
|
+
-write info:#{output_path}/tmp.mvg \
|
94
|
+
-alpha set -bordercolor none -border 3 \
|
95
|
+
\\( +clone -alpha transparent -background none \
|
96
|
+
-fill white -stroke none -strokewidth 0 -draw @#{output_path}/tmp.mvg \\) \
|
97
|
+
-compose DstIn -composite \
|
98
|
+
-gravity South -chop 0x1 #{output_path}/tmp.png
|
99
|
+
"""
|
100
|
+
command[4] = """
|
101
|
+
convert #{output_path}/tmp.png #{output_path}/coverage-badge.png
|
102
|
+
"""
|
103
|
+
command[5] = """
|
104
|
+
convert #{output_path}/coverage-badge.png #{output_path}/tmp.png -background none -gravity center -append #{output_path}/coverage-badge.png
|
105
|
+
"""
|
106
|
+
begin
|
107
|
+
command.each_with_index do |cmd, i|
|
108
|
+
next i if i == 4 unless group == false
|
109
|
+
next i if i == 5 if group == false
|
110
|
+
output = `#{cmd}`
|
111
|
+
check_status(output)
|
112
|
+
end
|
113
|
+
ensure
|
114
|
+
system("rm #{output_path}/tmp.mvg")
|
115
|
+
system("rm #{output_path}/tmp.png")
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
def generate_timestamp
|
120
|
+
timestamp_cmd = """
|
121
|
+
convert #{output_path}/coverage-badge.png -alpha set -bordercolor none -border 3 \
|
122
|
+
-gravity North -chop 0x3 \
|
123
|
+
-gravity East -chop 3x0 \
|
124
|
+
-gravity West -chop 3x0 \\( -background none -font 'Helvetica' label:'Generated #{Time.now.strftime('%m-%d-%y %H:%M UTC')}' \\) -background none -gravity center -append #{output_path}/coverage-badge.png
|
125
|
+
"""
|
126
|
+
output = `#{timestamp_cmd}`
|
127
|
+
check_status(output)
|
128
|
+
end
|
129
|
+
|
130
|
+
# getter method for config variables - abstracts group or main badge from generator
|
131
|
+
def get_config(name, group)
|
132
|
+
if group
|
133
|
+
eval("@@group_#{name}")
|
134
|
+
else
|
135
|
+
eval("@@#{name}")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# checks if imagemagick is installed and working
|
140
|
+
def check_imagemagick
|
141
|
+
output = `convert --version`
|
142
|
+
raise ImageMagickError, "ImageMagick doesn't appear to be installed." unless $?.to_i == 0
|
143
|
+
end
|
144
|
+
|
145
|
+
# Checks exit status after running a command with backtick
|
146
|
+
def check_status(output)
|
147
|
+
raise ImageMagickError, "ImageMagick exited with an error. It said:\n #{output}" unless $?.to_i == 0
|
148
|
+
end
|
149
|
+
|
150
|
+
def output_message(result)
|
151
|
+
"Coverage badge generated for #{result.command_name} to #{output_path}."
|
152
|
+
end
|
153
|
+
|
154
|
+
def output_path
|
155
|
+
SimpleCov.coverage_path
|
156
|
+
end
|
157
|
+
|
158
|
+
def title_background(cov, strength, foreground, use)
|
159
|
+
if !use
|
160
|
+
'silver'
|
161
|
+
elsif foreground
|
162
|
+
'transparent'
|
163
|
+
elsif cov > 90 and strength > 1
|
164
|
+
@@green
|
165
|
+
elsif cov > 80 and strength >= 1
|
166
|
+
@@yellow
|
167
|
+
else
|
168
|
+
@@red
|
169
|
+
end
|
170
|
+
end
|
171
|
+
|
172
|
+
def title_foreground(cov, strength, foreground, use)
|
173
|
+
if !foreground or !use
|
174
|
+
'white'
|
175
|
+
elsif cov > 90 and strength > 1
|
176
|
+
@@green
|
177
|
+
elsif cov > 80 and strength >= 1
|
178
|
+
@@yellow
|
179
|
+
else
|
180
|
+
@@red
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def strength_background(strength, foreground)
|
185
|
+
if foreground
|
186
|
+
'transparent'
|
187
|
+
else
|
188
|
+
strength_color(strength)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def strength_foreground(strength, foreground)
|
193
|
+
unless foreground
|
194
|
+
'white'
|
195
|
+
else
|
196
|
+
strength_color(strength)
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def coverage_color(covered_percent)
|
201
|
+
if covered_percent > 90
|
202
|
+
@@green
|
203
|
+
elsif covered_percent > 80
|
204
|
+
@@yellow
|
205
|
+
else
|
206
|
+
@@red
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
def strength_color(covered_strength)
|
211
|
+
if covered_strength > 1
|
212
|
+
@@green
|
213
|
+
elsif covered_strength == 1
|
214
|
+
@@yellow
|
215
|
+
else
|
216
|
+
@@red
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
# Ensure we are using a compatible version of SimpleCov
|
2
|
+
if Gem::Version.new(SimpleCov::VERSION) < Gem::Version.new("0.7.1")
|
3
|
+
raise RuntimeError, "The version of SimpleCov you are using is too old. Please update with `gem install simplecov` or `bundle update simplecov`"
|
4
|
+
end
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
|
7
|
+
require 'shadowbq-simplecov-badge/version'
|
8
|
+
require 'shadowbq-simplecov-badge/formatter.rb'
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'shadowbq-simplecov-badge/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "shadowbq-simplecov-badge"
|
7
|
+
s.version = SimpleCov::Formatter::ShadowbqBadgeFormatter::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Matt Hale"]
|
10
|
+
s.email = ["matt.hale.0 at gmail dot com"]
|
11
|
+
s.homepage = "https://github.com/shadowbq/shadowbq-simplecov-badge"
|
12
|
+
s.summary = %Q{Badge generator for SimpleCov code coverage tool for ruby 1.9+}
|
13
|
+
s.description = %Q{Badge generator for SimpleCov code coverage tool for ruby 1.9+}
|
14
|
+
s.add_development_dependency 'rake'
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
end
|
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SimpleCov::Formatter::ShadowbqBadgeFormatter do
|
4
|
+
before(:each) do
|
5
|
+
@output = double("output").as_null_object
|
6
|
+
@obj = SimpleCov::Formatter::ShadowbqBadgeFormatter.new(@output)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'format' do
|
10
|
+
context "when a StandardError is raised" do
|
11
|
+
before(:each) do
|
12
|
+
@result = double("result")
|
13
|
+
@result.stub(:command_name) {'test'}
|
14
|
+
@obj.stub(:check_imagemagick).and_raise(ImageMagickError, "test phrase")
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'does not call generate_header_badge' do
|
18
|
+
@obj.should_not_receive(:generate_header_badge)
|
19
|
+
@obj.format(@result)
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'does not call generate_group_badges' do
|
23
|
+
@obj.should_not_receive(:generate_group_badges)
|
24
|
+
@obj.format(@result)
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'outputs the error message' do
|
28
|
+
@output.should_receive(:puts).with('test phrase')
|
29
|
+
@obj.format(@result)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'outputs standard error message' do
|
33
|
+
@output.should_receive(:puts).with('Simplecov-Badge was unable to generate a badge for test.')
|
34
|
+
@obj.format(@result)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe "options" do
|
41
|
+
it 'generates option getter/setters' do
|
42
|
+
SimpleCov::Formatter::ShadowbqBadgeFormatter.generate_groups.should eq(true)
|
43
|
+
SimpleCov::Formatter::ShadowbqBadgeFormatter.generate_groups = false
|
44
|
+
SimpleCov::Formatter::ShadowbqBadgeFormatter.generate_groups.should eq(false)
|
45
|
+
SimpleCov::Formatter::ShadowbqBadgeFormatter.timestamp.should eq(false)
|
46
|
+
SimpleCov::Formatter::ShadowbqBadgeFormatter.timestamp = true
|
47
|
+
SimpleCov::Formatter::ShadowbqBadgeFormatter.timestamp.should eq(true)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "badge generation" do
|
52
|
+
it 'should generate header badge' do
|
53
|
+
@obj.stub(:check_imagemagick).and_return(0)
|
54
|
+
@obj.stub(:generate_group_badges).and_return(0)
|
55
|
+
@obj.stub(:coverage_color).and_return('green')
|
56
|
+
@obj.stub(:strength_color).and_return(@obj.class.green)
|
57
|
+
@obj.stub(:strength_foreground).and_return('white')
|
58
|
+
@obj.stub(:strength_background).and_return(@obj.class.green)
|
59
|
+
@obj.stub(:title_foreground).and_return('white')
|
60
|
+
@obj.stub(:title_background).and_return(@obj.class.green)
|
61
|
+
@obj.stub(:output_path).and_return('.')
|
62
|
+
result = double('Result')
|
63
|
+
result.stub_chain('source_files.covered_percent').and_return(50)
|
64
|
+
result.stub('covered_strength').and_return(90)
|
65
|
+
result.stub(:command_name) {'test'}
|
66
|
+
@obj.format(result)
|
67
|
+
$?.success?.should eq(true)
|
68
|
+
File.size('coverage-badge.png')
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should generate group badges' do
|
72
|
+
SimpleCov::Formatter::ShadowbqBadgeFormatter.generate_groups = true
|
73
|
+
result = double('Result')
|
74
|
+
result.stub(:command_name) {'test'}
|
75
|
+
files = double("files")
|
76
|
+
files.stub('covered_percent').and_return(50)
|
77
|
+
files.stub('covered_strength').and_return(90)
|
78
|
+
groups = {'group1' => files, 'group2' => files}
|
79
|
+
result.stub_chain('groups').and_return(groups)
|
80
|
+
@obj.stub(:check_imagemagick).and_return(0)
|
81
|
+
@obj.stub(:generate_header_badge).and_return(0)
|
82
|
+
@obj.stub(:coverage_color).and_return('green')
|
83
|
+
@obj.stub(:strength_color).and_return('green')
|
84
|
+
@obj.stub(:strength_foreground).and_return('white')
|
85
|
+
@obj.stub(:strength_background).and_return(@obj.class.green)
|
86
|
+
@obj.stub(:title_foreground).and_return('white')
|
87
|
+
@obj.stub(:title_background).and_return(@obj.class.green)
|
88
|
+
@obj.stub(:output_path).and_return('.')
|
89
|
+
expect{ @obj.format(result) }.to change{File.size('coverage-badge.png')}
|
90
|
+
$?.success?.should eq(true)
|
91
|
+
end
|
92
|
+
|
93
|
+
describe 'generation helpers' do
|
94
|
+
# Calling all these private methods here is a little ugly; but it seemed like the
|
95
|
+
# right thing in this case - testing these through public methods (format) just
|
96
|
+
# isn't possible
|
97
|
+
describe 'title_background' do
|
98
|
+
it 'returns transparent if foreground and lowest color if not' do
|
99
|
+
@obj.instance_eval{title_background(60, 1, true, true)}.should eq('transparent')
|
100
|
+
@obj.instance_eval{title_background(91,1.1, false, true)}.should eq(@obj.class.green)
|
101
|
+
@obj.instance_eval{title_background(91,1, false, true)}.should eq(@obj.class.yellow)
|
102
|
+
@obj.instance_eval{title_background(65,1, false, true)}.should eq(@obj.class.red)
|
103
|
+
@obj.instance_eval{title_background(90,1, false, false)}.should eq('silver')
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe 'title_foreground' do
|
108
|
+
it 'returns white unless foreground and lowest color otherwise' do
|
109
|
+
@obj.instance_eval{title_foreground(60,2,false, true)}.should eq('white')
|
110
|
+
@obj.instance_eval{title_foreground(91,2,true, true)}.should eq(@obj.class.green)
|
111
|
+
@obj.instance_eval{title_foreground(85,2,true, true)}.should eq(@obj.class.yellow)
|
112
|
+
@obj.instance_eval{title_foreground(85,0.5,true, true)}.should eq(@obj.class.red)
|
113
|
+
@obj.instance_eval{title_foreground(90,1, false, false)}.should eq('white')
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe 'strength_background' do
|
118
|
+
it 'returns transparent if foreground and strength_color if not' do
|
119
|
+
@obj.instance_eval{strength_background(60, true)}.should eq('transparent')
|
120
|
+
@obj.class.any_instance.should_receive(:strength_color)
|
121
|
+
@obj.instance_eval{strength_background(60, false)}
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe 'strength_foreground' do
|
126
|
+
it 'returns strength color if foreground and white if not' do
|
127
|
+
@obj.instance_eval{strength_foreground(60,false)}.should eq('white')
|
128
|
+
@obj.class.any_instance.should_receive(:strength_color)
|
129
|
+
@obj.instance_eval{strength_foreground(60,true)}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'coverage_color' do
|
134
|
+
it 'returns the correct colors' do
|
135
|
+
@obj.instance_eval{coverage_color(91)}.should eq(@obj.class.green)
|
136
|
+
@obj.instance_eval{coverage_color(81)}.should eq(@obj.class.yellow)
|
137
|
+
@obj.instance_eval{coverage_color(60)}.should eq(@obj.class.red)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'strength_color' do
|
142
|
+
it 'returns the correct colors' do
|
143
|
+
@obj.instance_eval{strength_color(1.1)}.should eq(@obj.class.green)
|
144
|
+
@obj.instance_eval{strength_color(1)}.should eq(@obj.class.yellow)
|
145
|
+
@obj.instance_eval{strength_color(0.9)}.should eq(@obj.class.red)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
after(:all) do
|
151
|
+
`rm coverage-badge.png`
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
|
156
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
require 'simplecov'
|
4
|
+
SimpleCov.start do
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
SimpleCov::Formatter::ShadowbqBadgeFormatter,
|
8
|
+
]
|
9
|
+
end
|
10
|
+
require 'shadowbq-simplecov-badge'
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
# some (optional) config here
|
14
|
+
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shadowbq-simplecov-badge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Hale
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Badge generator for SimpleCov code coverage tool for ruby 1.9+
|
28
|
+
email:
|
29
|
+
- matt.hale.0 at gmail dot com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".document"
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rspec"
|
37
|
+
- Gemfile
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- lib/shadowbq-simplecov-badge.rb
|
42
|
+
- lib/shadowbq-simplecov-badge/formatter.rb
|
43
|
+
- lib/shadowbq-simplecov-badge/version.rb
|
44
|
+
- shadowbq-simplecov-badge.gemspec
|
45
|
+
- spec/simplecov-badge_spec.rb
|
46
|
+
- spec/spec_helper.rb
|
47
|
+
homepage: https://github.com/shadowbq/shadowbq-simplecov-badge
|
48
|
+
licenses: []
|
49
|
+
metadata: {}
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.4.8
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: Badge generator for SimpleCov code coverage tool for ruby 1.9+
|
70
|
+
test_files: []
|