From 603645b054fd98dd02a9396689e527be5920d4fd Mon Sep 17 00:00:00 2001 From: TheMasterCado <36383948+TheMasterCado@users.noreply.github.com> Date: Fri, 12 Mar 2021 14:41:34 -0500 Subject: [PATCH 1/2] Fix error with the formatter --- lib/simplecov_small_badge/formatter.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/simplecov_small_badge/formatter.rb b/lib/simplecov_small_badge/formatter.rb index 3988dc1..bac27cf 100644 --- a/lib/simplecov_small_badge/formatter.rb +++ b/lib/simplecov_small_badge/formatter.rb @@ -21,7 +21,7 @@ def format(result) end private - + def badge(name, title, percent) percent_txt = percent_text(percent) @image.config_merge(map_image_config(state(percent))) @@ -33,8 +33,8 @@ def percent_text(percent) end def state(covered_percent) - if line_coverage_minimum&.positive? - if covered_percent >= line_coverage_minimum + if SimpleCov.minimum_coverage[:line]&.positive? + if covered_percent >= SimpleCov.minimum_coverage[:line] 'good' else 'bad' From 8af1ac93793733392d545e4a37d1fc775f721993 Mon Sep 17 00:00:00 2001 From: TheMasterCado Date: Mon, 26 Jul 2021 22:55:59 -0400 Subject: [PATCH 2/2] Implement suggested change --- lib/simplecov_small_badge/formatter.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/lib/simplecov_small_badge/formatter.rb b/lib/simplecov_small_badge/formatter.rb index bac27cf..313d23b 100644 --- a/lib/simplecov_small_badge/formatter.rb +++ b/lib/simplecov_small_badge/formatter.rb @@ -33,8 +33,8 @@ def percent_text(percent) end def state(covered_percent) - if SimpleCov.minimum_coverage[:line]&.positive? - if covered_percent >= SimpleCov.minimum_coverage[:line] + if coverage_minimum&.positive? + if covered_percent >= coverage_minimum 'good' else 'bad' @@ -44,6 +44,13 @@ def state(covered_percent) end end + def coverage_minimum + @coverage_minimum ||= begin + minimums = SimpleCov.minimum_coverage + minimums.is_a?(Hash) ? minimums[SimpleCov.primary_coverage] : minimums + end + end + def line_coverage_minimum minimums = SimpleCov.minimum_coverage minimums.is_a?(Hash) ? minimums[:line] : minimums