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

Scope is considerated "not ok" by simplecov-rcov when it is divided in two lines #411

Closed
robsonagapito opened this issue Aug 20, 2015 · 8 comments

Comments

@robsonagapito
Copy link

I have a code and I declare a scope, as line bellow:

scope :with_snapshot_histories,
-> { where(SCOPE_STR) }

In this case simplecov-rcov return "NOT OK", but if I declare scope in one line the result becomes OK.

scope :with_snapshot_histories, -> { where(SCOPE_STR) }

This situation also happens when I have a block (bellow):

NOT OK:
scope :service_codes_by_login, (lambda do |login|
joins(:account)
.where(accounts: {login: "#{login}/#{login}"})
.select(:service_code)
end)

OK:
scope :service_codes_by_login, (lambda do |login| joins(:account).where(accounts: {login: "#{login}/#{login}"}).select(:service_code) end)

Is this a problem? Or is this a expected comportment?

This situation affect the result of our coverage.

Code in 2 lines:
simplecov-rcov_before_perc

Result (2 lines) - 85.58% / 73.03 :
simplecov-rcov_before_code

Code in 1 line:
simplecov-rcov_after_code

Result (1 line) - 85.64% / 73.15%
simplecov-rcov_after_perc

Coverage's difference:
Result (2 lines) - 85.58% / 73.03%
Result (1 line) - 85.64% / 73.15%

PS: Images are gem SIMPLECOV-RCOV, but I tested with SIMPLECOV and happens the same.

@bf4
Copy link
Collaborator

bf4 commented Aug 23, 2015

Offhand, it sounds like a bug in the Coverage module that we may be able to work around with some clever trick.

@xaviershay
Copy link
Collaborator

Is the lambda/block actually being executed? If not, that would explain this behaviour to me.

@robsonagapito
Copy link
Author

Lambda/block really not being executed... but we can see a false positive in this case, because when it is in one line returns ok, but not being executed the complete line. I believe that it considers the line beginnings ok and ignores the "block", indifferent if executed or not.

@bf4
Copy link
Collaborator

bf4 commented Aug 25, 2015

Actually with C0 coverage it is correct as it only checks that the line was executed or evaulated at load :) and Coverage only does C0. :)

@robsonagapito
Copy link
Author

But, if I have a class with 20 scopes, all scopes with only one line to load, and no test, I have 100% of coverage, correct? This coverage would be a false positive?

@xaviershay
Copy link
Collaborator

yep, but there's nothing we can do about it. The underlying coverage library only provides line coverage, not branch coverage.

@bf4
Copy link
Collaborator

bf4 commented Aug 26, 2015

@robinroestenburg It's a common misunderstanding of SimpleCov. It's advertised as a test coverage tool, but practically it just uses the Ruby Coverage module to track which lines of a file are run and how many times. Since a method is only tracked when it's run, you can tell it's been called, so, during testing, it correlates with being tested.

@robinroestenburg
Copy link
Contributor

@bf4 think you meant @robsonagapito? 😉

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