mocha 2.5.0 → 2.6.0

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: 1a2fb97d6eb77787f83c9199c83fcadd3605a07ec431a5e3d47a0d2ee6ff2c67
4
+ data.tar.gz: 42815979d195d003a14b42f36c4818fa6b1ca59d498e5ca3b743338a6dc13af8
5
5
  SHA512:
6
- metadata.gz: 5508f0dce73db625638223279e9a51215fabbbaed47bd911c1a8359c81efad57aa32f7c3b672ad6b900e1848a4a31335102c3113319855f08a91997d85466264
7
- data.tar.gz: 37c2d7c0b5eaf2650a47a83b431e2c437f30f9b6bc0b902133b4d238e11b15daa3c005c738098bf326e3bb0a38ef82376923f8ef0e6f892e8a180c6b04038729
6
+ metadata.gz: 8b3494f44f9b603513afa227fd58f499275155695ae2c5e6759f11a0288d4f0fc706d2be90c01e12b8166caf328a8caf543303671310f91a4e3f28b130319973
7
+ data.tar.gz: d8b24445529930e616433246b41e43c78f034842967dff64df9c026be1dab5b5f3b671115d984608166caae6e7a73d253dc8e12bcca8b60514aefbd0520b9c76
data/RELEASE.md CHANGED
@@ -1,5 +1,16 @@
1
1
  # Release Notes
2
2
 
3
+ ## 2.6.0
4
+
5
+ ### External changes
6
+
7
+ * Expectation with never cardinality should display deprecation warning (#681) - thanks to @ducmtran for reporting and testing
8
+
9
+ ### Internal changes
10
+
11
+ * Simplify backtrace related assertions (#680)
12
+ * Remove unused `ExpectationList#match_but_out_of_order` (f2fa9919)
13
+
3
14
  ## 2.5.0
4
15
 
5
16
  ### 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.
@@ -321,10 +322,21 @@ module Mocha
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
+
326
+ matching_expectations = all_expectations.matching_expectations(invocation)
327
+ matching_expectation_allowing_invocation = matching_expectations.detect(&:invocations_allowed?)
328
+ matching_expectation_never_allowing_invocation = matching_expectations.detect(&:invocations_never_allowed?)
329
+
330
+ if matching_expectation_allowing_invocation
331
+ if matching_expectation_never_allowing_invocation
332
+ invocation_not_allowed_warning(invocation, matching_expectation_never_allowing_invocation)
333
+ end
325
334
  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)
335
+ else
336
+ matching_expectation_ignoring_order = all_expectations.match(invocation, ignoring_order: true)
337
+ if matching_expectation_ignoring_order || (!matching_expectation_ignoring_order && !@everything_stubbed)
338
+ raise_unexpected_invocation_error(invocation, matching_expectation_ignoring_order)
339
+ end
328
340
  end
329
341
  end
330
342
 
@@ -369,6 +381,14 @@ module Mocha
369
381
 
370
382
  private
371
383
 
384
+ def invocation_not_allowed_warning(invocation, expectation)
385
+ messages = [
386
+ "The expectation defined at #{expectation.definition_location} does not allow invocations, but #{invocation.call_description} was invoked.",
387
+ 'This invocation will cause the test to fail fast in a future version of Mocha.'
388
+ ]
389
+ Deprecation.warning(messages.join(' '))
390
+ end
391
+
372
392
  def raise_unexpected_invocation_error(invocation, matching_expectation)
373
393
  if @unexpected_invocation.nil?
374
394
  @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.0'.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.0
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-24 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