Skip to content

Commit

Permalink
Handle last positional arg in with statement
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabigeek committed Aug 23, 2022
1 parent 4667ce6 commit 2b1067b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mocha/parameter_matchers/last_positional_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(value)
def matches?(available_parameters)
parameter = available_parameters.shift
if RUBY_V3_PLUS
return false if Hash.ruby2_keywords_hash?(@value) && !Hash.ruby2_keywords_hash?(parameter)
return false unless Hash.ruby2_keywords_hash?(@value) == Hash.ruby2_keywords_hash?(parameter)
end

parameter == @value
Expand Down
5 changes: 5 additions & 0 deletions test/unit/expectation_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ def test_should_not_match_keyword_args_with_last_positional_hashes
expectation = new_expectation.with(1, Hash.ruby2_keywords_hash({ :a => 1 }))
assert !expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, { :a => 1 }))
end

def test_should_not_match_last_positional_hashes_with_keyword_args
expectation = new_expectation.with(1, { :a => 1 })
assert !expectation.match?(Invocation.new(:irrelevant, :expected_method, 1, Hash.ruby2_keywords_hash({ :a => 1 })))
end
end

def test_should_allow_invocations_until_expected_invocation_count_is_one_and_actual_invocation_count_would_be_two
Expand Down

0 comments on commit 2b1067b

Please sign in to comment.