-
Notifications
You must be signed in to change notification settings - Fork 563
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
Comments
Offhand, it sounds like a bug in the Coverage module that we may be able to work around with some clever trick. |
Is the lambda/block actually being executed? If not, that would explain this behaviour to me. |
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. |
|
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? |
yep, but there's nothing we can do about it. The underlying coverage library only provides line coverage, not branch coverage. |
@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. |
@bf4 think you meant @robsonagapito? 😉 |
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:

Result (2 lines) - 85.58% / 73.03 :

Code in 1 line:

Result (1 line) - 85.64% / 73.15%

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.
The text was updated successfully, but these errors were encountered: