Skip to content

Add a way to remove defaults filters and document them better #803

Open
@fadeltd

Description

@fadeltd

ruby version: 2.6.3
simplecov version: 0.17.1
test-unit version: 3.3.4

Issue
I have a project with some ruby scripts for CI purposes, and just now I'm creating unit tests for my ruby scripts, and I'm trying to get coverage from it with simplecov, but simplecov always gives me 0.0 / 0.0 LOC (100.0%) covered.

Here's sample script to reproduce the issue

test_calculator.rb

require 'simplecov'
SimpleCov.start

require 'test/unit'
require_relative '.scripts/tool/calculator'

# Test calculator
class CalculatorTest < Test::Unit::TestCase
  def test_add_2_different_numbers
    assert sum(2, 2) == 4
  end

  def test_add_same_numbers
    assert sum(2) == 4
  end
end

.scripts/tool/calculator.rb

def sum(first, second = nil)
  first + second unless second.nil?
  first + first
end
Loaded suite test_calculator
Started
..
Finished in 0.000728 seconds.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2747.25 tests/s, 2747.25 assertions/s
Coverage report generated for Unit Tests to /Users/fadeltd/project/ruby-scripts/coverage. 0.0 / 0.0 LOC (100.0%) covered.

It seems that simplecov can't generate coverage for require_relative when the first directory name has . prefix
I've tried renaming my directory to scripts/.tool/calculator, and it works

Loaded suite test_calculator
Started
..
Finished in 0.000402 seconds.
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
2 tests, 2 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
4975.12 tests/s, 4975.12 assertions/s
Coverage report generated for Unit Tests to /Users/fadeltd/project/ruby-scripts/coverage. 3 / 3 LOC (100.0%) covered.

How can I fix this issue without having to rename my directory?
Thanks

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions