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

Simplecov doesn't mark controller methods I know are being called #286

Closed
coneybeare opened this issue Mar 3, 2014 · 8 comments
Closed
Labels

Comments

@coneybeare
Copy link

I run a single controller test using rspec, the controller gets marked as 100%. I run the same tests as part of rake spec, and methods that I know are called are not being marked as covered. Where should I start debugging?

@xaviershay
Copy link
Collaborator

Check when you are loading simplecov. See #314 (comment) for one example of how this can make a difference. You can try dropping some puts statements in global scope of your controller code and also where simplecov is being loaded to see whether they are consistent with different ways of running your code.

Recommend close - debugging advice provided, stale, need a repro.

@coneybeare
Copy link
Author

Unfortunately, I have nothing loaded before simplecov in the spec_helper.rb

require 'simplecov'
SimpleCov.start 'rails' do
  add_group 'API Controllers' , 'app/controllers/api'
end

...

Can you please be more specific, as in, is there a way to log what controllers have been loaded so that I can add this just before the SimpleCov call?

@bf4
Copy link
Collaborator

bf4 commented Jul 16, 2014

Look at your Rakefile. I bet you're requiring app code there before simplecov.

@coneybeare
Copy link
Author

Unfortunately not. It is the default Rails implementation

# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.

require File.expand_path('../config/application', __FILE__)

Rails.application.load_tasks

@colszowka
Copy link
Collaborator

Hm, just had a quick glance over the current rake tasks file in rspec-rails master, nothing suspicious there. I know as a matter of fact that rails at least up to version 3 used to run the builtin unit tests, functional tests and integration tests tasks in separate processes, and hence SimpleCov's resultset merger had to fix things by providing explicit test suite names for these, see here. I think this got obsolete at some point on the road to Rails 4 and the tasks are currently all run as one, but I'm actually not sure about that.

Anyway, could you please try to configure SimpleCov to use a randomized command_name and see if this fixes your results? This way we'd know if this is a multi-process test suite problem (just put command_name SecureRandom.hex(16) in your SimpleCov configuration block).

Another possibility would be a cache_classes = false setting in your test environment, and/or some clever test env pre-loading tool like spork, zeus, spring etc. making trouble - these are kind of notorious for messing up coverage results in very hard to debug ways, see #42 for an example and lengthy discussion of the matter. If you're using some test pre-loader, I always advise to use spin, it is very lightweight and works very well alongside simplecov and guard in my own experience.

@coneybeare
Copy link
Author

Everything looks as suspected, but I played around a bit with the config.eager_load var in my test environment. Setting it to false seems to make the stats accurate again, but of course at the cost of not showing a 0% for unloaded and untested files.

@bf4
Copy link
Collaborator

bf4 commented Dec 31, 2014

@coneybeare I see in my comment above you're still loading Rails before requiring simplecov. Take a look at #340 for more info

@bf4
Copy link
Collaborator

bf4 commented Dec 31, 2014

Closing as stale. Please re-open if this is still an issue.

@bf4 bf4 closed this as completed Dec 31, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants