【问题标题】:SimpleCov issue. Some files not coveredSimpleCov 问题。部分文件未涵盖
【发布时间】:2017-11-08 20:34:17
【问题描述】:

SimpleCov 在其他文件成功覆盖 (100%) 时忽略一些文件 (0%)。

我使用框架的测试工具 (Rails 5.1.4) 运行我的测试。

这是我的test_helper.rb 文件。

require 'simplecov'

# save to CircleCI's artifacts directory if we're on CircleCI
if ENV['CIRCLE_ARTIFACTS']
  dir = File.join(ENV['CIRCLE_ARTIFACTS'], 'coverage')
  SimpleCov.coverage_dir(dir)
end

SimpleCov.start 'rails'

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

这是一个文件已成功覆盖 (100%),SimpleCov 使用Connection.types

class Connection < ApplicationRecord
  validates :type_of, inclusion: { in: proc { Connection.types.map(&:to_s) } }

  TYPES = %i[
    friend
    industry
    investor
  ].freeze

  belongs_to :project
  belongs_to :user

  def self.types
    TYPES
  end
end

这是一个文件未成功覆盖 (0%),SimpleCov 使用Kpi.types

class Kpi < ApplicationRecord
  REGEX = {
    float: "^\d+(\.?\d)?$"
  }.freeze

  TYPES = [
    { id: :buyers, name: 'Number of buyers', unit: 'users', example: '1000', regex: :float },
    { id: :sellers, name: 'Number of sellers', unit: 'users', example: '1000', regex: :float },
  ].freeze

  belongs_to :project

  def self.types
    TYPES
  end
end

我没有看到这里的模式......你呢?

【问题讨论】:

    标签: ruby-on-rails testing simplecov


    【解决方案1】:

    好的,找到了罪魁祸首:ActiveAdmin。这是后代的答案:)

    我添加了一个过滤器:

    SimpleCov.start 'rails' do
      add_filter('/admin')
    end
    

    现在可以正常使用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-20
      • 2012-02-26
      • 2017-08-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-10
      相关资源
      最近更新 更多