Skip to content

feat: add >> raises(...) for exception stubbing in interactions#6

Merged
JPDuchesne merged 1 commit intomasterfrom
jpd/interaction-raises
Feb 27, 2026
Merged

feat: add >> raises(...) for exception stubbing in interactions#6
JPDuchesne merged 1 commit intomasterfrom
jpd/interaction-raises

Conversation

@JPDuchesne
Copy link
Copy Markdown
Contributor

Summary

  • Introduces the outcome concept to interactions, replacing the raw return_value field. The >> operator now produces a typed outcome node (:rspock_returns or :rspock_raises) at parse time.
  • The transformation generically forwards the outcome type and args to Mocha via an explicit OUTCOME_METHODS mapping — no branching or string manipulation.
  • Adds OutcomeNode, ReturnsNode, and RaisesNode to the node type hierarchy for consistency with other RSpock node types.

New syntax

# Stub an exception
1 * repository.find(42) >> raises(RecordNotFound)

# With message
1 * repository.find(42) >> raises(RecordNotFound, "not found")

# With instance
1 * repository.find(42) >> raises(RecordNotFound.new("not found"))

Files changed

  • lib/rspock/ast/parser/interaction_parser.rbparse_outcome wraps >> values in typed nodes
  • lib/rspock/ast/node.rbOutcomeNode / ReturnsNode / RaisesNode; InteractionNode#outcome replaces #return_value
  • lib/rspock/ast/interaction_to_mocha_mock_transformation.rb — generic outcome forwarding via OUTCOME_METHODS constant
  • README.md — new "Stubbing Exceptions" section, updated interaction anatomy diagram
  • Tests updated and new tests added for all raises variants

Test plan

  • All 189 existing tests pass (no regressions)
  • New parser tests: >> raises(Ex), >> raises(Ex, msg) produce correct :rspock_raises nodes
  • New transformation tests: raises(Ex), raises(Ex, msg), raises(Ex.new(msg)), with params, with range cardinality

Made with Cursor

Introduces the "outcome" concept to interactions, replacing the raw
return_value field. The >> operator now produces a typed outcome node
(:rspock_returns or :rspock_raises) at parse time, and the transformation
generically forwards the outcome type and args to Mocha.

Made-with: Cursor
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@JPDuchesne JPDuchesne merged commit 838b6c1 into master Feb 27, 2026
3 checks passed
@JPDuchesne JPDuchesne deleted the jpd/interaction-raises branch February 27, 2026 19:32
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