mocha 2.6.0 → 2.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/README.md +1 -1
- data/RELEASE.md +30 -0
- data/lib/mocha/mock.rb +17 -20
- data/lib/mocha/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 36441d2fc56cc4d162b3f1e790c6add3c70eebac844ec6e6b275ef1b6e5f268c
|
4
|
+
data.tar.gz: b63504e88684874b3609b91096bcd90d18f31639b3d32ba95e36f48e8fc67ecf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 43c0128284d592878e833404f53f95a3c64bfeca18c85f7f94313b475566f98dc0993ed2b41a9d5118c1b4aabbb99e8848510d7aa3b4afa55804d67c0dd25658
|
7
|
+
data.tar.gz: d9b9785fbf25b80552a7f25e649a5e3ce08ef628c82a1dd36bccf260867156a4ac2c6cf1726e720c6ed8d836a8a1aa0e2441e29e869e65c244ac0c51f93c9423
|
data/Gemfile
CHANGED
@@ -25,6 +25,10 @@ if RUBY_VERSION >= '2.2.0'
|
|
25
25
|
gem 'jaro_winkler', '>= 1.5.5'
|
26
26
|
gem 'rubocop', '> 0.56', '<= 0.58.2'
|
27
27
|
end
|
28
|
+
if RUBY_ENGINE == 'jruby'
|
29
|
+
# Workaround for https://github.com/jruby/jruby/issues/8488
|
30
|
+
gem 'jar-dependencies', '~> 0.4.1'
|
31
|
+
end
|
28
32
|
if ENV['MOCHA_GENERATE_DOCS']
|
29
33
|
gem 'redcarpet'
|
30
34
|
gem 'yard'
|
data/README.md
CHANGED
@@ -276,7 +276,7 @@ Maybe, but probably not. Partial mocking changes the state of objects in the `Ob
|
|
276
276
|
|
277
277
|
Stubs and expectations are basically the same thing. A stub is just an expectation of zero or more invocations. The `Expectation#stubs` method is syntactic sugar to make the intent of the test more explicit.
|
278
278
|
|
279
|
-
When a method is invoked on a mock object, the mock object searches through its expectations from newest to oldest to find one that matches the invocation. After the invocation, the matching expectation might stop matching further invocations.
|
279
|
+
When a method is invoked on a mock object, the mock object searches through its expectations from newest to oldest to find one that matches the invocation. After the invocation, the matching expectation might stop matching further invocations. If the expectation that matches the invocation has a cardinality of "never", then an unexpected invocation error is reported.
|
280
280
|
|
281
281
|
See the [documentation](https://mocha.jamesmead.org/Mocha/Mock.html) for `Mocha::Mock` for further details.
|
282
282
|
|
data/RELEASE.md
CHANGED
@@ -1,11 +1,41 @@
|
|
1
1
|
# Release Notes
|
2
2
|
|
3
|
+
## 2.7.0
|
4
|
+
|
5
|
+
### External changes
|
6
|
+
|
7
|
+
* Fail fast if invocation matches never expectation (#679, #678, #490, #131 & #44) - thanks to @ducmtran & @davidstosik for reporting
|
8
|
+
|
9
|
+
### Internal changes
|
10
|
+
|
11
|
+
* Workaround for JRuby jar-dependencies issue (#690)
|
12
|
+
* Ruby v3.4 stacktrace uses single-quote vs backtick (#688 & #689) - thanks to Vít Ondruch
|
13
|
+
|
14
|
+
**WARNING: This release fixes a very _old_ bug**
|
15
|
+
* The bug relates to the use of `Expectation#never` in combination with other expectations on the same method.
|
16
|
+
* Please ensure you fix the relevant deprecation warnings when running against v2.6.1 *before* upgrading to v2.7.0.
|
17
|
+
* Previously, the following test would have passed, but now it will fail with an unexpected invocation error on the `foo.bar` line.
|
18
|
+
|
19
|
+
foo = mock('foo')
|
20
|
+
foo.stubs(:bar)
|
21
|
+
foo.expects(:bar).never
|
22
|
+
foo.bar
|
23
|
+
|
24
|
+
## 2.6.1
|
25
|
+
|
26
|
+
### External changes
|
27
|
+
|
28
|
+
* Fix logic for displaying deprecation warning for expectation with never cardinality (#686) - thanks to @davidstosik for reporting
|
29
|
+
|
3
30
|
## 2.6.0
|
4
31
|
|
5
32
|
### External changes
|
6
33
|
|
7
34
|
* Expectation with never cardinality should display deprecation warning (#681) - thanks to @ducmtran for reporting and testing
|
8
35
|
|
36
|
+
**WARNING: This release results in some incorrect deprecation warnings:**
|
37
|
+
* The logic for displaying the deprecation warnings is fixed in v2.6.1 (#686).
|
38
|
+
|
9
39
|
### Internal changes
|
10
40
|
|
11
41
|
* Simplify backtrace related assertions (#680)
|
data/lib/mocha/mock.rb
CHANGED
@@ -35,6 +35,9 @@ module Mocha
|
|
35
35
|
# while an +expects(:foo).at_least_once+ expectation will always be matched
|
36
36
|
# against invocations.
|
37
37
|
#
|
38
|
+
# However, note that if the expectation that matches the invocation has a
|
39
|
+
# cardinality of "never", then an unexpected invocation error is reported.
|
40
|
+
#
|
38
41
|
# This scheme allows you to:
|
39
42
|
#
|
40
43
|
# - Set up default stubs in your the +setup+ method of your test class and
|
@@ -318,25 +321,27 @@ module Mocha
|
|
318
321
|
ruby2_keywords(:method_missing)
|
319
322
|
|
320
323
|
# @private
|
321
|
-
def handle_method_call(symbol, arguments, block)
|
324
|
+
def handle_method_call(symbol, arguments, block) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
322
325
|
check_expiry
|
323
326
|
check_responder_responds_to(symbol)
|
324
327
|
invocation = Invocation.new(self, symbol, arguments, block)
|
325
328
|
|
326
329
|
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
|
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
if matching_expectation_ignoring_order || (!matching_expectation_ignoring_order && !@everything_stubbed)
|
338
|
-
raise_unexpected_invocation_error(invocation, matching_expectation_ignoring_order)
|
331
|
+
index = 0
|
332
|
+
while index < matching_expectations.length
|
333
|
+
matching_expectation = matching_expectations[index]
|
334
|
+
if matching_expectation.invocations_never_allowed?
|
335
|
+
raise_unexpected_invocation_error(invocation, matching_expectation)
|
336
|
+
elsif matching_expectation.invocations_allowed?
|
337
|
+
return matching_expectation.invoke(invocation)
|
339
338
|
end
|
339
|
+
index += 1
|
340
|
+
end
|
341
|
+
|
342
|
+
matching_expectation_ignoring_order = all_expectations.match(invocation, ignoring_order: true)
|
343
|
+
if matching_expectation_ignoring_order || (!matching_expectation_ignoring_order && !@everything_stubbed) # rubocop:disable Style/GuardClause
|
344
|
+
raise_unexpected_invocation_error(invocation, matching_expectation_ignoring_order)
|
340
345
|
end
|
341
346
|
end
|
342
347
|
|
@@ -381,14 +386,6 @@ module Mocha
|
|
381
386
|
|
382
387
|
private
|
383
388
|
|
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
|
-
|
392
389
|
def raise_unexpected_invocation_error(invocation, matching_expectation)
|
393
390
|
if @unexpected_invocation.nil?
|
394
391
|
@unexpected_invocation = invocation
|
data/lib/mocha/version.rb
CHANGED
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.
|
4
|
+
version: 2.7.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-
|
11
|
+
date: 2024-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby2_keywords
|