puppetlabs / rspec-puppet

RSpec tests for your Puppet manifests
https://puppetlabs.github.io/rspec-puppet/
MIT License
13 stars 18 forks source link

Coverage on custom functions tests #128

Open pfrayer opened 1 month ago

pfrayer commented 1 month ago

Describe the Bug

On a module, I have tests about custom functions present in this module. The tests work well, but the coverage don't detect it and stays at 0%.

My module structure is classic:

lib
└── puppet
    └── functions                      # my custom functions
        ├── bar.rb
        └── foo.rb
spec
├── classes
└── functions                          # the related tests
    ├── bar_spec.rb
    └── foo_spec.rb
templates
└── ...
files
└── ...
manifests
└── ...

rspec output:

$ rspec
Run options: exclude {:bolt=>true}
.................

Coverage Report:

Total resources:   0
Touched resources: 0
Resource coverage: 100.00%

Finished in 3.23 seconds (files took 1.57 seconds to load)
148 examples, 0 failures

Expected Behavior

rspec coverage report's resources should not be 0. Am I missing something ?

Environment

rspec (3.13.0)
rspec-core (3.13.0)
rspec-expectations (3.13.1)
rspec-github (2.4.0)
rspec-mocks (3.13.1)
rspec-puppet (4.0.2)
rspec-puppet-facts (5.1.0)
rspec-support (3.13.1)

spec_helper.rb uses a classic conf:

RSpec.configure do |c|
  c.default_facts = default_facts
  c.before :each do
    Puppet.settings[:strict] = :warning
    Puppet.settings[:strict_variables] = true
  end
  c.filter_run_excluding(bolt: true) unless ENV['GEM_BOLT']
  c.after(:suite) do
    RSpec::Puppet::Coverage.report!
  end

Additional Context

In this module I only have tests about custom functions, other part of the module aren't tested yet

jordanbreen28 commented 1 week ago

hey @pfrayer thanks for raising this. We've been looking into this abit, and we believe that the test coverage will only include resources declared in your puppet classes. We agree it would be nice to include custom function coverage, but are unable to commit to this just yet. We'll leave this open for now incase anyone feels like taking the task on.