1
votes

I have a requirement where in, i need to get the coverage so far. If I stop the server, the report gets generated and I do get the coverage so far. But if i start the server again, my previous coverage results are lost and I can only get the coverage after the server was restarted.

Is there a way for me to keep checking periodically for the the coverage% - without stopping the server?

If i try to generate a report without starting the server, by using the following command, in rails console (SimpleCov.result.format! ),I dont get anycoverage number.

The following is my config in my config/boot.rb:

require 'simplecov'
SimpleCov.start 'rails' do
add_filter "/vendor/"
end

Please share your thoughts Thanks Ramya

This is the content of my boot.rb:

require 'simplecov'

# # create coverage directory if it doesn't exist already.
 Dir.mkdir("coverage") unless Dir.exist?("coverage")

 SimpleCov.start 'rails' do
        SimpleCov.use_merging(true)
   add_filter "/vendor/"
   SimpleCov.merge_timeout 30
 end


require 'rubygems'

# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)

require 'bundler/setup' if File.exists?(ENV['BUNDLE_GEMFILE'])
2

2 Answers

0
votes

The pre-requisites for SimpleCov to work properly are documented here: Getting Started with SimpleCov. You must be having the SimpleCov related code inside the boot.rb file after the Rails loading code. This is wrong. Promote all that code to the top and the SimpleCov.result.format! method will work inside the console.

However, it's generally a bad idea to have any extra code inside the boot.rb. Usually, coverage reports are needed only in the test environment (when the code is committed and a continuous integration server like Travis runs the full test suite and generates a coverage report). Hence, the documentation refers to this style of setup where everything related to SimpleCov runs in the test environment. The first topic in the Getting Started section mentions that you need to have the SimpleCov.start line at the beginning of the test_helper file (spec_helper.rb if you're using Rspec) since that is the file that loads the Rails environment; which means that you end up loading SimpleCov and it's configuration before loading the actual application code and you get a correct output.

0
votes
require 'simplecov'
SimpleCov.start do
    coverage_dir  "custom-coverage_"+Time.now.strftime("%m_%d_%Y").to_s
end