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

Coverage isn't reported correctly for Mongoid backed rails project #56

Open
singfoom opened this issue Jul 25, 2011 · 2 comments
Open

Comments

@singfoom
Copy link

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.

@singfoom
Copy link
Author

I wanted to add that I have another test inside that context that hits the internals of that method more clearly.

should "have errors on users" do
  assert_equal(@twitter_feed.errors, {:users => ["must have at least one username or hash_tag"]})
end

This also passes and has the coverage problems I've mentioned earlier.

@dougrohde
Copy link

I have noticed the same problem as well. For example, for a particular method that I'm sure is being run, but does not show as covered, I'll throw a raise statement somewhere in that method and get errors all over the place when I run my tests. When I remove it, though, it still shows as not being covered.

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

2 participants