-
Notifications
You must be signed in to change notification settings - Fork 552
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
How to configure SimpleCov with Spring? #381
Comments
I definitely have an issue with spring and simplecov: $ bundle exec rspec
Finished in 15.98 seconds (files took 8.6 seconds to load)
87 examples, 0 failures, 5 pending
Coverage report generated for RSpec to /Users/craigsniffen/Documents/Projects/71lbs/coverage. 2372 / 7486 LOC (31.69%) covered.
$ bundle exec spring rspec
Finished in 13.9 seconds (files took 0.65848 seconds to load)
87 examples, 0 failures, 5 pending
Coverage report generated for RSpec to /Users/craigsniffen/Documents/Projects/71lbs/coverage. 18 / 27 LOC (66.67%) covered. This is with $ bundle exec rspec
Finished in 20.97 seconds (files took 11.15 seconds to load)
87 examples, 0 failures, 5 pending
Coverage report generated for RSpec to /Users/craigsniffen/Documents/Projects/71lbs/coverage. 1505 / 3530 LOC (42.63%) covered.
$ bundle exec spring rspec
Finished in 15.01 seconds (files took 0.89234 seconds to load)
87 examples, 0 failures, 5 pending
Coverage report generated for RSpec to /Users/craigsniffen/Documents/Projects/71lbs/coverage. 1188 / 2953 LOC (40.23%) covered. The difference in LOC is troubling, however. It's also not loading all of the files as I'd want. |
Why is the LOC count in your first I have the following settings in my # The test environment is used exclusively to run your application's
# test suite. You never need to work with it otherwise. Remember that
# your test database is "scratch space" for the test suite and is wiped
# and recreated between test runs. Don't rely on the data there!
config.cache_classes = false
# Disable Rails's static asset server (Apache or nginx will already do this)
config.serve_static_files = false
config.eager_load = false When running rspec alone, versus with spring, I did not notice a change in LOC or coverage. As I mentioned in my original post, we may have truly deleted a couple thousand LOC. |
I'm going to assume that it's because it's loading files that weren't loaded in the other run. I have very poor test coverage. I found the new section on the readme for dealing with spring, but after implementing it my coverage reports now claim that all code outside of methods are not covered. |
I am going to run some tests with eager load toggled. Thank you for the advice UPDATE: I see what you mean. Turning eager load to true makes my coverage 0/0 LOC at 100% |
Maybe a dumb question, but have you seen #341 (in the README?) Also, and this is just my opinion, but spring ruins everything it touches. I can't tell you how many times some bizarre error has been due to spring running old code. My bash_profile now has |
I did see that part of the README. My question, do I put that in my # config/spring.rb
Spring.after_fork do
if Rails.env == "test"
class ActiveRecord::Base
mattr_accessor :shared_connection
@@shared_connection = nil
def self.connection
@@shared_connection || ConnectionPool::Wrapper.new(size: 1) { retrieve_connection }
end
end
ActiveRecord::Base.shared_connection = ActiveRecord::Base.connection
RSpec.configure do |config|
srand; config.seed = srand % 0xFFFF
end
end
end |
@bf4 As I mentioned, I do not see any strange behavior with spring right now. I just wanted to properly set it up to prevent any behavior. When I make major changes I use I guess I should simply not fix what ain't broken? |
If you think you can improve rhe docs, please submit a pr
|
As a related note, since this is one of the top search results for "SimpleCov eager_load", if you do want to eager load all your code, you could try what is mentioned here: https://stormconsultancy.co.uk/blog/development/ruby-on-rails/getting-accurate-code-coverage-metrics-from-simplecov-rails-project/ just run I'll submit a PR for the docs if this seems like something that should be in the documentation! |
A cleaner solution to usage with spring than copying simple cov code start spring.rb. According to suggestion here simplecov-ruby#381 (comment) and here https://stormconsultancy.co.uk/blog/development/ruby-on-rails/getting-accurate-code-coverage-metrics-from-simplecov-rails-project/
A cleaner solution to usage with spring than copying simple cov start code to config/spring.rb. According to suggestion here simplecov-ruby#381 (comment) and here https://stormconsultancy.co.uk/blog/development/ruby-on-rails/getting-accurate-code-coverage-metrics-from-simplecov-rails-project/
@ibrahima thanks for the suggestion! Unfortunately, I'm seeing this error |
Just to let you know, everything is working fine when I moved |
I was having this issue recently and I tried to do the suggested approach of setting
this did not work for me, but what did work for me is updating
so that the |
Rails 4.2.0, RSpec 3.1, SimpleCov 0.9.2
I have the following in my
rails_helper.rb
file, outside of theRSpec.configure
blockI have read online that some people find running
spring rspec
returns high or even 100% coverage. It does not seem that way for our app, but I would just like to make sure. The LOC count seems a little low (short by 1000 maybe?), although again that could be from recent refactoring I have not viewed the commits for.And my
config/spring.rb
file contains nothing about SimpleCov. Would I put the above configuration in the spring file itself, or under theSpring.after_fork
block?The text was updated successfully, but these errors were encountered: