Skip to content

Loading…

Command name detection fails with recent Rake #110

Closed
andrerpbts opened this Issue · 8 comments

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
Owner

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

@colszowka colszowka closed this
@andrerpbts

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
@colszowka
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 :beer:

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

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

@StanBright

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

@apacala

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

@colszowka
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.

@colszowka colszowka added a commit that closed this issue
@colszowka Prevent libraries that tamper with ARGV (I'm looking at you, rake)
from disabling SimpleCov's ability to guess test suite / framework names
based upon the command line call that invoked the tests.

Fixes #110 and probably also #45

Cleaned up and refactored the command guessing along the way.
23a768d
@colszowka colszowka closed this in 23a768d
@colszowka
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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.