Skip to content

Allow setting RSpec expectations on a stub with options#1128

Open
inkstak wants to merge 1 commit into
bblimke:masterfrom
inkstak:feature-have_been_requested_with_body
Open

Allow setting RSpec expectations on a stub with options#1128
inkstak wants to merge 1 commit into
bblimke:masterfrom
inkstak:feature-have_been_requested_with_body

Conversation

@inkstak

@inkstak inkstak commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

This feature allows to verify a stubbed request has been requested with various options such as body, query or headers.

stubbed_request = stub_request(:post, "example.com")

# ... make requests ...

expect(stubbed_request).to have_been_requested.twice
expect(stubbed_request).to have_been_requested.once.with(body: {"a" => [1, 2, 3]})
expect(stubbed_request).to have_been_requested.once.with(body: {"a" => [4, 5, 6]})

The differences with setting these options before making the request is that we can create a generic stubbed request and only then verify it has been made with our expectations.

The implementation is pretty simple since it uses the already existing RequestExecutionVerifier to pass the options.

We use this as a monkeypatch in our projects since years. I think it was time to make a PR.
I you think this is an interesting feature, I'll be happy to dive deeper and add tests to the PR.

@inkstak inkstak changed the title Allow setting expectations in RSpec against a stub with options Allow setting RSpec expectations on a stub with options Jun 12, 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