Repository navigation
Failing test for options hash / kwarg compat - #20
Closed
tjefferson08 wants to merge 1 commit into
Closed
tjefferson08 wants to merge 1 commit into
tjefferson08 wants to merge 1 commit into
Conversation
Only this time, it's in the initializer!
Member
|
Give a mouse a method… 🐭 |
rosston
added a commit
that referenced
this pull request
Oct 12, 2026
Replacing a class swaps `new` and its class methods for generic
`(*args, **kwargs)` lambdas, so Ruby always splits brace-less keywords
like `Klass.new(item: "hello")` into kwargs. Mocktail then validated
those kwargs against the real method, and when that method takes an
options hash (`def initialize(opts = {})`) rather than keywords, it
raised `ArgumentError: unknown keyword: :item`, even though Ruby 3
passes keywords to a method with no keyword params as a trailing
positional hash. Instance-method doubles never had this problem
because their lambdas are generated from the real signature.
Add FoldsKeywordsIntoOptionsHash, which applies Ruby's rule: fold
non-empty kwargs into a trailing hash when the original method has no
:key, :keyreq, :keyrest, or :nokey params. It reads params through
GrabsOriginalMethodParameters so Sorbet-wrapped methods report their
real signature. Call it before building the Call in HandlesDryNewCall
and in the mocked branch of replaced class methods, so validation,
call logging, and stub matching all see the same shape instance
doubles already record.
test_replace_class asserted that `House.room(wrong: :arg)` raises for
`def self.room(room_name)`, which real Ruby accepts, so it now asserts
on a call Ruby also rejects.
Picks up the failing test from #20 and makes it pass.
Member
|
This was fixed in #34 and released in 3.0.1. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Only this time, it's in the initializer!
Very much appreciate the work done in #17 and #14
If I understand the landscape correctly, I'm asking about extending similar compatibility/support to initializers