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

Do not cover private methods #304

Closed
kofronpi opened this issue May 29, 2014 · 5 comments
Closed

Do not cover private methods #304

kofronpi opened this issue May 29, 2014 · 5 comments
Labels

Comments

@kofronpi
Copy link

In the coverage report SimpleCov show my private methods as not covered. It would be nice to be able to configure SimpleCov to uncover all private methods.

@colszowka
Copy link
Collaborator

You could use the :nocov: token to wrap the code to skip, as shown here, in that example also showing how to configure a different keyword for the nocov wrapper.

As general advice, although it is very reasonable to avoid directly testing private methods of your classes, normally these methods will be used by the actual public API of your objects to perform some kind of task, and hence if you appropriately test the public interface of your classes and objects you should automatically also get full coverage of your private methods. In my experience, private methods rarely end up being not covered by tests, even if you stick to no direct testing of private methods.

@dideler
Copy link
Contributor

dideler commented Jun 20, 2014

Very useful information. I think using # :nocov: to skip code should be mentioned in the README. A search for "nocov" or "skip" returns no results in the README.

if you appropriately test the public interface of your classes and objects you should automatically also get full coverage of your private method

This would also be useful in the README. I was going to skip a private method until I read this and realized I wasn't testing appropriately. At least have a section on private methods in the README, since a search for "private" also returns no results in the README.

Thanks for making simplecov!

@bf4
Copy link
Collaborator

bf4 commented Jun 20, 2014

@dideler Would you consider making a pull request?

@dideler
Copy link
Contributor

dideler commented Jun 21, 2014

Sure, as long as @colszowka or any other committer agrees with the suggestions.

I'm not sure where in the README these changes would go. They don't seem to fit nicely in any of the existing sections. Maybe a FAQ section?

@bf4
Copy link
Collaborator

bf4 commented Jun 22, 2014

I think it should be in the filters section perhaps even with a link to the feature

bf4 pushed a commit that referenced this issue Jul 13, 2014
jsonn pushed a commit to jsonn/pkgsrc that referenced this issue Feb 3, 2015
0.9.1, 2014-09-21 ([changes](simplecov-ruby/simplecov@v0.9.0...v0.9.1))
====================

## Bugfixes

 * In 0.9.0, we introduced a regression that made SimpleCov no-op mode fail on Ruby 1.8, while
   dropping 1.8 support altogether is announced only for v1.0. This has been fixed.
   See [#333](simplecov-ruby/simplecov#333) (thanks (@sferik)


0.9.0, 2014-07-17 ([changes](simplecov-ruby/simplecov@v0.8.2...v0.9.0))
====================

**A warm welcome and big thank you to the new contributors [@xaviershay](https://github.com/xaviershay), [@sferik](https://github.com/sferik) and especially [@bf4](https://github.com/bf4) for tackling a whole lot of issues and pull requests for this release!**

## Enhancements

  * New interface to specify multiple formatters.
    See [#317](simplecov-ruby/simplecov#317) (thanks @sferik)
  * Document in the README how to exclude code from coverage reports,
    and that the feature shouldn't be abused for skipping untested
    private code.
    See [#304](simplecov-ruby/simplecov#304)
  * Clarify Ruby version support.
    See [#279](simplecov-ruby/simplecov#279) (thanks @deivid-rodriguez)

## Bugfixes

  * Ensure calculations return Floats, not Fixnum or Rational. Fixes segfaults with mathn.
    See [#245](simplecov-ruby/simplecov#245) (thanks to @bf4)
  * Using `Kernel.exit` instead of exit to avoid uncaught throw :IRB_EXIT when
    exiting irb sessions.
    See [#287](simplecov-ruby/simplecov#287) (thanks @wless1)
    See [#285](simplecov-ruby/simplecov#285)
  * Does not look for .simplecov in ~/ when $HOME is not set.
    See [#311](simplecov-ruby/simplecov#311) (thanks @lasseebert)
  * Exit with code only if it's Numeric > 0.
    See [#302](simplecov-ruby/simplecov#303 @hajder)
  * Make default filter case insensitive.
    See [#280](simplecov-ruby/simplecov#280) (thanks @ryanatball)
  * Improve regexp that matches functional tests.
    See [#276](simplecov-ruby/simplecov#276) (thanks @sferik)
  * Fix TravisCI [#272](simplecov-ruby/simplecov#272) [#278](simplecov-ruby/simplecov#278), [#302](simplecov-ruby/simplecov#302)
  * Fix global config load.
    See [#311](simplecov-ruby/simplecov#311) (thanks @lasseebert)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants