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

Command name detection fails with recent Rake #110

Closed
andrerpbts opened this issue Jan 31, 2012 · 8 comments
Closed

Command name detection fails with recent Rake #110

andrerpbts opened this issue Jan 31, 2012 · 8 comments
Milestone

Comments

@andrerpbts
Copy link

Hi, I don't know if I'm doing something wrong, but I have a model with two methods, and even the test passing, the coverage file isn't being marked as covered. The code:

#model
class List < ActiveRecord::Base
  def closed?
    status == 'closed'
  end

  def open?
    status == 'open'
  end
end

#test
require 'test_helper'

class ListTest < ActiveSupport::TestCase
  test "should respond true to the closed? method" do
    list = create(status: 'closed')
    assert list.closed?, "a closed list is not responding true to closed? method"
  end

  test "should respond true to the open? method" do
    list = create(status: 'open')
    assert list.open?, "a opened list is not responding true to open? method"
  end

  private
  def create(options={})
    List.create({
      description: 'Test list',
      status: 'open'
    }.merge(options))
  end
end

the return of method open? isn't being covered. Why?

@colszowka
Copy link
Collaborator

Hi, please check out #60, I think your issue is the same. There's a solution at the bottom.

@andrerpbts
Copy link
Author

Ok, I'll reply on this Issue because I think the problem isn't related to #60, since I tried the following and my problem still remains:

  1. Upgrade my rails version to 3.2
  2. Force config.cache_classes = true.

Now, I tried run only my units tests rake test:units, and those lines are being marked covered. After, running all tests again rake test, then I got those lines marked uncovered again. Are the functionals tests overriding units tests in some methods or something like it? Am I doing something wrong?

@colszowka colszowka reopened this Feb 1, 2012
@colszowka
Copy link
Collaborator

Actually, you're right - something in the test suite detection seems to have went down the drain on the road to Rails 3.2 and I was able to reproduce this bug. Reopened, sorry for making too early conclusions 🍺

What you can do to temporarily fix this (note that this only has to be done in ONE file per test suite as it will apply to the whole SimpleCov config for that process):

  • In one test/unit/ANY_test.rb add SimpleCov.command_name 'Unit Tests' below require 'test_helper'
  • In one test/functional/ANY_test.rb add SimpleCov.command_name 'Functional Tests' below require 'test_helper'
  • In one test/integration/ANY_test.rb add SimpleCov.command_name 'Integration Tests' below require 'test_helper'

This will make SimpleCov ditch it's own CommandGuesser class and use the suite names you provided. Keeping this open as it definetely needs to get fixed though :)

@andrerpbts
Copy link
Author

Just to let you know, your temporarily fix worked here.

@StanBright
Copy link

Thanks for the "temp" fix. It worked for me to :) - ruby 1.9.3-p0, rails 3.2.1

@adrianpacala
Copy link

I'm having the same issue here. Temp fix worked, thanks.

@colszowka
Copy link
Collaborator

So, the offender here is lib/rake/rake_test_loader.rb in recent Rake releases as it's tampering with ARGV and removing the loaded test suite information for simplecov to figure out what Rails suite is running. I'm on it, a fix will be included in the next release.

@colszowka
Copy link
Collaborator

v0.6.0 is out and should resolve this. At least it did in my local tests on a fresh 3.2.1 Rails app :)

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