-
Notifications
You must be signed in to change notification settings - Fork 554
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
Always 100% test coverage with Ruby 2.0p353 and Rails 4.1beta #271
Comments
Hm, just tried running without Spring (via |
I seem to have the same problem with regular tests with rails 4.1.0.beta1 both with and without spring. require 'simplecov'
SimpleCov.start 'rails' do
add_group "Serializers", "app/serializers"
end |
I'm not using rails, but had a similar issue #277 and fixed it by rolling back to ruby 1.9.3. Try that if possible. |
As a side note, no problems with 2.1.0 x86_64, rvm 1.25.14, bundler 1.5.2, rails 4.0.2 on Linux.
and it works.
I'm not using spring. |
True, Ruby 2.1 works without a problem. Okay, I'll take that ;) |
Spring and SimpleCov don't mix well. Your Rakefile may also be loading library code. Also see my comment in #314 (comment) |
@swrobel PR to add this to the README? |
Upon further testing of my solution, I've found that using If it helps anyone knowledgeable with digging into the problem, I seem to get lower coverage for models when running simplecov through spring, but not for controllers. With Spring:
Without Spring:
|
@swrobel I noticed SimpleCov now runs on every spring based rspec run. Is there a way to disable it or only run it if an ENV is set? |
@swrobel I have this same problem. |
@swrobel I've mounted Grape into my rails project and it is also displaying below correct coverage. See issue #363. In the next week or two, I'll start reading through the Spring source code to see if there's any reason that Spring is not correctly reporting coverage for models and rack mounted apps. |
A preloader that forks may allow you to make the Coverage module |
@bf4 That's helpful to know. Thanks. |
@chrishough If you wrap |
You can also only execute simplecov outside of Spring like this:
|
@whatasunnyday Here's a protip for that pattern SimpleCov.start 'rails' do
# other config
end unless defined?(Spring) |
@bf4 I've never seen that before 👍 . Thanks! |
@bf4 @whatasunnyday the only way I was able to get this to work correctly with spring was to create the file if ENV['COVERAGE']
require 'simplecov'
SimpleCov.start do
coverage_dir 'tmp/coverage'
add_filter '/.bundle/'
add_filter '/spec/'
add_filter '/config/'
add_group 'Models', 'app/models'
add_group 'Controllers', 'app/controllers'
add_group 'Services', 'app/services'
add_group 'Utilities', 'app/utilities'
add_group 'Helpers', 'app/helpers'
add_group 'Libraries', 'lib'
add_group 'Mailers', 'app/mailers'
add_group "Long Files" do |src_file|
src_file.lines.count > 300
end
add_group 'Ignored Code' do |src_file|
File.readlines(src_file.filename).grep(/:nocov:/).any?
end
end
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter
]
SimpleCov.minimum_coverage 95
end |
@chrishough tl;dr you used an ENV var :) BTW, I recommend you move the simplecov config to a |
@swrobel, adding if ENV['RAILS_ENV'] == 'test'
require 'simplecov'
SimpleCov.start 'rails'
SimpleCov.command_name 'Rspec'
end Simplecov tries to discover the command but the spring command makes it impossible. |
I'm running the latest official patch version of Ruby 2.0 (p353) together with the the revision e4b9f6c of simplecov on Rails 4.1beta. I've added simplecov to the top of
spec_helper
but when I runbin/rake spec
, it always reports 100% test coverage and doesn't see files with no test coverage (like certain controllers, etc.). Anyone experiencing the same problems?I tried adapting the Spork logic to Spring, but without luck.
The text was updated successfully, but these errors were encountered: