Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ This document is formatted according to the principles of [Keep A CHANGELOG](htt
Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blob/master/CONTRIBUTING.md) for more info on how to contribute to Cucumber.

## [Unreleased]
### Fixed
- Fixed `cucumber/rspec/doubles` calling `RSpec::Mocks.setup` with an argument rspec-mocks 3 does not accept, and restored
the verification of message expectations after each scenario

## [12.0.0] - 2026-10-12
### Added
Expand Down
51 changes: 51 additions & 0 deletions features/docs/writing_support_code/rspec_doubles.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
Feature: RSpec doubles

Requiring `cucumber/rspec/doubles` makes rspec-mocks available in step definitions. Doubles and stubs are reset
after each scenario, and a message expectation that was not met fails the scenario.

Scenario: Stubs are reset between scenarios and unmet expectations fail
Given a file named "features/support/env.rb" with:
"""
require 'cucumber/rspec/doubles'
"""
And a file named "features/step_definitions/steps.rb" with:
"""
class Greeter
def self.greeting = 'hello'
end

Given('the greeting is stubbed') do
allow(Greeter).to receive(:greeting).and_return('stubbed')
end

Given('a greeting is expected') do
expect(Greeter).to receive(:greeting)
end

Then('the greeting is {string}') do |greeting|
expect(Greeter.greeting).to eq(greeting)
end
"""
And a file named "features/doubles.feature" with:
"""
Feature: Doubles

Scenario: Stubbed
Given the greeting is stubbed
Then the greeting is "stubbed"

Scenario: No longer stubbed
Then the greeting is "hello"

Scenario: Unmet expectation
Given a greeting is expected
"""
When I run `cucumber features/doubles.feature`
Then it should fail with:
"""
Failing Scenarios:
cucumber features/doubles.feature:10 # Scenario: Unmet expectation

3 scenarios (1 failed, 2 passed)
"""
And the output should contain "expected: 1 time with any arguments"
4 changes: 3 additions & 1 deletion lib/cucumber/rspec/doubles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
World(RSpec::Mocks::ExampleMethods)

Before do
RSpec::Mocks.setup(self)
RSpec::Mocks.setup
end

After do
RSpec::Mocks.verify
ensure
RSpec::Mocks.teardown
end
Loading