Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatter errors with undefined method 'positive?' #15

Open
realtradam opened this issue Jan 11, 2021 · 3 comments
Open

Formatter errors with undefined method 'positive?' #15

realtradam opened this issue Jan 11, 2021 · 3 comments

Comments

@realtradam
Copy link

Versions Used:

simplecov-small-badge version: 0.2.4
simplecov version: 0.21.2
ruby version: 2.7.1p83
rails version: 6.0.3.4

Issue:

When running rails test, SimpleCovSmallBadge::Formatter throws the following error

Formatter SimpleCovSmallBadge::Formatter failed with NoMethodError: undefined method `positive?' for [:line]:Array (gems/simplecov-small-badge-0.2.4/lib/simplecov_small_badge/formatter.rb:36:in `state')

with unnecessary parts of the path omitted.

It appears as though at some point simplecov started using a hash for the SimpleCov.minimum_coverage variable and this is causing it to fail. By placing the following code into my config/initializers path in the rails app so that it overwrote the problem method I was able to make the code work. It simply accesses the hash and does the rest as normal

require 'simplecov'
require 'simplecov_small_badge'
SimpleCovSmallBadge::Formatter.class_eval do
  private
  def state(covered_percent)
    if SimpleCov.minimum_coverage[:line]&.positive?
      if covered_percent >= SimpleCov.minimum_coverage[:line]
        'good'
      else
        'bad'
      end
    else
      'unknown'
    end
  end
end

However this is the first time I have ever used this gem, or the simplecov gem so perhaps there is just an issue with my configuration. I would appreciate some input. If this is a proper fix just let me know and I can make a pull request for it.

@joeyates
Copy link
Contributor

Since version 0.18.0, SimpleCov.minimum_coverage has been a Hash, allowing different values for :line and :branch coverage.

Here's the Changelog entry related to the change: https://github.com/simplecov-ruby/simplecov/blob/main/CHANGELOG.md#0180-2020-01-28

Here's the commit: simplecov-ruby/simplecov@69dfd85#diff-8cb7f3be7080b7ff0dc99ec016e9cf6422cf2ba71e6f0f24822bec6bdb1b36fbR243

#16 Fixes this issue.

@enricoribelli
Copy link

@joeyates problem is that #16 PR is open since a while 😅

@gdonald
Copy link

gdonald commented Oct 2, 2023

Same here:

Formatter SimpleCovSmallBadge::Formatter failed with NoMethodError: undefined method `positive?' for {}:Hash (/Users/gd/.rbenv/versions/3.2.2/lib/ruby/gems/3.2.0/gems/simplecov-small-badge-0.2.4/lib/simplecov_small_badge/formatter.rb:36:in `state')

This is sad. b0rken for 9 months because the fix PR is unacceptable and the repo owner is too lazy to just fix the bug. Oh well, next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants