Expand unit test coverage#44
Open
tas50 wants to merge 2 commits into
Open
Conversation
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>
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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. Coversunderscore(CamelCase, namespaced constants, acronyms, dashes),camelize, andtruncate(within-limit, over-limit ellipsis, default length).DoNothingMatcher— its spec file was nameddo_nothing_matcher.rbwithout the_specsuffix, so RSpec never loaded it, and its body was justpending— i.e. zero effective coverage. Replaced with a realdo_nothing_matcher_spec.rbexercisingmatches?(nil, empty actions,:nothing, real action),description, and both failure messages.ChefSpec::Normalize#resource_name—declared_type/resource_name/ plain-string fallbacks and dash→underscore normalization.ChefSpec::FileCachePathProxy— singleton identity and that it exposes a real temp directory.ChefSpec::Coverage::ResourceWrapper—source_file/source_lineparsing (with and without a source line),shortnamecookbook-relative paths,touch!/touched?state, andto_json. Coverage is core functionality and previously only its filters were tested.Why not api/ and extensions/?
lib/chefspec/api/andlib/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 theexamples/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.ymlon the new specs → no offenses.