rspec-mocks 3.10.2 → 3.11.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/Changelog.md +27 -1
- data/README.md +1 -1
- data/lib/rspec/mocks/argument_list_matcher.rb +18 -3
- data/lib/rspec/mocks/matchers/receive.rb +1 -0
- data/lib/rspec/mocks/matchers/receive_message_chain.rb +1 -1
- data/lib/rspec/mocks/message_expectation.rb +74 -3
- data/lib/rspec/mocks/method_double.rb +3 -0
- data/lib/rspec/mocks/proxy.rb +6 -0
- data/lib/rspec/mocks/verifying_double.rb +2 -10
- data/lib/rspec/mocks/version.rb +1 -1
- data.tar.gz.sig +0 -0
- metadata +11 -11
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93e990c0ca803cda14a587b44a4a6148fd60df472f56e58c54be5a2c8ef4a655
|
4
|
+
data.tar.gz: db0535d24fb98fa0da5c5de3356b687e1b95773624dd38132444f74a57c5d0b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e74e72aec89ffce718f693bfda425f142bfd7139d90c57ff02e62ac461d99f9458df2ffba237bd9163e1665fd9b03a0221f723552d84bffb539a567c3b98f71
|
7
|
+
data.tar.gz: 6b2b9c447b777b74fcf50eb62a9674b0a4e321cf71165d340017f1ec9050a676c818a608d4d99bb5bb9c1178f44e57505e52c750b22520cb868b05b02812bfc2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,5 +1,31 @@
|
|
1
1
|
### Development
|
2
|
-
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.
|
2
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.11.1...3-11-maintenance)
|
3
|
+
|
4
|
+
### 3.11.1 / 2022-03-31
|
5
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.11.0...v3.11.1)
|
6
|
+
|
7
|
+
Bug Fixes:
|
8
|
+
|
9
|
+
* Add extra `ruby2_keywords` calls to properly designate methods using
|
10
|
+
`*args` to pass keyword around, fixes an issue with TruffleRuby.
|
11
|
+
(Benoit Daloze, #1464)
|
12
|
+
|
13
|
+
### 3.11.0 / 2022-02-09
|
14
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.3...v3.11.0)
|
15
|
+
|
16
|
+
Enhancements:
|
17
|
+
|
18
|
+
* Add `and_invoke` implementation for configuring responses to `receive`
|
19
|
+
(and `receive_messages`) with multiple callable objects. (Kyle Smith, #1411)
|
20
|
+
|
21
|
+
### 3.10.3 / 2022-01-28
|
22
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.2...v3.10.3)
|
23
|
+
|
24
|
+
Bug Fixes:
|
25
|
+
|
26
|
+
* Suppress warning by setting `$VERBOSE` to nil. (Nobuyoshi Nakada, #1414)
|
27
|
+
* Support keyword argument semantics when constraining argument expectations using
|
28
|
+
`with` on Ruby 3.0+ (Yusuke Endoh, #1394)
|
3
29
|
|
4
30
|
### 3.10.2 / 2021-01-27
|
5
31
|
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.1...v3.10.2)
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# RSpec Mocks [![Build Status](https://github.com/rspec/rspec-mocks/workflows/RSpec%20CI/badge.svg
|
1
|
+
# RSpec Mocks [![Build Status](https://github.com/rspec/rspec-mocks/workflows/RSpec%20CI/badge.svg)](https://github.com/rspec/rspec-mocks/actions) [![Code Climate](https://codeclimate.com/github/rspec/rspec-mocks.svg)](https://codeclimate.com/github/rspec/rspec-mocks)
|
2
2
|
rspec-mocks is a test-double framework for rspec with support for method stubs,
|
3
3
|
fakes, and message expectations on generated test-doubles and real objects
|
4
4
|
alike.
|
@@ -46,17 +46,32 @@ module RSpec
|
|
46
46
|
@expected_args = expected_args
|
47
47
|
ensure_expected_args_valid!
|
48
48
|
end
|
49
|
+
ruby2_keywords :initialize if respond_to?(:ruby2_keywords, true)
|
49
50
|
|
50
51
|
# @api public
|
51
|
-
# @param [Array]
|
52
|
+
# @param [Array] actual_args
|
52
53
|
#
|
53
54
|
# Matches each element in the `expected_args` against the element in the same
|
54
55
|
# position of the arguments passed to `new`.
|
55
56
|
#
|
56
57
|
# @see #initialize
|
57
|
-
def args_match?(*
|
58
|
-
|
58
|
+
def args_match?(*actual_args)
|
59
|
+
expected_args = resolve_expected_args_based_on(actual_args)
|
60
|
+
|
61
|
+
return false if expected_args.size != actual_args.size
|
62
|
+
|
63
|
+
if RUBY_VERSION >= "3"
|
64
|
+
# if both arguments end with Hashes, and if one is a keyword hash and the other is not, they don't match
|
65
|
+
if Hash === expected_args.last && Hash === actual_args.last
|
66
|
+
if !Hash.ruby2_keywords_hash?(actual_args.last) && Hash.ruby2_keywords_hash?(expected_args.last)
|
67
|
+
return false
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
Support::FuzzyMatcher.values_match?(expected_args, actual_args)
|
59
73
|
end
|
74
|
+
ruby2_keywords :args_match? if respond_to?(:ruby2_keywords, true)
|
60
75
|
|
61
76
|
# @private
|
62
77
|
# Resolves abstract arg placeholders like `no_args` and `any_args` into
|
@@ -13,7 +13,7 @@ module RSpec
|
|
13
13
|
@recorded_customizations = []
|
14
14
|
end
|
15
15
|
|
16
|
-
[:with, :and_return, :and_throw, :and_raise, :and_yield, :and_call_original].each do |msg|
|
16
|
+
[:with, :and_return, :and_invoke, :and_throw, :and_raise, :and_yield, :and_call_original].each do |msg|
|
17
17
|
define_method(msg) do |*args, &block|
|
18
18
|
@recorded_customizations << ExpectationCustomization.new(msg, args, block)
|
19
19
|
self
|
@@ -53,7 +53,7 @@ module RSpec
|
|
53
53
|
# etc.
|
54
54
|
#
|
55
55
|
# If the message is received more times than there are values, the last
|
56
|
-
# value is
|
56
|
+
# value is returned for every subsequent call.
|
57
57
|
#
|
58
58
|
# @return [nil] No further chaining is supported after this.
|
59
59
|
# @example
|
@@ -85,6 +85,48 @@ module RSpec
|
|
85
85
|
nil
|
86
86
|
end
|
87
87
|
|
88
|
+
# Tells the object to invoke a Proc when it receives the message. Given
|
89
|
+
# more than one value, the result of the first Proc is returned the first
|
90
|
+
# time the message is received, the result of the second Proc is returned
|
91
|
+
# the next time, etc, etc.
|
92
|
+
#
|
93
|
+
# If the message is received more times than there are Procs, the result of
|
94
|
+
# the last Proc is returned for every subsequent call.
|
95
|
+
#
|
96
|
+
# @return [nil] No further chaining is supported after this.
|
97
|
+
# @example
|
98
|
+
# allow(api).to receive(:get_foo).and_invoke(-> { raise ApiTimeout })
|
99
|
+
# api.get_foo # => raises ApiTimeout
|
100
|
+
# api.get_foo # => raises ApiTimeout
|
101
|
+
#
|
102
|
+
# allow(api).to receive(:get_foo).and_invoke(-> { raise ApiTimeout }, -> { raise ApiTimeout }, -> { :a_foo })
|
103
|
+
# api.get_foo # => raises ApiTimeout
|
104
|
+
# api.get_foo # => rasies ApiTimeout
|
105
|
+
# api.get_foo # => :a_foo
|
106
|
+
# api.get_foo # => :a_foo
|
107
|
+
# api.get_foo # => :a_foo
|
108
|
+
# # etc
|
109
|
+
def and_invoke(first_proc, *procs)
|
110
|
+
raise_already_invoked_error_if_necessary(__method__)
|
111
|
+
if negative?
|
112
|
+
raise "`and_invoke` is not supported with negative message expectations"
|
113
|
+
end
|
114
|
+
|
115
|
+
if block_given?
|
116
|
+
raise ArgumentError, "Implementation blocks aren't supported with `and_invoke`"
|
117
|
+
end
|
118
|
+
|
119
|
+
procs.unshift(first_proc)
|
120
|
+
if procs.any? { |p| !p.respond_to?(:call) }
|
121
|
+
raise ArgumentError, "Arguments to `and_invoke` must be callable."
|
122
|
+
end
|
123
|
+
|
124
|
+
@expected_received_count = [@expected_received_count, procs.size].max unless ignoring_args? || (@expected_received_count == 0 && @at_least)
|
125
|
+
self.terminal_implementation_action = AndInvokeImplementation.new(procs)
|
126
|
+
|
127
|
+
nil
|
128
|
+
end
|
129
|
+
|
88
130
|
# Tells the object to delegate to the original unmodified method
|
89
131
|
# when it receives the message.
|
90
132
|
#
|
@@ -97,9 +139,12 @@ module RSpec
|
|
97
139
|
# counter.increment
|
98
140
|
# expect(counter.count).to eq(original_count + 1)
|
99
141
|
def and_call_original
|
100
|
-
|
101
|
-
original.call(*args, &
|
142
|
+
block = lambda do |original, *args, &b|
|
143
|
+
original.call(*args, &b)
|
102
144
|
end
|
145
|
+
block = block.ruby2_keywords if block.respond_to?(:ruby2_keywords)
|
146
|
+
|
147
|
+
wrap_original(__method__, &block)
|
103
148
|
end
|
104
149
|
|
105
150
|
# Decorates the stubbed method with the supplied block. The original
|
@@ -322,6 +367,7 @@ module RSpec
|
|
322
367
|
@argument_list_matcher = ArgumentListMatcher.new(*args)
|
323
368
|
self
|
324
369
|
end
|
370
|
+
ruby2_keywords(:with) if respond_to?(:ruby2_keywords, true)
|
325
371
|
|
326
372
|
# Expect messages to be received in a specific order.
|
327
373
|
#
|
@@ -418,18 +464,22 @@ module RSpec
|
|
418
464
|
def matches?(message, *args)
|
419
465
|
@message == message && @argument_list_matcher.args_match?(*args)
|
420
466
|
end
|
467
|
+
ruby2_keywords :matches? if respond_to?(:ruby2_keywords, true)
|
421
468
|
|
422
469
|
def safe_invoke(parent_stub, *args, &block)
|
423
470
|
invoke_incrementing_actual_calls_by(1, false, parent_stub, *args, &block)
|
424
471
|
end
|
472
|
+
ruby2_keywords :safe_invoke if respond_to?(:ruby2_keywords, true)
|
425
473
|
|
426
474
|
def invoke(parent_stub, *args, &block)
|
427
475
|
invoke_incrementing_actual_calls_by(1, true, parent_stub, *args, &block)
|
428
476
|
end
|
477
|
+
ruby2_keywords :invoke if respond_to?(:ruby2_keywords, true)
|
429
478
|
|
430
479
|
def invoke_without_incrementing_received_count(parent_stub, *args, &block)
|
431
480
|
invoke_incrementing_actual_calls_by(0, true, parent_stub, *args, &block)
|
432
481
|
end
|
482
|
+
ruby2_keywords :invoke_without_incrementing_received_count if respond_to?(:ruby2_keywords, true)
|
433
483
|
|
434
484
|
def negative?
|
435
485
|
@expected_received_count == 0 && !@at_least
|
@@ -578,6 +628,7 @@ module RSpec
|
|
578
628
|
@actual_received_count += increment
|
579
629
|
end
|
580
630
|
end
|
631
|
+
ruby2_keywords :invoke_incrementing_actual_calls_by if respond_to?(:ruby2_keywords, true)
|
581
632
|
|
582
633
|
def has_been_invoked?
|
583
634
|
@actual_received_count > 0
|
@@ -683,6 +734,24 @@ module RSpec
|
|
683
734
|
end
|
684
735
|
end
|
685
736
|
|
737
|
+
# Handles the implementation of an `and_invoke` implementation.
|
738
|
+
# @private
|
739
|
+
class AndInvokeImplementation
|
740
|
+
def initialize(procs_to_invoke)
|
741
|
+
@procs_to_invoke = procs_to_invoke
|
742
|
+
end
|
743
|
+
|
744
|
+
def call(*args, &block)
|
745
|
+
proc = if @procs_to_invoke.size > 1
|
746
|
+
@procs_to_invoke.shift
|
747
|
+
else
|
748
|
+
@procs_to_invoke.first
|
749
|
+
end
|
750
|
+
|
751
|
+
proc.call(*args, &block)
|
752
|
+
end
|
753
|
+
end
|
754
|
+
|
686
755
|
# Represents a configured implementation. Takes into account
|
687
756
|
# any number of sub-implementations.
|
688
757
|
# @private
|
@@ -694,6 +763,7 @@ module RSpec
|
|
694
763
|
action.call(*args, &block)
|
695
764
|
end.last
|
696
765
|
end
|
766
|
+
ruby2_keywords :call if respond_to?(:ruby2_keywords, true)
|
697
767
|
|
698
768
|
def present?
|
699
769
|
actions.any?
|
@@ -739,6 +809,7 @@ module RSpec
|
|
739
809
|
def call(*args, &block)
|
740
810
|
@block.call(@method, *args, &block)
|
741
811
|
end
|
812
|
+
ruby2_keywords :call if respond_to?(:ruby2_keywords, true)
|
742
813
|
|
743
814
|
private
|
744
815
|
|
@@ -63,6 +63,8 @@ module RSpec
|
|
63
63
|
define_method(method_name) do |*args, &block|
|
64
64
|
method_double.proxy_method_invoked(self, *args, &block)
|
65
65
|
end
|
66
|
+
# This can't be `if respond_to?(:ruby2_keywords, true)`,
|
67
|
+
# see https://github.com/rspec/rspec-mocks/pull/1385#issuecomment-755340298
|
66
68
|
ruby2_keywords(method_name) if Module.private_method_defined?(:ruby2_keywords)
|
67
69
|
__send__(visibility, method_name)
|
68
70
|
end
|
@@ -77,6 +79,7 @@ module RSpec
|
|
77
79
|
def proxy_method_invoked(_obj, *args, &block)
|
78
80
|
@proxy.message_received method_name, *args, &block
|
79
81
|
end
|
82
|
+
ruby2_keywords :proxy_method_invoked if respond_to?(:ruby2_keywords, true)
|
80
83
|
|
81
84
|
# @private
|
82
85
|
def restore_original_method
|
data/lib/rspec/mocks/proxy.rb
CHANGED
@@ -230,6 +230,7 @@ module RSpec
|
|
230
230
|
@object.__send__(:method_missing, message, *args, &block)
|
231
231
|
end
|
232
232
|
end
|
233
|
+
ruby2_keywords :message_received if respond_to?(:ruby2_keywords, true)
|
233
234
|
|
234
235
|
# @private
|
235
236
|
def raise_unexpected_message_error(method_name, args)
|
@@ -279,12 +280,14 @@ module RSpec
|
|
279
280
|
expectation.matches?(method_name, *args)
|
280
281
|
end
|
281
282
|
end
|
283
|
+
ruby2_keywords :find_matching_expectation if respond_to?(:ruby2_keywords, true)
|
282
284
|
|
283
285
|
def find_almost_matching_expectation(method_name, *args)
|
284
286
|
find_best_matching_expectation_for(method_name) do |expectation|
|
285
287
|
expectation.matches_name_but_not_args(method_name, *args)
|
286
288
|
end
|
287
289
|
end
|
290
|
+
ruby2_keywords :find_almost_matching_expectation if respond_to?(:ruby2_keywords, true)
|
288
291
|
|
289
292
|
def find_best_matching_expectation_for(method_name)
|
290
293
|
first_match = nil
|
@@ -301,10 +304,12 @@ module RSpec
|
|
301
304
|
def find_matching_method_stub(method_name, *args)
|
302
305
|
method_double_for(method_name).stubs.find { |stub| stub.matches?(method_name, *args) }
|
303
306
|
end
|
307
|
+
ruby2_keywords :find_matching_method_stub if respond_to?(:ruby2_keywords, true)
|
304
308
|
|
305
309
|
def find_almost_matching_stub(method_name, *args)
|
306
310
|
method_double_for(method_name).stubs.find { |stub| stub.matches_name_but_not_args(method_name, *args) }
|
307
311
|
end
|
312
|
+
ruby2_keywords :find_almost_matching_stub if respond_to?(:ruby2_keywords, true)
|
308
313
|
end
|
309
314
|
|
310
315
|
# @private
|
@@ -360,6 +365,7 @@ module RSpec
|
|
360
365
|
end
|
361
366
|
super
|
362
367
|
end
|
368
|
+
ruby2_keywords :message_received if respond_to?(:ruby2_keywords, true)
|
363
369
|
|
364
370
|
private
|
365
371
|
|
@@ -34,23 +34,15 @@ module RSpec
|
|
34
34
|
super
|
35
35
|
end
|
36
36
|
|
37
|
-
# @private
|
38
|
-
module SilentIO
|
39
|
-
def self.method_missing(*); end
|
40
|
-
def self.respond_to?(*)
|
41
|
-
true
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
37
|
# Redefining `__send__` causes ruby to issue a warning.
|
46
|
-
old, $
|
38
|
+
old, $VERBOSE = $VERBOSE, nil
|
47
39
|
def __send__(name, *args, &block)
|
48
40
|
@__sending_message = name
|
49
41
|
super
|
50
42
|
ensure
|
51
43
|
@__sending_message = nil
|
52
44
|
end
|
53
|
-
$
|
45
|
+
$VERBOSE = old
|
54
46
|
|
55
47
|
def send(name, *args, &block)
|
56
48
|
__send__(name, *args, &block)
|
data/lib/rspec/mocks/version.rb
CHANGED
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-mocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.11.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Baker
|
@@ -45,7 +45,7 @@ cert_chain:
|
|
45
45
|
ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
|
46
46
|
F3MdtaDehhjC
|
47
47
|
-----END CERTIFICATE-----
|
48
|
-
date:
|
48
|
+
date: 2022-03-31 00:00:00.000000000 Z
|
49
49
|
dependencies:
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: rspec-support
|
@@ -53,14 +53,14 @@ dependencies:
|
|
53
53
|
requirements:
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: 3.
|
56
|
+
version: 3.11.0
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: 3.
|
63
|
+
version: 3.11.0
|
64
64
|
- !ruby/object:Gem::Dependency
|
65
65
|
name: diff-lcs
|
66
66
|
requirement: !ruby/object:Gem::Requirement
|
@@ -99,16 +99,16 @@ dependencies:
|
|
99
99
|
name: cucumber
|
100
100
|
requirement: !ruby/object:Gem::Requirement
|
101
101
|
requirements:
|
102
|
-
- - "
|
102
|
+
- - ">="
|
103
103
|
- !ruby/object:Gem::Version
|
104
|
-
version: 1.3
|
104
|
+
version: '1.3'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
107
|
version_requirements: !ruby/object:Gem::Requirement
|
108
108
|
requirements:
|
109
|
-
- - "
|
109
|
+
- - ">="
|
110
110
|
- !ruby/object:Gem::Version
|
111
|
-
version: 1.3
|
111
|
+
version: '1.3'
|
112
112
|
- !ruby/object:Gem::Dependency
|
113
113
|
name: aruba
|
114
114
|
requirement: !ruby/object:Gem::Requirement
|
@@ -194,7 +194,7 @@ licenses:
|
|
194
194
|
- MIT
|
195
195
|
metadata:
|
196
196
|
bug_tracker_uri: https://github.com/rspec/rspec-mocks/issues
|
197
|
-
changelog_uri: https://github.com/rspec/rspec-mocks/blob/v3.
|
197
|
+
changelog_uri: https://github.com/rspec/rspec-mocks/blob/v3.11.1/Changelog.md
|
198
198
|
documentation_uri: https://rspec.info/documentation/
|
199
199
|
mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
|
200
200
|
source_code_uri: https://github.com/rspec/rspec-mocks
|
@@ -214,8 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
214
|
- !ruby/object:Gem::Version
|
215
215
|
version: '0'
|
216
216
|
requirements: []
|
217
|
-
rubygems_version: 3.
|
217
|
+
rubygems_version: 3.3.3
|
218
218
|
signing_key:
|
219
219
|
specification_version: 4
|
220
|
-
summary: rspec-mocks-3.
|
220
|
+
summary: rspec-mocks-3.11.1
|
221
221
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|