Skip to content

feat: Spock-style implicit assertions for Then/Expect blocks#7

Merged
JPDuchesne merged 1 commit intomasterfrom
jpd/spock-style-assertions
Feb 28, 2026
Merged

feat: Spock-style implicit assertions for Then/Expect blocks#7
JPDuchesne merged 1 commit intomasterfrom
jpd/spock-style-assertions

Conversation

@JPDuchesne
Copy link
Copy Markdown
Contributor

Summary

  • Spock-style implicit assertions: every non-assignment statement in Then/Expect blocks is now an assertion — no assertion API needed, matching Spock's core model.
  • Binary operator assertions: ==, !=, =~, !~, >, <, >=, <= map to specialized Minitest assertions (assert_equal, refute_equal, assert_match, refute_match, assert_operator) with clear error messages.
  • General statement assertions: bare boolean expressions (e.g. obj.valid?) are wrapped in assert_equal(true, expr) with the original source text in the error message. Negation (!expr) is detected and maps to assert_equal(false, inner_expr).
  • New pipeline: StatementParser classifies statements at parse time; StatementToAssertionTransformation handles Minitest mapping. Replaces the old ComparisonToAssertionTransformation.
  • Documentation: README updated with assertion tables, examples, and expanded Then/Expect block docs. CHANGELOG backfilled for all prior versions (1.0.0 through 2.3.1). Release instructions updated to remind about CHANGELOG maintenance.

Test plan

  • bundle exec rake test passes (unit + integration tests)
  • New StatementParserTest covers assignment passthrough, binary operator classification, and general statement wrapping with source text
  • New StatementToAssertionTransformationTest covers all 8 binary operators, general statements, and negation
  • Updated ThenBlockTest and ExpectBlockTest verify new node types
  • Integration tests in ExampleRSpockTest exercise =~, >, <, >=, <=, bare predicates, negation, and variable assignments in Expect/Then blocks
  • CHANGELOG renders correctly on GitHub with comparison links

Made with Cursor

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Feb 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@JPDuchesne JPDuchesne force-pushed the jpd/spock-style-assertions branch 2 times, most recently from a8e301b to 9e76fe6 Compare February 28, 2026 19:28
Every non-assignment statement in Then/Expect blocks is now an assertion,
matching Spock's core model. Binary operators (==, !=, =~, !~, >, <, >=, <=)
map to specialized Minitest assertions; bare boolean expressions use
assert_equal(true/false, expr) with the original source text in the error
message. Negation (!expr) is detected automatically.

Introduces StatementParser for classification and
StatementToAssertionTransformation for Minitest mapping. Removes the old
ComparisonToAssertionTransformation. Backfills CHANGELOG for all prior
versions and updates README documentation.

Made-with: Cursor
@JPDuchesne JPDuchesne force-pushed the jpd/spock-style-assertions branch from 9e76fe6 to 789d55c Compare February 28, 2026 19:34
@JPDuchesne JPDuchesne merged commit 1d2b991 into master Feb 28, 2026
3 checks passed
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