Skip to content

Fix NameError from removed rspec-expectations diff class (#13)#31

Open
tas50 wants to merge 1 commit into
chef:mainfrom
tas50:fix/issue-13-rspec-expectations-diff
Open

Fix NameError from removed rspec-expectations diff class (#13)#31
tas50 wants to merge 1 commit into
chef:mainfrom
tas50:fix/issue-13-rspec-expectations-diff

Conversation

@tas50

@tas50 tas50 commented Jun 28, 2026

Copy link
Copy Markdown

Summary

Resolves #13.

rspec-expectations renamed its private diff helper class from ExpectedsForMultipleDiffs to MultiMatcherDiff in 3.12.4 and changed its signature (actual moved from message_with_diff into the from factory). The originally reported error was a LoadError on require "rspec/matchers/expecteds_for_multiple_diffs".

A prior change (#19) addressed the LoadError by removing the rspec-expectations <= 3.12.3 pin and commenting out the broken require — but it left the call site in ResourceMatcher#failure_message still referencing the removed ::RSpec::Matchers::ExpectedsForMultipleDiffs class. That turned the loud LoadError into a latent NameError that only fires when a resource-parameter assertion fails and chefspec tries to render a diff.

Changes

  • lib/chefspec/matchers/resource_matcher.rb: Remove the stale commented-out require; extract a diff_for helper that detects which private rspec class is available and calls the matching API. This keeps chefspec working across the full rspec ~> 3.0 range (old and new rspec-expectations).
  • chefspec.gemspec: Drop the dangling "temporary restriction" comment that described a version pin already removed.
  • spec/unit/matchers/resource_matcher_spec.rb: Replace the pending stub with a real test covering the diff-rendering failure path (regression test for this issue).

Testing

  • Reproduced the NameError with a failing test first, then confirmed the fix (green) against rspec-expectations 3.13.5.
  • Manually verified the legacy branch produces a correct diff against rspec-expectations 3.11.1.
  • Full unit suite: 163 examples, 0 failures.
  • Lint: cookstyle --chefstyle -c .rubocop.yml → no offenses.

@tas50
tas50 requested review from a team and jaymzh as code owners June 28, 2026 05:04
@tas50
tas50 force-pushed the fix/issue-13-rspec-expectations-diff branch from ce9333c to 9202d2d Compare June 28, 2026 05:19
rspec-expectations renamed its private diff helper from
ExpectedsForMultipleDiffs to MultiMatcherDiff in 3.12.4 and changed its
signature (actual moved from message_with_diff into the from factory).

A prior change removed the version pin and the broken require but left
the call site referencing the old class, turning the original LoadError
into a latent NameError that fires whenever a resource-parameter
assertion renders a diff.

Add a diff_for helper that detects which class is available and uses the
matching API, so chefspec works across the full rspec ~> 3.0 range. Also
drop the now-stale gemspec comment describing a pin that no longer
exists, and replace the pending resource_matcher spec with a test
covering the diff-rendering failure path.

Signed-off-by: Tim Smith <tsmith84@proton.me>
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.

missing expecteds_for_multiple_diffs file in rspec gem

1 participant