rspec-mocks 3.8.0 → 3.10.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 +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Changelog.md +43 -0
- data/README.md +9 -6
- data/lib/rspec/mocks.rb +4 -1
- data/lib/rspec/mocks/any_instance/chain.rb +1 -0
- data/lib/rspec/mocks/any_instance/recorder.rb +5 -0
- data/lib/rspec/mocks/argument_matchers.rb +2 -0
- data/lib/rspec/mocks/matchers/have_received.rb +1 -1
- data/lib/rspec/mocks/message_expectation.rb +14 -4
- data/lib/rspec/mocks/method_double.rb +1 -1
- data/lib/rspec/mocks/proxy.rb +33 -15
- data/lib/rspec/mocks/version.rb +1 -1
- metadata +19 -15
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a31e7a6d767908477670b8a92d2d8ec2d6e170441caed3fdca032ab679a48823
|
4
|
+
data.tar.gz: 4de03ad5013551b8dfd17c68808df8353610907d4df35e9d0d795a0c56e3cfd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5035b0ce8fc5a4ddf37c7495fe72dbb75543efc706eef5c4b022c3eafb918bc79761b8060ebed43a9d89a5d18359334b63cf24b538d8e853e73fbb3609734168
|
7
|
+
data.tar.gz: fb4974a5e0c9c9bb00818d5e083aa9061448c372e0ee6a76d30df37f59abe08def5d240c45967b07861fce2bf6d8e89d6a0b6b50fe0c46beec5b9b7c9faa67b2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,3 +1,46 @@
|
|
1
|
+
### 3.10.0 / 2020-10-30
|
2
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.9.1...v3.10.0)
|
3
|
+
|
4
|
+
Enhancements:
|
5
|
+
* Add the ability to set a custom error generator in `MessageExpectation`.
|
6
|
+
This will allow rspec-expectations to inject a custom failure message.
|
7
|
+
(Benoit Tigeot and Nicolas Zermati, #1312)
|
8
|
+
* Return the result of the block passed to `RSpec::Mocks.with_temporary_scope`
|
9
|
+
when block run. (@expeehaa, #1329)
|
10
|
+
|
11
|
+
### 3.9.1 / 2019-12-31
|
12
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.9.0...v3.9.1)
|
13
|
+
|
14
|
+
Bug Fixes:
|
15
|
+
|
16
|
+
* Trigger `RSpec::Mocks.configuration.verifying_double_callbacks` when using
|
17
|
+
`allow_any_instance_of` or `expect_any_instance_of` (Daniel Orner, #1309)
|
18
|
+
|
19
|
+
### 3.9.0 / 2019-10-07
|
20
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.8.2...v3.9.0)
|
21
|
+
|
22
|
+
Enhancements:
|
23
|
+
|
24
|
+
* Improve thread safety of message expectations by using Mutex to prevent
|
25
|
+
deadlocking errors. (Ry Biesemeyer, #1236)
|
26
|
+
* Add the ability to use `time` as an alias for `times`. For example:
|
27
|
+
`expect(Class).to receive(:method).exactly(1).time`.
|
28
|
+
(Pistos, Benoit Tigeot, #1271)
|
29
|
+
|
30
|
+
### 3.8.2 / 2019-10-02
|
31
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.8.1...v3.8.2)
|
32
|
+
|
33
|
+
* Allow `array_including` argument matchers to be nested.
|
34
|
+
(Emmanuel Delmas, #1291)
|
35
|
+
|
36
|
+
### 3.8.1 / 2019-06-13
|
37
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.8.0...v3.8.1)
|
38
|
+
|
39
|
+
Bug Fixes:
|
40
|
+
|
41
|
+
* Ensure stubbing methods does not change their visibility.
|
42
|
+
(Kevin Boschert, #1277)
|
43
|
+
|
1
44
|
### 3.8.0 / 2018-08-04
|
2
45
|
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.7.0...v3.8.0)
|
3
46
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# RSpec Mocks [](http://travis-ci.org/rspec/rspec-mocks) [](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.
|
@@ -8,12 +8,12 @@ alike.
|
|
8
8
|
gem install rspec # for rspec-core, rspec-expectations, rspec-mocks
|
9
9
|
gem install rspec-mocks # for rspec-mocks only
|
10
10
|
|
11
|
-
Want to run against the `
|
11
|
+
Want to run against the `main` branch? You'll need to include the dependent
|
12
12
|
RSpec repos as well. Add the following to your `Gemfile`:
|
13
13
|
|
14
14
|
```ruby
|
15
15
|
%w[rspec-core rspec-expectations rspec-mocks rspec-support].each do |lib|
|
16
|
-
gem lib, :git => "https://github.com/rspec/#{lib}.git", :branch => '
|
16
|
+
gem lib, :git => "https://github.com/rspec/#{lib}.git", :branch => 'main'
|
17
17
|
end
|
18
18
|
```
|
19
19
|
## Contributing
|
@@ -53,7 +53,7 @@ book = instance_double("Book", :pages => 250)
|
|
53
53
|
Verifying doubles have some clever tricks to enable you to both test in
|
54
54
|
isolation without your dependencies loaded while still being able to validate
|
55
55
|
them against real objects. More detail is available in [their
|
56
|
-
documentation](https://github.com/rspec/rspec-mocks/blob/
|
56
|
+
documentation](https://github.com/rspec/rspec-mocks/blob/main/features/verifying_doubles).
|
57
57
|
|
58
58
|
Verifying doubles can also accept custom identifiers, just like double(), e.g.:
|
59
59
|
|
@@ -285,12 +285,15 @@ expect(double).to receive(:msg).with(hash_excluding(:a => 5)) # first arg is a h
|
|
285
285
|
```ruby
|
286
286
|
expect(double).to receive(:msg).once
|
287
287
|
expect(double).to receive(:msg).twice
|
288
|
+
expect(double).to receive(:msg).exactly(n).time
|
288
289
|
expect(double).to receive(:msg).exactly(n).times
|
289
290
|
expect(double).to receive(:msg).at_least(:once)
|
290
291
|
expect(double).to receive(:msg).at_least(:twice)
|
292
|
+
expect(double).to receive(:msg).at_least(n).time
|
291
293
|
expect(double).to receive(:msg).at_least(n).times
|
292
294
|
expect(double).to receive(:msg).at_most(:once)
|
293
295
|
expect(double).to receive(:msg).at_most(:twice)
|
296
|
+
expect(double).to receive(:msg).at_most(n).time
|
294
297
|
expect(double).to receive(:msg).at_most(n).times
|
295
298
|
```
|
296
299
|
|
@@ -327,7 +330,7 @@ expect(double).to receive(:msg).and_return(value)
|
|
327
330
|
expect(double).to receive(:msg).exactly(3).times.and_return(value1, value2, value3)
|
328
331
|
# returns value1 the first time, value2 the second, etc
|
329
332
|
expect(double).to receive(:msg).and_raise(error)
|
330
|
-
# error can be an instantiated object or a class
|
333
|
+
# `error` can be an instantiated object (e.g. `StandardError.new(some_arg)`) or a class (e.g. `StandardError`)
|
331
334
|
# if it is a class, it must be instantiable with no args
|
332
335
|
expect(double).to receive(:msg).and_throw(:msg)
|
333
336
|
expect(double).to receive(:msg).and_yield(values, to, yield)
|
@@ -400,7 +403,7 @@ your code.
|
|
400
403
|
## Stubbing and Hiding Constants
|
401
404
|
|
402
405
|
See the [mutating constants
|
403
|
-
README](https://github.com/rspec/rspec-mocks/blob/
|
406
|
+
README](https://github.com/rspec/rspec-mocks/blob/main/features/mutating_constants/README.md)
|
404
407
|
for info on this feature.
|
405
408
|
|
406
409
|
## Use `before(:example)`, not `before(:context)`
|
data/lib/rspec/mocks.rb
CHANGED
@@ -87,12 +87,15 @@ module RSpec
|
|
87
87
|
|
88
88
|
# Call the passed block and verify mocks after it has executed. This allows
|
89
89
|
# mock usage in arbitrary places, such as a `before(:all)` hook.
|
90
|
+
#
|
91
|
+
# @return [Object] the return value from the block
|
90
92
|
def self.with_temporary_scope
|
91
93
|
setup
|
92
94
|
|
93
95
|
begin
|
94
|
-
yield
|
96
|
+
result = yield
|
95
97
|
verify
|
98
|
+
result
|
96
99
|
ensure
|
97
100
|
teardown
|
98
101
|
end
|
@@ -21,6 +21,11 @@ module RSpec
|
|
21
21
|
@backed_up_method_owner = {}
|
22
22
|
@klass = klass
|
23
23
|
@expectation_set = false
|
24
|
+
|
25
|
+
return unless RSpec::Mocks.configuration.verify_partial_doubles?
|
26
|
+
RSpec::Mocks.configuration.verifying_double_callbacks.each do |block|
|
27
|
+
block.call(ObjectReference.for(klass))
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
31
|
# Initializes the recording a stub to be played back against any
|
@@ -5,7 +5,7 @@ module RSpec
|
|
5
5
|
class HaveReceived
|
6
6
|
include Matcher
|
7
7
|
|
8
|
-
COUNT_CONSTRAINTS = %w[exactly at_least at_most times once twice thrice]
|
8
|
+
COUNT_CONSTRAINTS = %w[exactly at_least at_most times time once twice thrice]
|
9
9
|
ARGS_CONSTRAINTS = %w[with]
|
10
10
|
CONSTRAINTS = COUNT_CONSTRAINTS + ARGS_CONSTRAINTS + %w[ordered]
|
11
11
|
|
@@ -1,3 +1,5 @@
|
|
1
|
+
RSpec::Support.require_rspec_support 'mutex'
|
2
|
+
|
1
3
|
module RSpec
|
2
4
|
module Mocks
|
3
5
|
# A message expectation that only allows concrete return values to be set
|
@@ -236,6 +238,7 @@ module RSpec
|
|
236
238
|
self.inner_implementation_action = block
|
237
239
|
self
|
238
240
|
end
|
241
|
+
alias time times
|
239
242
|
|
240
243
|
# Expect a message not to be received at all.
|
241
244
|
#
|
@@ -357,12 +360,13 @@ module RSpec
|
|
357
360
|
# some collaborators it delegates to for this stuff but for now this was
|
358
361
|
# the simplest way to split the public from private stuff to make it
|
359
362
|
# easier to publish the docs for the APIs we want published.
|
363
|
+
# rubocop:disable Metrics/ModuleLength
|
360
364
|
module ImplementationDetails
|
361
365
|
attr_accessor :error_generator, :implementation
|
362
366
|
attr_reader :message
|
363
367
|
attr_reader :orig_object
|
364
368
|
attr_writer :expected_received_count, :expected_from, :argument_list_matcher
|
365
|
-
protected :expected_received_count=, :expected_from=, :error_generator
|
369
|
+
protected :expected_received_count=, :expected_from=, :error_generator=, :implementation=
|
366
370
|
|
367
371
|
# @private
|
368
372
|
attr_reader :type
|
@@ -372,12 +376,13 @@ module RSpec
|
|
372
376
|
type=:expectation, opts={}, &implementation_block)
|
373
377
|
@type = type
|
374
378
|
@error_generator = error_generator
|
375
|
-
@error_generator.opts = opts
|
379
|
+
@error_generator.opts = error_generator.opts.merge(opts)
|
376
380
|
@expected_from = expected_from
|
377
381
|
@method_double = method_double
|
378
382
|
@orig_object = @method_double.object
|
379
383
|
@message = @method_double.method_name
|
380
384
|
@actual_received_count = 0
|
385
|
+
@actual_received_count_write_mutex = Support::Mutex.new
|
381
386
|
@expected_received_count = type == :expectation ? 1 : :any
|
382
387
|
@argument_list_matcher = ArgumentListMatcher::MATCH_ALL
|
383
388
|
@order_group = expectation_ordering
|
@@ -536,7 +541,9 @@ module RSpec
|
|
536
541
|
end
|
537
542
|
|
538
543
|
def increase_actual_received_count!
|
539
|
-
@
|
544
|
+
@actual_received_count_write_mutex.synchronize do
|
545
|
+
@actual_received_count += 1
|
546
|
+
end
|
540
547
|
end
|
541
548
|
|
542
549
|
private
|
@@ -567,7 +574,9 @@ module RSpec
|
|
567
574
|
parent_stub.invoke(nil, *args, &block)
|
568
575
|
end
|
569
576
|
ensure
|
570
|
-
@
|
577
|
+
@actual_received_count_write_mutex.synchronize do
|
578
|
+
@actual_received_count += increment
|
579
|
+
end
|
571
580
|
end
|
572
581
|
|
573
582
|
def has_been_invoked?
|
@@ -626,6 +635,7 @@ module RSpec
|
|
626
635
|
nil
|
627
636
|
end
|
628
637
|
end
|
638
|
+
# rubocop:enable Metrics/ModuleLength
|
629
639
|
|
630
640
|
include ImplementationDetails
|
631
641
|
end
|
@@ -59,7 +59,7 @@ module RSpec
|
|
59
59
|
return if @method_is_proxied
|
60
60
|
|
61
61
|
save_original_implementation_callable!
|
62
|
-
definition_target.class_exec(self, method_name, visibility) do |method_double, method_name, visibility|
|
62
|
+
definition_target.class_exec(self, method_name, @original_visibility || visibility) do |method_double, method_name, visibility|
|
63
63
|
define_method(method_name) do |*args, &block|
|
64
64
|
method_double.proxy_method_invoked(self, *args, &block)
|
65
65
|
end
|
data/lib/rspec/mocks/proxy.rb
CHANGED
@@ -9,6 +9,11 @@ module RSpec
|
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
+
unless defined?(Mutex)
|
13
|
+
Support.require_rspec_support 'mutex'
|
14
|
+
Mutex = Support::Mutex
|
15
|
+
end
|
16
|
+
|
12
17
|
# @private
|
13
18
|
def ensure_implemented(*_args)
|
14
19
|
# noop for basic proxies, see VerifyingProxy for behaviour.
|
@@ -20,6 +25,7 @@ module RSpec
|
|
20
25
|
@order_group = order_group
|
21
26
|
@error_generator = ErrorGenerator.new(object)
|
22
27
|
@messages_received = []
|
28
|
+
@messages_received_mutex = Mutex.new
|
23
29
|
@options = options
|
24
30
|
@null_object = false
|
25
31
|
@method_doubles = Hash.new { |h, k| h[k] = MethodDouble.new(@object, k, self) }
|
@@ -90,27 +96,31 @@ module RSpec
|
|
90
96
|
@error_generator.raise_expectation_on_unstubbed_method(expected_method_name)
|
91
97
|
end
|
92
98
|
|
93
|
-
@
|
94
|
-
|
99
|
+
@messages_received_mutex.synchronize do
|
100
|
+
@messages_received.each do |(actual_method_name, args, received_block)|
|
101
|
+
next unless expectation.matches?(actual_method_name, *args)
|
95
102
|
|
96
|
-
|
97
|
-
|
103
|
+
expectation.safe_invoke(nil)
|
104
|
+
block.call(*args, &received_block) if block
|
105
|
+
end
|
98
106
|
end
|
99
107
|
end
|
100
108
|
|
101
109
|
# @private
|
102
110
|
def check_for_unexpected_arguments(expectation)
|
103
|
-
|
111
|
+
@messages_received_mutex.synchronize do
|
112
|
+
return if @messages_received.empty?
|
104
113
|
|
105
|
-
|
114
|
+
return if @messages_received.any? { |method_name, args, _| expectation.matches?(method_name, *args) }
|
106
115
|
|
107
|
-
|
108
|
-
|
109
|
-
|
116
|
+
name_but_not_args, others = @messages_received.partition do |(method_name, args, _)|
|
117
|
+
expectation.matches_name_but_not_args(method_name, *args)
|
118
|
+
end
|
110
119
|
|
111
|
-
|
120
|
+
return if name_but_not_args.empty? && !others.empty?
|
112
121
|
|
113
|
-
|
122
|
+
expectation.raise_unexpected_message_args_error(name_but_not_args.map { |args| args[1] })
|
123
|
+
end
|
114
124
|
end
|
115
125
|
|
116
126
|
# @private
|
@@ -141,17 +151,23 @@ module RSpec
|
|
141
151
|
|
142
152
|
# @private
|
143
153
|
def reset
|
144
|
-
@
|
154
|
+
@messages_received_mutex.synchronize do
|
155
|
+
@messages_received.clear
|
156
|
+
end
|
145
157
|
end
|
146
158
|
|
147
159
|
# @private
|
148
160
|
def received_message?(method_name, *args, &block)
|
149
|
-
@
|
161
|
+
@messages_received_mutex.synchronize do
|
162
|
+
@messages_received.any? { |array| array == [method_name, args, block] }
|
163
|
+
end
|
150
164
|
end
|
151
165
|
|
152
166
|
# @private
|
153
167
|
def messages_arg_list
|
154
|
-
@
|
168
|
+
@messages_received_mutex.synchronize do
|
169
|
+
@messages_received.map { |_, args, _| args }
|
170
|
+
end
|
155
171
|
end
|
156
172
|
|
157
173
|
# @private
|
@@ -162,7 +178,9 @@ module RSpec
|
|
162
178
|
# @private
|
163
179
|
def record_message_received(message, *args, &block)
|
164
180
|
@order_group.invoked SpecificMessage.new(object, message, args)
|
165
|
-
@
|
181
|
+
@messages_received_mutex.synchronize do
|
182
|
+
@messages_received << [message, args, block]
|
183
|
+
end
|
166
184
|
end
|
167
185
|
|
168
186
|
# @private
|
data/lib/rspec/mocks/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-mocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.10.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Baker
|
8
8
|
- David Chelimsky
|
9
9
|
- Myron Marston
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain:
|
13
13
|
- |
|
@@ -45,7 +45,7 @@ cert_chain:
|
|
45
45
|
ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
|
46
46
|
F3MdtaDehhjC
|
47
47
|
-----END CERTIFICATE-----
|
48
|
-
date:
|
48
|
+
date: 2020-10-30 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.10.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.10.0
|
64
64
|
- !ruby/object:Gem::Dependency
|
65
65
|
name: diff-lcs
|
66
66
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,14 +85,14 @@ dependencies:
|
|
85
85
|
name: rake
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - "
|
88
|
+
- - ">"
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: 10.0.0
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- - "
|
95
|
+
- - ">"
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: 10.0.0
|
98
98
|
- !ruby/object:Gem::Dependency
|
@@ -115,14 +115,14 @@ dependencies:
|
|
115
115
|
requirements:
|
116
116
|
- - "~>"
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version: 0.
|
118
|
+
version: 0.14.10
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - "~>"
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version: 0.
|
125
|
+
version: 0.14.10
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: minitest
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -192,8 +192,13 @@ files:
|
|
192
192
|
homepage: https://github.com/rspec/rspec-mocks
|
193
193
|
licenses:
|
194
194
|
- MIT
|
195
|
-
metadata:
|
196
|
-
|
195
|
+
metadata:
|
196
|
+
bug_tracker_uri: https://github.com/rspec/rspec-mocks/issues
|
197
|
+
changelog_uri: https://github.com/rspec/rspec-mocks/blob/v3.10.0/Changelog.md
|
198
|
+
documentation_uri: https://rspec.info/documentation/
|
199
|
+
mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
|
200
|
+
source_code_uri: https://github.com/rspec/rspec-mocks
|
201
|
+
post_install_message:
|
197
202
|
rdoc_options:
|
198
203
|
- "--charset=UTF-8"
|
199
204
|
require_paths:
|
@@ -209,9 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
209
214
|
- !ruby/object:Gem::Version
|
210
215
|
version: '0'
|
211
216
|
requirements: []
|
212
|
-
|
213
|
-
|
214
|
-
signing_key:
|
217
|
+
rubygems_version: 3.1.3
|
218
|
+
signing_key:
|
215
219
|
specification_version: 4
|
216
|
-
summary: rspec-mocks-3.
|
220
|
+
summary: rspec-mocks-3.10.0
|
217
221
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|