From 99f3f6bf16956822b632e83fdda2e6c8ecdc5b80 Mon Sep 17 00:00:00 2001 From: James Mead Date: Sun, 8 Dec 2024 18:11:35 +0000 Subject: [PATCH] Document Expectation#with called multiple times This is accidental and possibly undesirable behaviour, but it seems like an improvement to at least document the current behaviour. --- lib/mocha/expectation.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/mocha/expectation.rb b/lib/mocha/expectation.rb index cf794c10..b3b6c095 100644 --- a/lib/mocha/expectation.rb +++ b/lib/mocha/expectation.rb @@ -193,6 +193,8 @@ def at_most_once # # May be used with Ruby literals or variables for exact matching or with parameter matchers for less-specific matching, e.g. {ParameterMatchers#includes}, {ParameterMatchers#has_key}, etc. See {ParameterMatchers} for a list of all available parameter matchers. # + # Note that if {#with} is called multiple times on the same expectation, the last call takes precedence; other calls are ignored. + # # Positional arguments were separated from keyword arguments in Ruby v3 (see {https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0 this article}). In relation to this a new configuration option ({Configuration#strict_keyword_argument_matching=}) is available in Ruby >= 2.7. # # When {Configuration#strict_keyword_argument_matching=} is set to +false+ (which is currently the default), a positional +Hash+ and a set of keyword arguments passed to {#with} are treated the same for the purposes of parameter matching. However, a deprecation warning will be displayed if a positional +Hash+ matches a set of keyword arguments or vice versa. This is because {Configuration#strict_keyword_argument_matching=} will default to +true+ in the future.