Skip to content

Expand unit test coverage#44

Open
tas50 wants to merge 2 commits into
chef:mainfrom
tas50:tests/unit-coverage-util-do-nothing
Open

Expand unit test coverage#44
tas50 wants to merge 2 commits into
chef:mainfrom
tas50:tests/unit-coverage-util-do-nothing

Conversation

@tas50

@tas50 tas50 commented Jun 28, 2026

Copy link
Copy Markdown

Summary

Expands the project's unit test coverage, targeting code that is genuinely unit-testable (pure logic and isolated classes), taking the unit suite from 162 → 194 examples.

Added / fixed specs

  • ChefSpec::Util — had no spec. Covers underscore (CamelCase, namespaced constants, acronyms, dashes), camelize, and truncate (within-limit, over-limit ellipsis, default length).
  • DoNothingMatcher — its spec file was named do_nothing_matcher.rb without the _spec suffix, so RSpec never loaded it, and its body was just pending — i.e. zero effective coverage. Replaced with a real do_nothing_matcher_spec.rb exercising matches? (nil, empty actions, :nothing, real action), description, and both failure messages.
  • ChefSpec::Normalize#resource_namedeclared_type / resource_name / plain-string fallbacks and dash→underscore normalization.
  • ChefSpec::FileCachePathProxy — singleton identity and that it exposes a real temp directory.
  • ChefSpec::Coverage::ResourceWrappersource_file/source_line parsing (with and without a source line), shortname cookbook-relative paths, touch!/touched? state, and to_json. Coverage is core functionality and previously only its filters were tested.

Why not api/ and extensions/?

lib/chefspec/api/ and lib/chefspec/extensions/ define the test DSL and monkey-patch Chef internals — they only do anything meaningful during a real Chef converge and are already exercised end-to-end by the examples/ acceptance suite. Unit-testing them would require mocking Chef so heavily that the tests would assert the mocks rather than real behavior, so they're deliberately left to the acceptance tests.

Testing

  • bundle exec rspec spec/unit/194 examples, 0 failures (up from 162).
  • cookstyle --chefstyle -c .rubocop.yml on the new specs → no offenses.

Close two real unit-test gaps:

- ChefSpec::Util (underscore/camelize/truncate) had no spec at all; add
  one covering the transformations and the truncate boundary/default.
- The DoNothingMatcher "spec" was named do_nothing_matcher.rb (missing
  the _spec suffix) so RSpec never loaded it, and its body was just
  `pending`. Replace it with a real do_nothing_matcher_spec.rb exercising
  matches?, description, and both failure messages.

Signed-off-by: Tim Smith <tsmith84@proton.me>
@tas50
tas50 requested review from a team and jaymzh as code owners June 28, 2026 05:48
Expand unit coverage of the pure, unit-appropriate code:

- ChefSpec::Normalize#resource_name: declared_type/resource_name/string
  fallbacks and dash-to-underscore normalization.
- ChefSpec::FileCachePathProxy: singleton identity and that it exposes a
  real temp directory.
- ChefSpec::Coverage::ResourceWrapper: source_file/source_line parsing
  (with and without a source line), touch!/touched? state, and to_json.

Signed-off-by: Tim Smith <tsmith84@proton.me>
@tas50 tas50 changed the title Add unit specs for Util and DoNothingMatcher Expand unit test coverage Jun 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant