markbates / markbates/cover_me
Coverage isn't reported correctly for Mongoid backed rails project
Nobody has claimed this yet.
- Dominant language
- Ruby
- Stars
- 203
- Forks
- 17
- PR merge metrics
- No merged PRs in 30d
Description
I've got a rails project that's using Mongoid as the "database" and I'm getting odd coverage results. Here's a snippet of a good example of the behavior I'm seeing:
Class:
```
class Source::TwitterFeed < Source
field :hash_tags, :type => Array, :default => []
field :users, :type => Array, :default => []
attr_accessible :users, :hash_tags
validate :validate_empty_feed
def validate_empty_feed
if (self.users.empty? && self.hash_tags.empty?)
errors.add(:users, "must have at least one username or hash_tag")
end
end
```
Test
```
context "twitter feed with empty hash_tags and users validation" do
setup do
Source::TwitterFeed.delete_all
@twitter_feed = Source::TwitterFeed.create(:users => [], :hash_tags => [])
end
should "be invalid" do
assert(@twitter_feed.invalid?, "twitter_feed was not invalid")
end
end
```
The test passes. Yet, only the def line of validate_empty_feed is considered covered. For reference, this is with cover_me 1.0.0, rails 3.0.7 and a cover_me config (That's really just empty) after a require in the test helper. I see this behavior all over the coverage report, where I have tests that I'm sure execute lines but are not considered covered. I looked around at the other issues and googled around but was unable to find anything on cover_me and mongoid.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported behavior with cover_me 1.0.0, Rails 3.0.7, Mongoid, the shown model and test, and the empty cover_me configuration loaded from the test helper. Compare the coverage report for validate_empty_feed with the test result; done means executed validation branches are reported as covered or the incompatibility is clearly isolated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, rails, ruby
- Domain
- testing-qa
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100