Skip to content

Fix cucumber/rspec/doubles for rspec-mocks 3 - #1914

Open
erikaxel wants to merge 1 commit into
cucumber:mainfrom
erikaxel:fix-rspec-doubles
Open

erikaxel wants to merge 1 commit into
cucumber:mainfrom
erikaxel:fix-rspec-doubles

Conversation

@erikaxel

Copy link
Copy Markdown

Description

Since 12.0.0, require 'cucumber/rspec/doubles' breaks every scenario in a project using rspec-mocks 3:

wrong number of arguments (given 1, expected 0) (ArgumentError)
rspec-mocks-3.13.8/lib/rspec/mocks.rb:38:in 'RSpec::Mocks.setup'
cucumber-12.0.0/lib/cucumber/rspec/doubles.rb:8:in 'block in <main>'

#1847 removed the rspec-mocks version guard from lib/cucumber/rspec/doubles.rb, but kept the branch for rspec-mocks older than 2.9.9 (RSpec::Mocks.setup(self)) rather than the current one. rspec-mocks 3.0 removed that argument, so the hook raises on every rspec-mocks 3 release. The same change dropped RSpec::Mocks.verify from the After hook, so an unmet expect(...).to receive(...) would no longer fail the scenario. Neither change is mentioned in the 12.0.0 changelog or upgrading notes, so I take both to be unintended.

This restores the hooks the file had for rspec-mocks 3 before 12.0.0 (setup, then verify with teardown in an ensure), the same sequence features/lib/support/command_line.rb uses. Nothing in the suite loaded cucumber/rspec/doubles before, so this adds features/docs/writing_support_code/rspec_doubles.feature, which checks that a stub works within its scenario, is reset for the next one, and that an unmet expectation fails the scenario. The feature fails against the 12.0.0 file with the ArgumentError above.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • Tests have been added for any changes to behaviour of the code
  • New and existing tests are passing locally and on CI
  • bundle exec rubocop reports no offenses
  • RDoc comments have been updated
  • CHANGELOG.md has been updated

Ran locally on Ruby 4.0: rake spec (606 examples, 0 failures), rake cucumber (231 scenarios passed), rake cck (111 examples, 0 failures) and rubocop (no offenses). Also checked against a Rails app's suite of 20 Selenium scenarios that stub with allow(...).to receive.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@mvz mvz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @luke-hill what do you think?

This branch has not been deployed

No deployments
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.

2 participants