Command name detection fails with recent Rake #110

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

Comments

Projects
None yet
4 participants
@andrerpbts

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

This comment has been minimized.

Show comment
Hide comment
@colszowka

colszowka Feb 1, 2012

Owner

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

Owner

colszowka commented Feb 1, 2012

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

@colszowka colszowka closed this Feb 1, 2012

@andrerpbts

This comment has been minimized.

Show comment
Hide comment
@andrerpbts

andrerpbts Feb 1, 2012

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?

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

This comment has been minimized.

Show comment
Hide comment
@colszowka

colszowka Feb 1, 2012

Owner

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 :)

Owner

colszowka commented Feb 1, 2012

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

This comment has been minimized.

Show comment
Hide comment
@andrerpbts

andrerpbts Feb 1, 2012

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

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

@StanBright

This comment has been minimized.

Show comment
Hide comment
@StanBright

StanBright Feb 5, 2012

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

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

@adrianpacala

This comment has been minimized.

Show comment
Hide comment
@adrianpacala

adrianpacala Feb 19, 2012

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

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

@colszowka

This comment has been minimized.

Show comment
Hide comment
@colszowka

colszowka Feb 22, 2012

Owner

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.

Owner

colszowka commented Feb 22, 2012

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 colszowka closed this in 23a768d Feb 22, 2012

@colszowka

This comment has been minimized.

Show comment
Hide comment
@colszowka

colszowka Feb 22, 2012

Owner

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 :)

Owner

colszowka commented Feb 22, 2012

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