mocha 2.6.1 → 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 +21 -0
- data/lib/mocha/mock.rb +4 -13
- 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,5 +1,26 @@
|
|
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
|
+
|
3
24
|
## 2.6.1
|
4
25
|
|
5
26
|
### External changes
|
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
|
@@ -326,15 +329,11 @@ module Mocha
|
|
326
329
|
matching_expectations = all_expectations.matching_expectations(invocation)
|
327
330
|
|
328
331
|
index = 0
|
329
|
-
never_allowed_expectation = nil
|
330
332
|
while index < matching_expectations.length
|
331
333
|
matching_expectation = matching_expectations[index]
|
332
334
|
if matching_expectation.invocations_never_allowed?
|
333
|
-
|
335
|
+
raise_unexpected_invocation_error(invocation, matching_expectation)
|
334
336
|
elsif matching_expectation.invocations_allowed?
|
335
|
-
if never_allowed_expectation
|
336
|
-
invocation_not_allowed_warning(invocation, never_allowed_expectation)
|
337
|
-
end
|
338
337
|
return matching_expectation.invoke(invocation)
|
339
338
|
end
|
340
339
|
index += 1
|
@@ -387,14 +386,6 @@ module Mocha
|
|
387
386
|
|
388
387
|
private
|
389
388
|
|
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
|
-
|
398
389
|
def raise_unexpected_invocation_error(invocation, matching_expectation)
|
399
390
|
if @unexpected_invocation.nil?
|
400
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
|