ruby - simplecov 报告覆盖 0.0%

标签 ruby rspec simplecov

我正在开发一个小插件,其中包括 simplecov。

在我的 gem 文件中有一行:

gem 'simplecov', :require => false, :group => :test

在我的测试文件中,我放置了行 require "projectname/devuntil/rspec/spec_helper" 在文件的最顶部。

在我的 spec_helper.rb 文件中,我在文件顶部添加了 simplecov

if ENV['COVERAGE']
  require 'simplecov'
  require 'coveralls'

  puts "require simplecov and coveralls"
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
    SimpleCov::Formatter::HTMLFormatter,
    Coveralls::SimpleCov::Formatter
  ]

  SimpleCov.start do
    add_filter 'spec/'
    add_filter 'vendor/'
    puts "Start simple coverage"
  end
end

当我尝试使用命令 COVERAGE=true bundle exec rspec 运行测试时,它显示:

[root@node1 logstash-input-imap]# COVERAGE=true bundle exec rspec
Coverage may be inaccurate; set the "--debug" command line option, or do JRUBY_OPTS="--debug" or set the "debug.fullTrace=true" option in your .jrubyrc
require simplecov and coveralls
/usr/local/rvm/gems/jruby-9.1.7.0/gems/logstash-devutils-1.3.3-java/lib/logstash/devutils/rspec/spec_helper.rb:6:in `<main>': [DEPRECATION] ::[] is deprecated. Use ::new instead.
Start simple coverage
/usr/local/rvm/gems/jruby-9.1.7.0/gems/simplecov-0.15.0/lib/simplecov.rb:48: warning: tracing (e.g. set_trace_func) will not capture all events without --debug flag
--- jar coordinate com.fasterxml.jackson.core:jackson-databind already loaded with version 2.7.4 - omit version 2.7.3
--- jar coordinate com.fasterxml.jackson.core:jackson-annotations already loaded with version 2.7.0 - omit version 2.7.3
--- jar coordinate com.fasterxml.jackson.module:jackson-module-afterburner already loaded with version 2.7.4 - omit version 2.7.3
--- jar coordinate com.fasterxml.jackson.core:jackson-core already loaded with version 2.7.4 - omit version 2.7.3
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Sending Logstash's logs to  which is now configured via log4j2.properties
Run options: exclude {:redis=>true, :socket=>true, :performance=>true, :couchdb=>true, :elasticsearch=>true, :elasticsearch_secure=>true, :export_cypher=>true, :integration=>true, :windows=>true}

Randomized with seed 6877
.function called
.function called
.function called
.function called
.function called
.function called
.

Finished in 4.04 seconds (files took 16.56 seconds to load)
7 examples, 0 failures

Randomized with seed 6877

Coverage report generated for RSpec to /root/Downloads/logstash-input-imap/coverage. 0 / 88 LOC (0.0%) covered.
[Coveralls] Outside the Travis environment, not sending data.

虽然我的函数被调用了,但它仍然显示 0.0% 被覆盖。
这里可能有什么问题以及如何解决?谢谢

最佳答案

您可以尝试在您的项目根目录中使用以下内容创建 .jrubyrc:

cli.debug=true

debug.fullTrace=true

关于ruby - simplecov 报告覆盖 0.0%,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45812044/

相关文章:

ruby-on-rails - 如何在 RSpec 中模拟数组?

ruby-on-rails - 使用 simplecov 进行最小测试

ruby-on-rails - 英雄数据库 :pull not working

ruby - Sinatra/1.4.3 使用 Rack::Session::Cookie 警告

ruby - 如何检查文件是否正在被其他应用程序使用?

ruby-on-rails - Rails 4 - 带有命名空间的 STI

ruby-on-rails - 在设备 3.1 中返回设计确认 token

ruby-on-rails - 如何使用 RSpec 模拟登录?

testing - SonarQube 不显示 Ruby on Rails 项目的测试代码覆盖率

ruby-on-rails - 从 Simplecov 报告中排除供应商文件