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 not covering lib directory in Rails engine -- NOT a missing require #221

Closed
lastobelus opened this issue May 3, 2013 · 10 comments

Comments

@lastobelus
Copy link

In my rails engine simplecov does not (or rather will not) provide coverage for the lib directory.

I tried adding the root directory of the engine to the loadpath in spec_helper, and doing require "lib/myengine", which did not work.

HOWEVER If I simply rename lib to bob and change the corresponding require in the spec to require 'bob/myclass', the coverage DOES get created.

The issue seems to be purely with the name lib. 🐤

Adding a group with the lib path does not help the matter.

@lastobelus
Copy link
Author

After some work at debugging this, we realized the problem exists only in the rubygems.org version of the gem, and not in HEAD

We discovered we needed to use the HEAD version of the gem AND do this in the spec_helper:

Dir["lib/**/*.rb"].each {|file| puts file; puts load(file); }

@lsaffie
Copy link

lsaffie commented Oct 15, 2013

Although this does work, it feels a little hackie. I'll try to get some time to make a pull request to get simplecov to detect this and load. Thanks for the workaround!

@lsaffie
Copy link

lsaffie commented Oct 16, 2013

Actually, loading the files above didn't work for me correctly as it's order,directory dependent => flaky.

Instead I did the following and it worked nicely:

https://gist.github.com/bsodmike/5866873

SimpleCov.start('rails') do
adapters.delete(:root_filter)
filters.clear
add_filter do |src|
!(src.filename =~ /^#{SimpleCov.root}/) unless src.filename =~ /my_engine/
end
end if ENV['COVERAGE']

@lastobelus
Copy link
Author

@lsaffie Thanks I'll try that next time I work on an engine.

@colszowka
Copy link
Collaborator

Great this got fixed by the recent release, thanks for reporting back!

@lsaffie That's a cool idea, I'll add this to the README documentation.

@hongweikang
Copy link

@lsaffie, how can I use add_filter and add_group to coverage several engines in different group.

@lsaffie
Copy link

lsaffie commented Dec 8, 2014

@hongweikang check out these examples: https://gist.github.com/bsodmike/5866873

@hongweikang
Copy link

@lsaffie , thank you, that's work well.But the simplecov just coverage code that spec code include.How to
coverage code that doesn't invoke by rspec test case.
image

Above is the engine that doesn't call by spec code.But our goal is to detect every engine's code coverage rate.

@mhenrixon
Copy link

👍 @hongweikang I have the same problem as you do.

@simplecov-ruby simplecov-ruby locked and limited conversation to collaborators Dec 31, 2014
@bf4
Copy link
Collaborator

bf4 commented Dec 31, 2014

Please create a new issue (or submit a PR) on how to have SimpleCov report coverage for files outside of SimpleCov.root. Perhaps see #340

For reference, the config example in at @lsaffie's link is

  adapters.delete(:root_filter)
  filters.clear
  add_filter do |src|
    !(src.filename =~ /^#{SimpleCov.root}/) unless src.filename =~ /\/my_engine\//
  end

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants