简体   繁体   English

SimpleCov ::定期覆盖率报告

[英]SimpleCov :: Periodic Coverage Report

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. 如果我尝试在不启动服务器的情况下尝试生成报告,则通过在Rails控制台(SimpleCov.result.format!)中使用以下命令,不会得到任何coverage编号。

The following is my config in my config/boot.rb: 以下是我在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: 这是我的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'])

The pre-requisites for SimpleCov to work properly are documented here: Getting Started with SimpleCov . SimpleCov正常工作的前提条件在此处记录: SimpleCov入门。 You must be having the SimpleCov related code inside the boot.rb file after the Rails loading code. 在Rails加载代码之后 ,您必须在boot.rb文件中包含与SimpleCov相关的代码。 This is wrong. 错了 Promote all that code to the top and the SimpleCov.result.format! 将所有代码提升到顶部和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 . 但是,在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). 通常,仅在测试环境中才需要覆盖报告(当提交代码并且像Travis这样的连续集成服务器运行完整的测试套件并生成覆盖报告时)。 Hence, the documentation refers to this style of setup where everything related to SimpleCov runs in the test environment. 因此,文档涉及这种设置样式,其中与SimpleCov相关的所有内容均在test环境中运行。 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; Getting Started部分的第一个主题提到,您需要在test_helper文件(如果使用spec_helper.rb话,为spec_helper.rb的开头具有SimpleCov.start行,因为那是加载Rails环境的文件。 which means that you end up loading SimpleCov and it's configuration before loading the actual application code and you get a correct output. 这意味着您最终将在加载实际的应用程序代码之前加载SimpleCov及其配置,并获得正确的输出。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM