mocha 2.5.0 → 2.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e6e1cd848b633850f0774eb601a31b7c574658eaa1be031443a235410e73ef83
4
- data.tar.gz: 67f6af8a50e7f0cbc294367eb04696e6f40a04d44c432b17cb9c534b006a6a65
3
+ metadata.gz: 427e4fdcdcceac0496dd9ad52802ae29be41ba102de0888e58f6c379c77ac24e
4
+ data.tar.gz: d2c3e87c6d5f861f1ae2124b758fd548e19f2299e1ebe69551b7483d0941516d
5
5
  SHA512:
6
- metadata.gz: 5508f0dce73db625638223279e9a51215fabbbaed47bd911c1a8359c81efad57aa32f7c3b672ad6b900e1848a4a31335102c3113319855f08a91997d85466264
7
- data.tar.gz: 37c2d7c0b5eaf2650a47a83b431e2c437f30f9b6bc0b902133b4d238e11b15daa3c005c738098bf326e3bb0a38ef82376923f8ef0e6f892e8a180c6b04038729
6
+ metadata.gz: 7b82f53427cf92b742d97c551808e42f8b954148f7311f97bb52e4c1c15952515cce115e23022ce10a5d52e07238dc8ce7188d810de5f4a7e193ca59d72b2e4f
7
+ data.tar.gz: c345496f74391ca1b8b2f6a4b0d3947f30c119a89416c7f69037b064c6ca207a77607fa8bd93443152c196f4f5fef93cccc984c4a75040ee675d140237dd0f8b
data/RELEASE.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Release Notes
2
2
 
3
+ ## 2.6.1
4
+
5
+ ### External changes
6
+
7
+ * Fix logic for displaying deprecation warning for expectation with never cardinality (#686) - thanks to @davidstosik for reporting
8
+
9
+ ## 2.6.0
10
+
11
+ ### External changes
12
+
13
+ * Expectation with never cardinality should display deprecation warning (#681) - thanks to @ducmtran for reporting and testing
14
+
15
+ **WARNING: This release results in some incorrect deprecation warnings:**
16
+ * The logic for displaying the deprecation warnings is fixed in v2.6.1 (#686).
17
+
18
+ ### Internal changes
19
+
20
+ * Simplify backtrace related assertions (#680)
21
+ * Remove unused `ExpectationList#match_but_out_of_order` (f2fa9919)
22
+
3
23
  ## 2.5.0
4
24
 
5
25
  ### External changes
@@ -34,6 +34,10 @@ module Mocha
34
34
  @invocations.size < maximum
35
35
  end
36
36
 
37
+ def invocations_never_allowed?
38
+ maximum.zero?
39
+ end
40
+
37
41
  def satisfied?
38
42
  @invocations.size >= required
39
43
  end
@@ -653,6 +653,11 @@ module Mocha
653
653
  @cardinality.invocations_allowed?
654
654
  end
655
655
 
656
+ # @private
657
+ def invocations_never_allowed?
658
+ @cardinality.invocations_never_allowed?
659
+ end
660
+
656
661
  # @private
657
662
  def satisfied?
658
663
  @cardinality.satisfied?
@@ -21,14 +21,14 @@ module Mocha
21
21
  matching_expectations(invocation, ignoring_order: ignoring_order).first
22
22
  end
23
23
 
24
- def match_but_out_of_order(invocation)
25
- matching_expectations(invocation).first
26
- end
27
-
28
24
  def match_allowing_invocation(invocation)
29
25
  matching_expectations(invocation).detect(&:invocations_allowed?)
30
26
  end
31
27
 
28
+ def match_never_allowing_invocation(invocation)
29
+ matching_expectations(invocation).detect(&:invocations_never_allowed?)
30
+ end
31
+
32
32
  def verified?(assertion_counter = nil)
33
33
  @expectations.all? { |expectation| expectation.verified?(assertion_counter) }
34
34
  end
@@ -53,8 +53,6 @@ module Mocha
53
53
  self.class.new(to_a + other.to_a)
54
54
  end
55
55
 
56
- private
57
-
58
56
  def matching_expectations(invocation, ignoring_order: false)
59
57
  @expectations.select { |e| e.match?(invocation, ignoring_order: ignoring_order) }
60
58
  end
data/lib/mocha/mock.rb CHANGED
@@ -8,6 +8,7 @@ require 'mocha/method_matcher'
8
8
  require 'mocha/parameters_matcher'
9
9
  require 'mocha/argument_iterator'
10
10
  require 'mocha/expectation_error_factory'
11
+ require 'mocha/deprecation'
11
12
 
12
13
  module Mocha
13
14
  # Traditional mock object.
@@ -317,14 +318,31 @@ module Mocha
317
318
  ruby2_keywords(:method_missing)
318
319
 
319
320
  # @private
320
- def handle_method_call(symbol, arguments, block)
321
+ def handle_method_call(symbol, arguments, block) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
321
322
  check_expiry
322
323
  check_responder_responds_to(symbol)
323
324
  invocation = Invocation.new(self, symbol, arguments, block)
324
- if (matching_expectation_allowing_invocation = all_expectations.match_allowing_invocation(invocation))
325
- matching_expectation_allowing_invocation.invoke(invocation)
326
- elsif (matching_expectation = all_expectations.match(invocation, ignoring_order: true)) || (!matching_expectation && !@everything_stubbed)
327
- raise_unexpected_invocation_error(invocation, matching_expectation)
325
+
326
+ matching_expectations = all_expectations.matching_expectations(invocation)
327
+
328
+ index = 0
329
+ never_allowed_expectation = nil
330
+ while index < matching_expectations.length
331
+ matching_expectation = matching_expectations[index]
332
+ if matching_expectation.invocations_never_allowed?
333
+ never_allowed_expectation = matching_expectation
334
+ elsif matching_expectation.invocations_allowed?
335
+ if never_allowed_expectation
336
+ invocation_not_allowed_warning(invocation, never_allowed_expectation)
337
+ end
338
+ return matching_expectation.invoke(invocation)
339
+ end
340
+ index += 1
341
+ end
342
+
343
+ matching_expectation_ignoring_order = all_expectations.match(invocation, ignoring_order: true)
344
+ if matching_expectation_ignoring_order || (!matching_expectation_ignoring_order && !@everything_stubbed) # rubocop:disable Style/GuardClause
345
+ raise_unexpected_invocation_error(invocation, matching_expectation_ignoring_order)
328
346
  end
329
347
  end
330
348
 
@@ -369,6 +387,14 @@ module Mocha
369
387
 
370
388
  private
371
389
 
390
+ def invocation_not_allowed_warning(invocation, expectation)
391
+ messages = [
392
+ "The expectation defined at #{expectation.definition_location} does not allow invocations, but #{invocation.call_description} was invoked.",
393
+ 'This invocation will cause the test to fail fast in a future version of Mocha.'
394
+ ]
395
+ Deprecation.warning(messages.join(' '))
396
+ end
397
+
372
398
  def raise_unexpected_invocation_error(invocation, matching_expectation)
373
399
  if @unexpected_invocation.nil?
374
400
  @unexpected_invocation = invocation
data/lib/mocha/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Mocha
2
- VERSION = '2.5.0'.freeze
2
+ VERSION = '2.6.1'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocha
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.0
4
+ version: 2.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mead
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-10-23 00:00:00.000000000 Z
11
+ date: 2024-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby2_keywords
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
154
154
  - !ruby/object:Gem::Version
155
155
  version: '0'
156
156
  requirements: []
157
- rubygems_version: 3.4.1
157
+ rubygems_version: 3.5.22
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: Mocking and stubbing library