simplecov-badge 1.0.0
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 +26 -0
- data/.rspec +2 -0
- data/Gemfile +14 -0
- data/LICENSE +20 -0
- data/README.md +20 -0
- data/Rakefile +16 -0
- data/lib/simplecov-badge.rb +210 -0
- data/lib/simplecov-badge/version.rb +7 -0
- data/simplecov-badge.gemspec +25 -0
- data/spec/simplecov-badge_spec.rb +111 -0
- data/spec/spec_helper.rb +15 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f48429e4d889d1ff70ee5f5005886a7b72bd8d26
|
4
|
+
data.tar.gz: dbc14c945f52b4c70229fa27e7be7c59f0481891
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 1de96fe3b56ae991834842362ba979a13e1a43f2cbf5ce24981a1ecbf7539f4d128155f9e36b4c60f13ebd25e84a9150635c72dc0c5ae46cc7ce45ca28d7f221
|
7
|
+
data.tar.gz: 222bb81ce5c55af0a213a4e815f4c206f83c6f05c493e3134d028f37f99fad4cb7217c7a0e599eb1b6ecf4da0d03c1b72d59aff0976ba333d037a8b523118ed8
|
data/.document
ADDED
data/.gitignore
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
.rvmrc
|
2
|
+
.bundle
|
3
|
+
Gemfile.lock
|
4
|
+
|
5
|
+
## MAC OS
|
6
|
+
.DS_Store
|
7
|
+
|
8
|
+
## TEXTMATE
|
9
|
+
*.tmproj
|
10
|
+
tmtags
|
11
|
+
|
12
|
+
## EMACS
|
13
|
+
*~
|
14
|
+
\#*
|
15
|
+
.\#*
|
16
|
+
|
17
|
+
## VIM
|
18
|
+
*.swp
|
19
|
+
|
20
|
+
## PROJECT::GENERAL
|
21
|
+
coverage
|
22
|
+
rdoc
|
23
|
+
pkg
|
24
|
+
.sass-cache
|
25
|
+
|
26
|
+
## PROJECT::SPECIFIC
|
data/.rspec
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gemspec
|
4
|
+
|
5
|
+
group :development do
|
6
|
+
# Use local copy of simplecov in development when checked out, fetch from git otherwise
|
7
|
+
if File.directory?(File.dirname(__FILE__) + '/../simplecov')
|
8
|
+
gem 'simplecov', :path => File.dirname(__FILE__) + '/../simplecov'
|
9
|
+
else
|
10
|
+
gem 'simplecov', :git => 'https://github.com/colszowka/simplecov'
|
11
|
+
end
|
12
|
+
|
13
|
+
gem 'rspec'
|
14
|
+
end
|
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,20 @@
|
|
1
|
+
# Badge formatter for SimpleCov
|
2
|
+
====================================
|
3
|
+
[ ![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)
|
4
|
+
[ ![Code Coverage for matthew342/simplecov-badge](http://http://matthew342.github.io/simplecov-badge/coverage/coverage-badge.png)](http://matthew342.github.io/simplecov-badge/coverage/index.html)
|
5
|
+
***Note: To learn more about SimpleCov, check out the main repo at https://github.com/colszowka/simplecov***
|
6
|
+
|
7
|
+
Generates coverage badges from SimpleCov using ImageMagick.
|
8
|
+
|
9
|
+
|
10
|
+
Note on Patches/Pull Requests
|
11
|
+
-----------------------------
|
12
|
+
|
13
|
+
\[to come\]
|
14
|
+
|
15
|
+
|
16
|
+
Copyright
|
17
|
+
---------
|
18
|
+
Adapted from [simplecov-html](https://github.com/colszowka/simplecov-html).
|
19
|
+
Thanks to [Christoph Olszowka](https://github.com/colszowka).
|
20
|
+
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,210 @@
|
|
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
|
+
ImageMagickError = Class.new(StandardError)
|
7
|
+
|
8
|
+
class SimpleCov::Formatter::BadgeFormatter
|
9
|
+
# Set up config variables.
|
10
|
+
options = {:generate_groups => true, :timestamp => false, :green => '#4fb151',
|
11
|
+
:yellow => '#ded443', :red => '#a23e3f', :number_font => 'Helvetica-Narrow-Bold',
|
12
|
+
:number_font_size => 20, :name_font => 'Helvetica', :name_font_size => 17,
|
13
|
+
:badge_height => 25, :use_strength_color => true, :strength_foreground => false,
|
14
|
+
:group_number_font => 'Helvetica-Narrow-Bold', :group_number_font_size => 20,
|
15
|
+
:group_name_font => 'Helvetica-Bold', :group_name_font_size => 17,
|
16
|
+
:group_badge_height => 25, :use_strength_color_for_group_name => true,
|
17
|
+
:group_strength_foreground => true}
|
18
|
+
|
19
|
+
# set up class variables and getters/setters
|
20
|
+
options.each do |opt,v|
|
21
|
+
set = "@@#{opt} = v"
|
22
|
+
getter = "def self.#{opt}; @@#{opt}; end;"
|
23
|
+
setter = "def self.#{opt}=(value); @@#{opt} = value; end;"
|
24
|
+
eval(set)
|
25
|
+
eval(getter)
|
26
|
+
eval(setter)
|
27
|
+
end
|
28
|
+
|
29
|
+
def format(result)
|
30
|
+
begin
|
31
|
+
check_imagemagick
|
32
|
+
generate_header_badge(result)
|
33
|
+
generate_group_badges(result) if @@generate_groups
|
34
|
+
puts output_message(result)
|
35
|
+
rescue ImageMagickError => e
|
36
|
+
puts e
|
37
|
+
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
|
+
command = []
|
47
|
+
command[0] = """
|
48
|
+
convert -size 52x#{@@badge_height} xc:'#{coverage_color(overall_cov)}' -pointsize #{@@number_font_size} -font '#{@@number_font}' \
|
49
|
+
-gravity east -fill white -draw \"kerning 2 text +2,+2 '#{overall_cov}%'\" \
|
50
|
+
-alpha set -bordercolor none -border 3 \
|
51
|
+
-gravity North -chop 0x3 \
|
52
|
+
-gravity South -chop 0x3 \
|
53
|
+
-gravity West -chop 3x0 \
|
54
|
+
#{output_path}/tmp.png
|
55
|
+
"""
|
56
|
+
command[1] = """
|
57
|
+
convert #{output_path}/tmp.png \\( -size 237x#{@@badge_height} xc:'#{strength_background(overall_strength, @@strength_foreground)}' \
|
58
|
+
-pointsize #{@@name_font_size} -fill '#{strength_foreground(overall_strength, @@strength_foreground)}' -font '#{@@name_font}' \
|
59
|
+
-draw \"kerning 1 text 4,19 'OVERALL STRENGTH'\" \
|
60
|
+
-gravity West \
|
61
|
+
-background white -splice 1x0 -background black -splice 1x0 \
|
62
|
+
-trim +repage -gravity West -chop 1x0 -gravity East \
|
63
|
+
-background '#{strength_background(overall_strength, @@strength_foreground)}' -splice 2x0 \\) \
|
64
|
+
-background none +append #{output_path}/tmp.png
|
65
|
+
"""
|
66
|
+
command[2] = """
|
67
|
+
convert #{output_path}/tmp.png -format 'roundrectangle 1,1 %[fx:w+4],%[fx:h+#{@@badge_height}] 10,10' \
|
68
|
+
-write info:#{output_path}/tmp.mvg \
|
69
|
+
-alpha set -bordercolor none -border 3 \
|
70
|
+
\\( +clone -alpha transparent -background none \
|
71
|
+
-fill white -stroke none -strokewidth 0 -draw @#{output_path}/tmp.mvg \\) \
|
72
|
+
-compose DstIn -composite \
|
73
|
+
-gravity South -chop 0x3 #{output_path}/tmp.png
|
74
|
+
"""
|
75
|
+
command[3] = """
|
76
|
+
convert #{output_path}/tmp.png \\( +clone -alpha extract \
|
77
|
+
\\( -size 5x2 xc:black -draw 'fill white circle 8,8 8,0' -write mpr:arc +delete \\) \
|
78
|
+
\\( mpr:arc -rotate 180 \\) -gravity southeast -composite \\) \
|
79
|
+
-alpha off -compose CopyOpacity -composite #{output_path}/coverage-badge.png
|
80
|
+
"""
|
81
|
+
begin
|
82
|
+
command.each do |cmd|
|
83
|
+
output = `#{cmd}`
|
84
|
+
check_status(output)
|
85
|
+
end
|
86
|
+
ensure
|
87
|
+
system("rm #{output_path}/tmp.mvg")
|
88
|
+
system("rm #{output_path}/tmp.png")
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def generate_group_badges(result)
|
93
|
+
result.groups.each do |name, files|
|
94
|
+
cov = files.covered_percent.round(0)
|
95
|
+
strength = files.covered_strength.round(0)
|
96
|
+
command = []
|
97
|
+
command[0] = """
|
98
|
+
convert -size 52x#{@@group_badge_height} xc:'#{coverage_color(cov)}' -pointsize #{@@group_number_font_size} -font '#{@@group_number_font}' \
|
99
|
+
-gravity east -fill white -draw \"kerning 2 text +2,+2 '#{cov}%'\" \
|
100
|
+
-alpha set -bordercolor none -border 3 \
|
101
|
+
-gravity North -chop 0x3 \
|
102
|
+
-gravity South -chop 0x3 \
|
103
|
+
-gravity East -chop 3x0 #{output_path}/tmp.png
|
104
|
+
"""
|
105
|
+
command[1] = """
|
106
|
+
convert #{output_path}/tmp.png \\( -size 300x#{@@group_badge_height} xc:#{strength_background(strength, @@group_strength_foreground)} \
|
107
|
+
-pointsize #{@@group_name_font_size} -fill '#{strength_foreground(strength, @@group_strength_foreground)}' -font '#{@@group_name_font}' \
|
108
|
+
-draw \"kerning 0.5 text 4,19 '#{name.upcase}'\" \
|
109
|
+
-gravity West -background white -splice 1x0 -background black -splice 1x0 \
|
110
|
+
-trim +repage -gravity West -chop 1x0 -gravity East \
|
111
|
+
-background '#{strength_background(strength, @@group_strength_foreground)}' -splice 2x0 \
|
112
|
+
-alpha set -bordercolor none -border 3 \
|
113
|
+
-gravity North -chop 0x3 -gravity South -chop 0x3 \
|
114
|
+
-strokewidth 2 -format 'stroke white line 1,1 %[fx:w],3' \\) \
|
115
|
+
-background none +append #{output_path}/tmp.png
|
116
|
+
"""
|
117
|
+
command[2] = """
|
118
|
+
convert #{output_path}/tmp.png \\( +clone -alpha extract \
|
119
|
+
\\( -size 5x2 xc:black -draw 'fill white circle 8,8 8,0' -write mpr:arc +delete \\) \
|
120
|
+
\\( mpr:arc -flip \\) -gravity southwest -composite \
|
121
|
+
\\( mpr:arc -rotate 180 \\) -gravity southeast -composite \\) \
|
122
|
+
-alpha off -compose CopyOpacity -composite \
|
123
|
+
#{output_path}/tmp.png
|
124
|
+
"""
|
125
|
+
command[3] = """
|
126
|
+
convert #{output_path}/coverage-badge.png #{output_path}/tmp.png -gravity West -background none -append #{output_path}/coverage-badge.png
|
127
|
+
"""
|
128
|
+
begin
|
129
|
+
command.each_with_index do |cmd, y|
|
130
|
+
next cmd if y == 2 #and i != result.groups.count
|
131
|
+
output = `#{cmd}`
|
132
|
+
check_status(output)
|
133
|
+
end
|
134
|
+
ensure
|
135
|
+
system("rm #{output_path}/tmp.png")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
if @@timestamp
|
139
|
+
timestamp_cmd = """
|
140
|
+
convert #{output_path}/coverage-badge.png -alpha set -bordercolor none -border 3 \
|
141
|
+
-gravity North -chop 0x3 \
|
142
|
+
-gravity East -chop 3x0 \
|
143
|
+
-gravity West -chop 3x0 \\( -background none -font 'Helvetica' label:'Generated #{Time.current.strftime('%m-%d-%y %H:%M UTC')}' \\) -background none -gravity center -append #{output_path}/coverage-badge.png
|
144
|
+
"""
|
145
|
+
output = `#{timestamp_cmd}`
|
146
|
+
check_status(output)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
# checks if imagemagick is installed and working
|
151
|
+
def check_imagemagick
|
152
|
+
output = `convert`
|
153
|
+
raise ImageMagickError, "ImageMagick doesn't appear to be installed." unless $?.to_i == 0
|
154
|
+
end
|
155
|
+
|
156
|
+
def check_status(output)
|
157
|
+
raise ImageMagickError, "ImageMagick exited with an error. It said:\n #{output}" unless $?.to_i == 0
|
158
|
+
end
|
159
|
+
|
160
|
+
def output_message(result)
|
161
|
+
"Coverage badge generated for #{result.command_name} to #{output_path}."
|
162
|
+
end
|
163
|
+
|
164
|
+
def output_path
|
165
|
+
SimpleCov.coverage_path
|
166
|
+
end
|
167
|
+
|
168
|
+
def strength_background(strength, foreground)
|
169
|
+
if foreground
|
170
|
+
'transparent'
|
171
|
+
else
|
172
|
+
strength_color(strength, @@use_strength_color)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def strength_foreground(strength, foreground)
|
177
|
+
unless foreground
|
178
|
+
'white'
|
179
|
+
else
|
180
|
+
strength_color(strength, @@use_strength_color)
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
def coverage_color(covered_percent)
|
185
|
+
if covered_percent > 90
|
186
|
+
@@green
|
187
|
+
elsif covered_percent > 80
|
188
|
+
@@yellow
|
189
|
+
else
|
190
|
+
@@red
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
def strength_color(covered_strength, use)
|
195
|
+
if use
|
196
|
+
if covered_strength > 1
|
197
|
+
@@green
|
198
|
+
elsif covered_strength == 1
|
199
|
+
@@yellow
|
200
|
+
else
|
201
|
+
@@red
|
202
|
+
end
|
203
|
+
else
|
204
|
+
'silver'
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
|
210
|
+
require 'simplecov-badge/version'
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require 'simplecov-badge/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "simplecov-badge"
|
7
|
+
s.version = SimpleCov::Formatter::BadgeFormatter::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/matthew342/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
|
+
|
15
|
+
s.rubyforge_project = "simplecov-badge"
|
16
|
+
|
17
|
+
s.add_development_dependency 'rake'
|
18
|
+
s.add_development_dependency 'sprockets'
|
19
|
+
s.add_development_dependency 'sass'
|
20
|
+
|
21
|
+
s.files = `git ls-files`.split("\n")
|
22
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
23
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
24
|
+
s.require_paths = ["lib"]
|
25
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe SimpleCov::Formatter::BadgeFormatter do
|
4
|
+
before(:all) do
|
5
|
+
@obj = SimpleCov::Formatter::BadgeFormatter.new
|
6
|
+
end
|
7
|
+
|
8
|
+
describe 'format' do
|
9
|
+
it "handles a StandardError" do
|
10
|
+
result = double("result")
|
11
|
+
result.stub(:command_name) {'test'}
|
12
|
+
@obj.stub(:check_imagemagick).and_raise(ImageMagickError, "test phrase")
|
13
|
+
@obj.should_not_receive(:generate_header_badge)
|
14
|
+
@obj.should_not_receive(:generate_group_badges)
|
15
|
+
$stdout.should_receive(:write).at_least(:once)
|
16
|
+
@obj.format(result)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "options" do
|
21
|
+
it 'generates option getter/setters' do
|
22
|
+
SimpleCov::Formatter::BadgeFormatter.generate_groups.should eq(true)
|
23
|
+
SimpleCov::Formatter::BadgeFormatter.generate_groups = false
|
24
|
+
SimpleCov::Formatter::BadgeFormatter.generate_groups.should eq(false)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "badge generation" do
|
29
|
+
it 'should generate header badge' do
|
30
|
+
@obj.stub(:check_imagemagick).and_return(0)
|
31
|
+
@obj.stub(:generate_group_badges).and_return(0)
|
32
|
+
@obj.stub(:coverage_color).and_return('green')
|
33
|
+
@obj.stub(:strength_color).and_return('green')
|
34
|
+
@obj.stub(:strength_foreground).and_return('green')
|
35
|
+
@obj.stub(:strength_background).and_return('transparent')
|
36
|
+
@obj.stub(:output_path).and_return('.')
|
37
|
+
result = double('Result')
|
38
|
+
result.stub_chain('source_files.covered_percent').and_return(50)
|
39
|
+
result.stub('covered_strength').and_return(90)
|
40
|
+
result.stub(:command_name) {'test'}
|
41
|
+
@obj.format(result)
|
42
|
+
$?.success?.should eq(true)
|
43
|
+
File.size('coverage-badge.png')
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should generate group badges' do
|
47
|
+
SimpleCov::Formatter::BadgeFormatter.generate_groups = true
|
48
|
+
result = double('Result')
|
49
|
+
result.stub(:command_name) {'test'}
|
50
|
+
files = double("files")
|
51
|
+
files.stub('covered_percent').and_return(50)
|
52
|
+
files.stub('covered_strength').and_return(90)
|
53
|
+
groups = {'group1' => files, 'group2' => files}
|
54
|
+
result.stub_chain('groups').and_return(groups)
|
55
|
+
@obj.stub(:check_imagemagick).and_return(0)
|
56
|
+
@obj.stub(:generate_header_badge).and_return(0)
|
57
|
+
@obj.stub(:coverage_color).and_return('green')
|
58
|
+
@obj.stub(:strength_color).and_return('green')
|
59
|
+
@obj.stub(:strength_foreground).and_return('green')
|
60
|
+
@obj.stub(:strength_background).and_return('transparent')
|
61
|
+
@obj.stub(:output_path).and_return('.')
|
62
|
+
expect{ @obj.format(result) }.to change{File.size('coverage-badge.png')}
|
63
|
+
$?.success?.should eq(true)
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'generation helpers' do
|
67
|
+
# Calling all these private methods here is a little ugly; but it seemed like the
|
68
|
+
# right thing in this case - testing these through public methods (format) just
|
69
|
+
# isn't possible
|
70
|
+
|
71
|
+
describe 'strength_background' do
|
72
|
+
it 'returns transparent if foreground and strength_color if not' do
|
73
|
+
@obj.instance_eval{strength_background(60, true)}.should eq('transparent')
|
74
|
+
@obj.class.any_instance.should_receive(:strength_color)
|
75
|
+
@obj.instance_eval{strength_background(60, false)}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe 'strength_foreground' do
|
80
|
+
it 'returns strength color if foreground and white if not' do
|
81
|
+
@obj.instance_eval{strength_foreground(60,false)}.should eq('white')
|
82
|
+
@obj.class.any_instance.should_receive(:strength_color)
|
83
|
+
@obj.instance_eval{strength_foreground(60,true)}
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'coverage_color' do
|
88
|
+
it 'returns the correct colors' do
|
89
|
+
@obj.instance_eval{coverage_color(91)}.should eq(@obj.class.green)
|
90
|
+
@obj.instance_eval{coverage_color(81)}.should eq(@obj.class.yellow)
|
91
|
+
@obj.instance_eval{coverage_color(60)}.should eq(@obj.class.red)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe 'strength_color' do
|
96
|
+
it 'returns the correct colors' do
|
97
|
+
@obj.instance_eval{strength_color(1.1, true)}.should eq(@obj.class.green)
|
98
|
+
@obj.instance_eval{strength_color(1, true)}.should eq(@obj.class.yellow)
|
99
|
+
@obj.instance_eval{strength_color(0.9, true)}.should eq(@obj.class.red)
|
100
|
+
@obj.instance_eval{strength_color(0.9, false)}.should eq('silver')
|
101
|
+
end
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
after(:all) do
|
106
|
+
`rm coverage-badge.png`
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
|
111
|
+
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::BadgeFormatter,
|
8
|
+
]
|
9
|
+
end
|
10
|
+
require 'simplecov-badge'
|
11
|
+
|
12
|
+
RSpec.configure do |config|
|
13
|
+
# some (optional) config here
|
14
|
+
|
15
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: simplecov-badge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matt Hale
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-05-16 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
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: sprockets
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sass
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Badge generator for SimpleCov code coverage tool for ruby 1.9+
|
56
|
+
email:
|
57
|
+
- matt.hale.0 at gmail dot com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .document
|
63
|
+
- .gitignore
|
64
|
+
- .rspec
|
65
|
+
- Gemfile
|
66
|
+
- LICENSE
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/simplecov-badge.rb
|
70
|
+
- lib/simplecov-badge/version.rb
|
71
|
+
- simplecov-badge.gemspec
|
72
|
+
- spec/simplecov-badge_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
74
|
+
homepage: https://github.com/matthew342/simplecov-badge
|
75
|
+
licenses: []
|
76
|
+
metadata: {}
|
77
|
+
post_install_message:
|
78
|
+
rdoc_options: []
|
79
|
+
require_paths:
|
80
|
+
- lib
|
81
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
requirements:
|
83
|
+
- - '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '>='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
requirements: []
|
92
|
+
rubyforge_project: simplecov-badge
|
93
|
+
rubygems_version: 2.0.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: Badge generator for SimpleCov code coverage tool for ruby 1.9+
|
97
|
+
test_files:
|
98
|
+
- spec/simplecov-badge_spec.rb
|
99
|
+
- spec/spec_helper.rb
|