Skip to content

Conversation

@hadley
Copy link
Member

@hadley hadley commented Aug 9, 2025

New local_mocked_s3_method(), local_mocked_s4_method(), and local_mocked_r6_class() allow you to mock S3 and S4 methods and R6 classes.

Fixes #1892. Fixes #1916.

Copy link
Member

@EmilHvitfeldt EmilHvitfeldt left a comment

Choose a reason for hiding this comment

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

looking good!

@claude
Copy link

claude bot commented Aug 13, 2025

Claude finished @hadley's task —— View job


Code Review

  • Read main implementation file R/mock-oo.R
  • Review test file and snapshots
  • Check for potential bugs, edge cases, error handling
  • Provide minimal feedback

Issues Found

Bug in R6 mocking (line 94): The string interpolation "{class$classname}" won't work as intended. In R, this creates a literal string "{class$classname}" rather than interpolating the value. Should be:

local_mocked_bindings(!!class$classname := mocked_class, .env = frame)

or

name <- class$classname
local_mocked_bindings("{name}" := mocked_class, .env = frame)

Unused variable: df in test-mock-oo.R (noted by reviewer but not addressed).

Otherwise the implementation looks solid - good input validation, proper cleanup with withr::defer, and comprehensive test coverage.

@hadley hadley merged commit c0c1fff into main Aug 13, 2025
12 checks passed
@hadley hadley deleted the oo-mocking branch August 13, 2025 13:04
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.

Some way to mock S4 methods Mocking for R6 methods

3 participants