simplecov-badge 1.0.2 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 160e356fd19f2b82e15304731c2ccbf92ee58602
4
- data.tar.gz: c201e083d23622d1ecda804b09ac27848b318638
3
+ metadata.gz: 63cbd31bade8e277a79de7ad257d991c45e70a0e
4
+ data.tar.gz: 84d6f952d41b24981183d12780f4844c2e703e25
5
5
  SHA512:
6
- metadata.gz: 8402a99f95e4412440ce824be5a96d896b6dca3b2bb3257895543c302e74863de37d374df586d6a456b0bcd772ccaf3e1d7698ef5c1aa20775eb6270c6af866c
7
- data.tar.gz: b5d1b1a94e4ac3bd8df36a0e4a68b9a62caa17e00101d74e321e15e255b8486ef47930ba2cbdecaf69c58fac424b862803b7189ccda756d0735c27161f8f6a4e
6
+ metadata.gz: 63466a277761c6316e75c1b7ab7a7cb69c91c7d236b233a50ba9ddaaeaf8c9464baf87c32057af5339198ec685675286c4b5566b795dd403f1ec6f3ed0b82866
7
+ data.tar.gz: f6434a9dc4d48d036ab6a89405590666d81408b16287d21da8124578e11bf9d80b8249afa45ab09b39a9f93f06508d3ed2b0b71195bd697426ff80245dd8b7a5
data/README.md CHANGED
@@ -1,17 +1,104 @@
1
1
  # Badge formatter for SimpleCov
2
- ====================================
3
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)
4
3
  [ ![Code Coverage for matthew342/simplecov-badge](http://matthew342.github.io/simplecov-badge/coverage/coverage-badge.png)](http://matthew342.github.io/simplecov-badge/coverage/index.html)
5
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/).
6
+
6
7
  ***Note: To learn more about SimpleCov, check out the main repo at https://github.com/colszowka/simplecov***
7
8
 
8
- Generates coverage badges from SimpleCov using ImageMagick.
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](http://matthew342.github.io/simplecov-badge/coverage/coverage-badge.png)
14
+ ####Including Group sub-badges and timestamp
15
+ ----------
16
+ ![Code Coverage for matthew342/simplecov-badge](http://matthew342.github.io/simplecov-badge/coverage-badge-example.png)
17
+
18
+ ## Installation
19
+ # In your gemfile
20
+ gem 'simplecov-badge', :require => false
21
+
22
+ ## Usage
23
+ # Wherever your SimpleCov.start block is (spec_helper.rb, test_helper.rb, or .simplecov)
24
+ SimpleCov.start 'rails' do
25
+ require 'simplecov-badge'
26
+ # add your normal SimpleCov configs
27
+ add_filter "/app/admin/"
28
+ # configure any options you want for SimpleCov::Formatter::BadgeFormatter
29
+ SimpleCov::Formatter::BadgeFormatter.generate_groups = true
30
+ SimpleCov::Formatter::BadgeFormatter.strength_foreground = true
31
+ SimpleCov::Formatter::BadgeFormatter.timestamp = true
32
+ # call SimpleCov::Formatter::BadgeFormatter after the normal HTMLFormatter
33
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
34
+ SimpleCov::Formatter::HTMLFormatter,
35
+ SimpleCov::Formatter::BadgeFormatter,
36
+ ]
37
+ end
38
+
39
+ ## Use with your CI
40
+ 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.
41
+
42
+ ####If you want to store your coverage reports in GitHub Pages
43
+ --------
44
+ You can do something like this as the last step in your build/deploy (assuming you've already created an orphan gh-pages branch):
45
+
46
+ mkdir ../tmp-coverage
47
+ cp -r coverage/ ../tmp-coverage/
48
+ git config --global user.email "CI@example.com"
49
+ git config --global user.name "CI Server"
50
+ cd ..
51
+ git clone --branch gh-pages git@github.com:matthew342/simplecov-badge.git gh-pages-clone
52
+ cd gh-pages-clone
53
+ cp -r ../tmp-coverage/. .
54
+ rm -r ../tmp-coverage
55
+ git add .
56
+ git commit -a -m "CI: Coverage for $COMMIT_ID"
57
+ git push origin gh-pages:gh-pages
58
+
59
+ REMEMBER Gitub Pages are public - so if your repo is private pushing somewhere else might be a better idea.
60
+
61
+ ####If you want to store your coverage reports in S3
62
+ --------
63
+ 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).
64
+
65
+ ## Options
66
+ Set these in your SimpleCov.start block - see Usage section.
67
+ <table>
68
+ <tr>
69
+ <td>Name</td>
70
+ <td>Description</td>
71
+ <td>Default</td>
72
+ </tr>
73
+ <tr><td>strength_indicator_title</td><td>Title for right portion of badge, which can be colored according to coverage strength (i.e. >1 hits/line = green, == 1 hits/line = yellow, <1 hits/line = red)</td><td> 'TEST COVERAGE'</td></tr>
74
+ <tr><td>generate_groups </td><td>Whether to generate sub-badges for each group under the main badge</td><td>true</td></tr>
75
+ <tr><td>timestamp </td><td>Stick a timestamp on the bottom of the badge</td><td> false</td></tr>
76
+ <tr><td>green </td><td>The specific color to be used for 'green'</td><td> '#4fb151'</td></tr>
77
+ <tr><td>yellow </td><td>The specific color to be used for 'yellow'</td><td> '#ded443'</td></tr>
78
+ <tr><td>red </td><td>The specific color to be used for 'red'</td><td> '#a23e3f'</td></tr>
79
+ <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>
80
+ <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>
81
+ <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>
82
+ <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>
83
+ <tr><td>badge_height </td><td>Height of the badge</td><td> 25</td></tr>
84
+ <tr><td>use_strength_color </td><td>Whether to color-code the name portion of the badge according to the coverage strength (NOT the covered percentage)</td><td> true</td></tr>
85
+ <tr><td>strength_foreground </td><td>Whether to color the foreground instead of the background when coloring the name portion of the badge according to the coverage strength</td><td> false</td></tr>
86
+ <tr><td>group_number_font </td><td>Same as above, but for group sub-badges</td><td> 'Helvetica-Narrow-Bold'</td></tr>
87
+ <tr><td>group_number_font_size </td><td>Same as above, but for group sub-badges</td><td> 20</td></tr>
88
+ <tr><td>group_name_font </td><td>Same as above, but for group sub-badges</td><td> 'Helvetica-Bold'</td></tr>
89
+ <tr><td>group_name_font_size </td><td>Same as above, but for group sub-badges</td><td> 17</td></tr>
90
+ <tr><td>group_badge_height </td><td>Same as above, but for group sub-badges</td><td> 25</td></tr>
91
+ <tr><td>use_strength_color_for_group_name </td><td>Same as above, but for group sub-badges</td><td> true</td></tr>
92
+ <tr><td>group_strength_foreground </td><td>Same as above, but for group sub-badges</td><td> true</td></tr>
93
+ </table>
9
94
 
95
+ #### Note on Patches/Pull Requests
10
96
 
11
- Note on Patches/Pull Requests
12
- -----------------------------
97
+ Pull requests are much appreciated - but please add tests!
98
+ Run the test suite by cloning down the repo, then:
13
99
 
14
- \[to come\]
100
+ bundle install
101
+ rspec
15
102
 
16
103
 
17
104
  Copyright
@@ -7,14 +7,14 @@ ImageMagickError = Class.new(StandardError)
7
7
 
8
8
  class SimpleCov::Formatter::BadgeFormatter
9
9
  # Set up config variables.
10
- options = {:strength_indicator_title => 'TEST COVERAGE', :generate_groups => true, :timestamp => false, :green => '#4fb151',
10
+ options = {:badge_title => 'TEST COVERAGE', :generate_groups => true, :timestamp => false, :green => '#4fb151',
11
11
  :yellow => '#ded443', :red => '#a23e3f', :number_font => 'Helvetica-Narrow-Bold',
12
12
  :number_font_size => 20, :name_font => 'Helvetica', :name_font_size => 17,
13
- :badge_height => 25, :use_strength_color => true, :strength_foreground => false,
13
+ :badge_height => 27, :strength_foreground => false,
14
14
  :group_number_font => 'Helvetica-Narrow-Bold', :group_number_font_size => 20,
15
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}
16
+ :group_badge_height => 27, :group_strength_foreground => true, :color_code_title => true,
17
+ :group_color_code_title => true}
18
18
 
19
19
  # set up class variables and getters/setters
20
20
  options.each do |opt,v|
@@ -31,6 +31,7 @@ class SimpleCov::Formatter::BadgeFormatter
31
31
  check_imagemagick
32
32
  generate_header_badge(result)
33
33
  generate_group_badges(result) if @@generate_groups
34
+ generate_timestamp if @@timestamp
34
35
  puts output_message(result)
35
36
  rescue ImageMagickError => e
36
37
  puts e
@@ -43,10 +44,24 @@ class SimpleCov::Formatter::BadgeFormatter
43
44
  def generate_header_badge(result)
44
45
  overall_cov = result.source_files.covered_percent.round(0)
45
46
  overall_strength = result.covered_strength.round(0)
47
+ generator(overall_cov, overall_strength, false)
48
+ end
49
+
50
+ def generate_group_badges(result)
51
+ result.groups.each do |name, files|
52
+ cov = files.covered_percent.round(0)
53
+ strength = files.covered_strength.round(0)
54
+ generator(cov, strength, name)
55
+ end
56
+ end
57
+
58
+ def generator(cov, strength, group)
46
59
  command = []
47
60
  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}%'\" \
61
+ 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)}\" \
62
+ -gravity center -fill white -draw \"kerning 2 text +2,-1 '#{cov}%'\" \
63
+ -pointsize 10 -font \"#{get_config('number_font', group)}\" \
64
+ -gravity south -fill white -draw \"text 0,-1 'coverage'\" \
50
65
  -alpha set -bordercolor none -border 3 \
51
66
  -gravity North -chop 0x3 \
52
67
  -gravity South -chop 0x3 \
@@ -54,32 +69,45 @@ class SimpleCov::Formatter::BadgeFormatter
54
69
  #{output_path}/tmp.png
55
70
  """
56
71
  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 '#{@@strength_indicator_title}'\" \
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 \\) \
72
+ 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))}\" \
73
+ -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)}\" \
74
+ -draw \"kerning 1 text 4,19 '#{group ? group.upcase : @@badge_title}'\" \
75
+ -gravity West -background white -splice 1x0 \
76
+ -background black -splice 1x0 -trim +repage \
77
+ -gravity West -chop 1x0 -gravity East \
78
+ -background \"#{title_background(cov, strength, get_config('strength_foreground', group), get_config('color_code_title', group))}\" -splice 3x0 \\) \
64
79
  -background none +append #{output_path}/tmp.png
65
80
  """
66
- command[2] = """
67
- convert #{output_path}/tmp.png -format 'roundrectangle 1,1 %[fx:w+4],%[fx:h+#{@@badge_height}] 10,10' \
81
+ command[2] = """
82
+ 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)}\" \
83
+ -gravity Center -fill white -draw \"kerning 2 text 0,-1 '#{strength}'\" \
84
+ -pointsize 10 -font \"#{get_config('number_font', group)}\" \
85
+ -gravity south -fill white -draw \"text 0,-1 'hits/line'\" \
86
+ -alpha set -bordercolor none -border 3 \
87
+ -gravity North -chop 0x3 \
88
+ -gravity South -chop 0x3 \
89
+ -gravity East -chop 3x0 \\) \
90
+ -background none +append #{output_path}/tmp.png
91
+ """
92
+ command[3] = """
93
+ convert #{output_path}/tmp.png -format 'roundrectangle 1,1 %[fx:w+4],%[fx:h+4] 10,10' \
68
94
  -write info:#{output_path}/tmp.mvg \
69
95
  -alpha set -bordercolor none -border 3 \
70
96
  \\( +clone -alpha transparent -background none \
71
97
  -fill white -stroke none -strokewidth 0 -draw @#{output_path}/tmp.mvg \\) \
72
98
  -compose DstIn -composite \
73
- -gravity South -chop 0x3 #{output_path}/tmp.png
99
+ -gravity South -chop 0x1 #{output_path}/tmp.png
74
100
  """
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
101
+ command[4] = """
102
+ convert #{output_path}/tmp.png #{output_path}/coverage-badge.png
103
+ """
104
+ command[5] = """
105
+ convert #{output_path}/coverage-badge.png #{output_path}/tmp.png -background none -gravity center -append #{output_path}/coverage-badge.png
80
106
  """
81
107
  begin
82
- command.each do |cmd|
108
+ command.each_with_index do |cmd, i|
109
+ next i if i == 4 unless group == false
110
+ next i if i == 5 if group == false
83
111
  output = `#{cmd}`
84
112
  check_status(output)
85
113
  end
@@ -89,70 +117,33 @@ class SimpleCov::Formatter::BadgeFormatter
89
117
  end
90
118
  end
91
119
 
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)
120
+ def generate_timestamp
121
+ timestamp_cmd = """
122
+ convert #{output_path}/coverage-badge.png -alpha set -bordercolor none -border 3 \
123
+ -gravity North -chop 0x3 \
124
+ -gravity East -chop 3x0 \
125
+ -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
126
+ """
127
+ output = `#{timestamp_cmd}`
128
+ check_status(output)
129
+ end
130
+
131
+ # getter method for config variables - abstracts group or main badge from generator
132
+ def get_config(name, group)
133
+ if group
134
+ eval("@@group_#{name}")
135
+ else
136
+ eval("@@#{name}")
147
137
  end
148
138
  end
149
-
139
+
150
140
  # checks if imagemagick is installed and working
151
141
  def check_imagemagick
152
142
  output = `convert`
153
143
  raise ImageMagickError, "ImageMagick doesn't appear to be installed." unless $?.to_i == 0
154
144
  end
155
145
 
146
+ # Checks exit status after running a command with backtick
156
147
  def check_status(output)
157
148
  raise ImageMagickError, "ImageMagick exited with an error. It said:\n #{output}" unless $?.to_i == 0
158
149
  end
@@ -165,11 +156,37 @@ class SimpleCov::Formatter::BadgeFormatter
165
156
  SimpleCov.coverage_path
166
157
  end
167
158
 
159
+ def title_background(cov, strength, foreground, use)
160
+ if !use
161
+ 'silver'
162
+ elsif foreground
163
+ 'transparent'
164
+ elsif cov > 90 and strength > 1
165
+ @@green
166
+ elsif cov > 80 and strength >= 1
167
+ @@yellow
168
+ else
169
+ @@red
170
+ end
171
+ end
172
+
173
+ def title_foreground(cov, strength, foreground, use)
174
+ if !foreground or !use
175
+ 'white'
176
+ elsif cov > 90 and strength > 1
177
+ @@green
178
+ elsif cov > 80 and strength >= 1
179
+ @@yellow
180
+ else
181
+ @@red
182
+ end
183
+ end
184
+
168
185
  def strength_background(strength, foreground)
169
186
  if foreground
170
187
  'transparent'
171
188
  else
172
- strength_color(strength, @@use_strength_color)
189
+ strength_color(strength)
173
190
  end
174
191
  end
175
192
 
@@ -177,7 +194,7 @@ class SimpleCov::Formatter::BadgeFormatter
177
194
  unless foreground
178
195
  'white'
179
196
  else
180
- strength_color(strength, @@use_strength_color)
197
+ strength_color(strength)
181
198
  end
182
199
  end
183
200
 
@@ -191,17 +208,13 @@ class SimpleCov::Formatter::BadgeFormatter
191
208
  end
192
209
  end
193
210
 
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
211
+ def strength_color(covered_strength)
212
+ if covered_strength > 1
213
+ @@green
214
+ elsif covered_strength == 1
215
+ @@yellow
203
216
  else
204
- 'silver'
217
+ @@red
205
218
  end
206
219
  end
207
220
  end
@@ -1,7 +1,7 @@
1
1
  module SimpleCov
2
2
  module Formatter
3
3
  class BadgeFormatter
4
- VERSION = "1.0.2"
4
+ VERSION = "2.0.0"
5
5
  end
6
6
  end
7
7
  end
@@ -30,9 +30,11 @@ describe SimpleCov::Formatter::BadgeFormatter do
30
30
  @obj.stub(:check_imagemagick).and_return(0)
31
31
  @obj.stub(:generate_group_badges).and_return(0)
32
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')
33
+ @obj.stub(:strength_color).and_return(@obj.class.green)
34
+ @obj.stub(:strength_foreground).and_return('white')
35
+ @obj.stub(:strength_background).and_return(@obj.class.green)
36
+ @obj.stub(:title_foreground).and_return('white')
37
+ @obj.stub(:title_background).and_return(@obj.class.green)
36
38
  @obj.stub(:output_path).and_return('.')
37
39
  result = double('Result')
38
40
  result.stub_chain('source_files.covered_percent').and_return(50)
@@ -44,30 +46,51 @@ describe SimpleCov::Formatter::BadgeFormatter do
44
46
  end
45
47
 
46
48
  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
49
+ SimpleCov::Formatter::BadgeFormatter.generate_groups = true
50
+ result = double('Result')
51
+ result.stub(:command_name) {'test'}
52
+ files = double("files")
53
+ files.stub('covered_percent').and_return(50)
54
+ files.stub('covered_strength').and_return(90)
55
+ groups = {'group1' => files, 'group2' => files}
56
+ result.stub_chain('groups').and_return(groups)
57
+ @obj.stub(:check_imagemagick).and_return(0)
58
+ @obj.stub(:generate_header_badge).and_return(0)
59
+ @obj.stub(:coverage_color).and_return('green')
60
+ @obj.stub(:strength_color).and_return('green')
61
+ @obj.stub(:strength_foreground).and_return('white')
62
+ @obj.stub(:strength_background).and_return(@obj.class.green)
63
+ @obj.stub(:title_foreground).and_return('white')
64
+ @obj.stub(:title_background).and_return(@obj.class.green)
65
+ @obj.stub(:output_path).and_return('.')
66
+ expect{ @obj.format(result) }.to change{File.size('coverage-badge.png')}
67
+ $?.success?.should eq(true)
68
+ end
65
69
 
66
70
  describe 'generation helpers' do
67
71
  # Calling all these private methods here is a little ugly; but it seemed like the
68
72
  # right thing in this case - testing these through public methods (format) just
69
73
  # isn't possible
70
-
74
+ describe 'title_background' do
75
+ it 'returns transparent if foreground and lowest color if not' do
76
+ @obj.instance_eval{title_background(60, 1, true, true)}.should eq('transparent')
77
+ @obj.instance_eval{title_background(91,1.1, false, true)}.should eq(@obj.class.green)
78
+ @obj.instance_eval{title_background(91,1, false, true)}.should eq(@obj.class.yellow)
79
+ @obj.instance_eval{title_background(65,1, false, true)}.should eq(@obj.class.red)
80
+ @obj.instance_eval{title_background(90,1, false, false)}.should eq('silver')
81
+ end
82
+ end
83
+
84
+ describe 'title_foreground' do
85
+ it 'returns white unless foreground and lowest color otherwise' do
86
+ @obj.instance_eval{title_foreground(60,2,false, true)}.should eq('white')
87
+ @obj.instance_eval{title_foreground(91,2,true, true)}.should eq(@obj.class.green)
88
+ @obj.instance_eval{title_foreground(85,2,true, true)}.should eq(@obj.class.yellow)
89
+ @obj.instance_eval{title_foreground(85,0.5,true, true)}.should eq(@obj.class.red)
90
+ @obj.instance_eval{title_foreground(90,1, false, false)}.should eq('white')
91
+ end
92
+ end
93
+
71
94
  describe 'strength_background' do
72
95
  it 'returns transparent if foreground and strength_color if not' do
73
96
  @obj.instance_eval{strength_background(60, true)}.should eq('transparent')
@@ -94,10 +117,9 @@ describe SimpleCov::Formatter::BadgeFormatter do
94
117
 
95
118
  describe 'strength_color' do
96
119
  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')
120
+ @obj.instance_eval{strength_color(1.1)}.should eq(@obj.class.green)
121
+ @obj.instance_eval{strength_color(1)}.should eq(@obj.class.yellow)
122
+ @obj.instance_eval{strength_color(0.9)}.should eq(@obj.class.red)
101
123
  end
102
124
  end
103
125
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplecov-badge
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Hale