rspec-mocks-diag 3.9.1.1 → 3.10.2.1
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 +4 -4
- data/Changelog.md +34 -0
- data/README.md +5 -5
- data/lib/rspec/mocks.rb +4 -1
- data/lib/rspec/mocks/any_instance/error_generator.rb +10 -2
- data/lib/rspec/mocks/any_instance/recorder.rb +7 -1
- data/lib/rspec/mocks/error_generator.rb +1 -1
- data/lib/rspec/mocks/message_expectation.rb +3 -2
- data/lib/rspec/mocks/method_double.rb +1 -0
- data/lib/rspec/mocks/mutate_const.rb +1 -1
- data/lib/rspec/mocks/proxy.rb +16 -0
- data/lib/rspec/mocks/test_double.rb +10 -0
- data/lib/rspec/mocks/version.rb +1 -1
- metadata +9 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9049535662ab617b1f1a4772d76a51f2a5a4c982b079f0f62313a122acc6b59e
|
|
4
|
+
data.tar.gz: bb11b60f438f96f2fb61e654359ea12453de223d57762bbf544ae1aca052c04f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 887b9e4327808672956beba27647db28a4e3c8ea8bc600d5db986ebf0f39e3fee3fc850ed5b3281d0ae25dfb7cf49d98ed66ee3afdb3367909900bc003bd6418
|
|
7
|
+
data.tar.gz: 96dac6f369dff621fbb4f67b4cdd9880c6b051758e36c85ef39c8d64dd6c680fd833772146f490edf68f5be3599aa55b8d34930f479b47898894b02d91f31046
|
data/Changelog.md
CHANGED
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
### Development
|
|
2
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.2...main)
|
|
3
|
+
|
|
4
|
+
### 3.10.2 / 2021-01-27
|
|
5
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.1...v3.10.2)
|
|
6
|
+
|
|
7
|
+
Bug Fixes:
|
|
8
|
+
|
|
9
|
+
* Support keyword arguments with `and_call_original` on Ruby 3.0.
|
|
10
|
+
(Bryan Powell, #1385)
|
|
11
|
+
* `RSpec::Mocks::Constant#previously_defined?` is now always a boolean.
|
|
12
|
+
(Phil Pirozhkov, #1397)
|
|
13
|
+
* Support keyword arguments on Ruby 3.0 when used with `expect_any_instance_of`
|
|
14
|
+
or `allow_any_instance_of` with `and_call_original`.
|
|
15
|
+
(Jess Hottenstein, #1407)
|
|
16
|
+
|
|
17
|
+
### 3.10.1 / 2020-12-27
|
|
18
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.0...v3.10.1)
|
|
19
|
+
|
|
20
|
+
Bug Fixes:
|
|
21
|
+
|
|
22
|
+
* Issue `ArgumentError` rather than `TypeError` when unsupported methods on
|
|
23
|
+
unsupported objects are attempted to be stubbed. (@zhisme, #1357)
|
|
24
|
+
|
|
25
|
+
### 3.10.0 / 2020-10-30
|
|
26
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.9.1...v3.10.0)
|
|
27
|
+
|
|
28
|
+
Enhancements:
|
|
29
|
+
* Add the ability to set a custom error generator in `MessageExpectation`.
|
|
30
|
+
This will allow rspec-expectations to inject a custom failure message.
|
|
31
|
+
(Benoit Tigeot and Nicolas Zermati, #1312)
|
|
32
|
+
* Return the result of the block passed to `RSpec::Mocks.with_temporary_scope`
|
|
33
|
+
when block run. (@expeehaa, #1329)
|
|
34
|
+
|
|
1
35
|
### 3.9.1 / 2019-12-31
|
|
2
36
|
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.9.0...v3.9.1)
|
|
3
37
|
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# RSpec Mocks [](https://github.com/rspec/rspec-mocks/actions) [](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
|
|
|
@@ -403,7 +403,7 @@ your code.
|
|
|
403
403
|
## Stubbing and Hiding Constants
|
|
404
404
|
|
|
405
405
|
See the [mutating constants
|
|
406
|
-
README](https://github.com/rspec/rspec-mocks/blob/
|
|
406
|
+
README](https://github.com/rspec/rspec-mocks/blob/main/features/mutating_constants/README.md)
|
|
407
407
|
for info on this feature.
|
|
408
408
|
|
|
409
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
|
|
@@ -12,9 +12,17 @@ module RSpec
|
|
|
12
12
|
__raise "#{klass} does not implement ##{method_name}"
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
-
def raise_message_already_received_by_other_instance_error(method_name, object_inspect, invoked_instance)
|
|
15
|
+
def raise_message_already_received_by_other_instance_error(method_name, object_inspect, invoked_instance, invoked_backtrace)
|
|
16
|
+
begin
|
|
17
|
+
raise RuntimeError
|
|
18
|
+
rescue => e
|
|
19
|
+
backtrace = e.backtrace
|
|
20
|
+
end
|
|
16
21
|
__raise "The message '#{method_name}' was received by #{object_inspect} " \
|
|
17
|
-
"but has already been received by #{invoked_instance}"
|
|
22
|
+
"but has already been received by #{invoked_instance}.\nCurrent backtrace:\n" +
|
|
23
|
+
backtrace.map { |line| ' ' + line }.join("\n") +
|
|
24
|
+
"\nPrevious backtrace: \n" +
|
|
25
|
+
invoked_backtrace.map { |line| ' ' + line }.join("\n")
|
|
18
26
|
end
|
|
19
27
|
|
|
20
28
|
def raise_not_supported_with_prepend_error(method_name, problem_mod)
|
|
@@ -261,16 +261,22 @@ module RSpec
|
|
|
261
261
|
recorder.playback!(self, method_name)
|
|
262
262
|
__send__(method_name, *args, &blk)
|
|
263
263
|
end
|
|
264
|
+
@klass.__send__(:ruby2_keywords, method_name) if @klass.respond_to?(:ruby2_keywords, true)
|
|
264
265
|
end
|
|
265
266
|
|
|
266
267
|
def mark_invoked!(method_name)
|
|
267
268
|
backup_method!(method_name)
|
|
268
269
|
recorder = self
|
|
270
|
+
begin
|
|
271
|
+
raise RuntimeError
|
|
272
|
+
rescue => e
|
|
273
|
+
invoked_backtrace = e.backtrace
|
|
274
|
+
end
|
|
269
275
|
@klass.__send__(:define_method, method_name) do |*_args, &_blk|
|
|
270
276
|
invoked_instance = recorder.instance_that_received(method_name)
|
|
271
277
|
inspect = "#<#{self.class}:#{object_id} #{instance_variables.map { |name| "#{name}=#{instance_variable_get name}" }.join(', ')}>"
|
|
272
278
|
AnyInstance.error_generator.raise_message_already_received_by_other_instance_error(
|
|
273
|
-
method_name, inspect, invoked_instance
|
|
279
|
+
method_name, inspect, invoked_instance, invoked_backtrace
|
|
274
280
|
)
|
|
275
281
|
end
|
|
276
282
|
end
|
|
@@ -47,7 +47,7 @@ module RSpec
|
|
|
47
47
|
|
|
48
48
|
# @private
|
|
49
49
|
def raise_unexpected_message_error(message, args)
|
|
50
|
-
__raise "#{intro} received unexpected message :#{message} with #{format_args(args)}"
|
|
50
|
+
__raise "#{intro} received unexpected message :#{message} with #{format_args(args)}\nDouble instantiated from:\n#{@target._rspec_backtrace.map { |line| ' ' + line }.join("\n")}"
|
|
51
51
|
end
|
|
52
52
|
|
|
53
53
|
# @private
|
|
@@ -366,7 +366,7 @@ module RSpec
|
|
|
366
366
|
attr_reader :message
|
|
367
367
|
attr_reader :orig_object
|
|
368
368
|
attr_writer :expected_received_count, :expected_from, :argument_list_matcher
|
|
369
|
-
protected :expected_received_count=, :expected_from=, :error_generator
|
|
369
|
+
protected :expected_received_count=, :expected_from=, :error_generator=, :implementation=
|
|
370
370
|
|
|
371
371
|
# @private
|
|
372
372
|
attr_reader :type
|
|
@@ -376,7 +376,7 @@ module RSpec
|
|
|
376
376
|
type=:expectation, opts={}, &implementation_block)
|
|
377
377
|
@type = type
|
|
378
378
|
@error_generator = error_generator
|
|
379
|
-
@error_generator.opts = opts
|
|
379
|
+
@error_generator.opts = error_generator.opts.merge(opts)
|
|
380
380
|
@expected_from = expected_from
|
|
381
381
|
@method_double = method_double
|
|
382
382
|
@orig_object = @method_double.object
|
|
@@ -390,6 +390,7 @@ module RSpec
|
|
|
390
390
|
@expectation_type = type
|
|
391
391
|
@ordered = false
|
|
392
392
|
@at_least = @at_most = @exactly = nil
|
|
393
|
+
@args_history = nil
|
|
393
394
|
|
|
394
395
|
# Initialized to nil so that we don't allocate an array for every
|
|
395
396
|
# mock or stub. See also comment in `and_yield`.
|
data/lib/rspec/mocks/proxy.rb
CHANGED
|
@@ -21,6 +21,8 @@ module RSpec
|
|
|
21
21
|
|
|
22
22
|
# @private
|
|
23
23
|
def initialize(object, order_group, options={})
|
|
24
|
+
ensure_can_be_proxied!(object)
|
|
25
|
+
|
|
24
26
|
@object = object
|
|
25
27
|
@order_group = order_group
|
|
26
28
|
@error_generator = ErrorGenerator.new(object)
|
|
@@ -31,6 +33,20 @@ module RSpec
|
|
|
31
33
|
@method_doubles = Hash.new { |h, k| h[k] = MethodDouble.new(@object, k, self) }
|
|
32
34
|
end
|
|
33
35
|
|
|
36
|
+
# @private
|
|
37
|
+
def ensure_can_be_proxied!(object)
|
|
38
|
+
return unless object.is_a?(Symbol) || object.frozen?
|
|
39
|
+
return if object.nil?
|
|
40
|
+
|
|
41
|
+
msg = "Cannot proxy frozen objects"
|
|
42
|
+
if Symbol === object
|
|
43
|
+
msg << ". Symbols such as #{object} cannot be mocked or stubbed."
|
|
44
|
+
else
|
|
45
|
+
msg << ", rspec-mocks relies on proxies for method stubbing and expectations."
|
|
46
|
+
end
|
|
47
|
+
raise ArgumentError, msg
|
|
48
|
+
end
|
|
49
|
+
|
|
34
50
|
# @private
|
|
35
51
|
attr_reader :object
|
|
36
52
|
|
|
@@ -15,8 +15,18 @@ module RSpec
|
|
|
15
15
|
@name = name
|
|
16
16
|
end
|
|
17
17
|
assign_stubs(stubs)
|
|
18
|
+
|
|
19
|
+
begin
|
|
20
|
+
raise RuntimeError
|
|
21
|
+
rescue => e
|
|
22
|
+
@_rspec_backtrace = e.backtrace.dup.tap do |bt|
|
|
23
|
+
bt.shift
|
|
24
|
+
end
|
|
25
|
+
end
|
|
18
26
|
end
|
|
19
27
|
|
|
28
|
+
attr_reader :_rspec_backtrace
|
|
29
|
+
|
|
20
30
|
# Tells the object to respond to all messages. If specific stub values
|
|
21
31
|
# are declared, they'll work as expected. If not, the receiver is
|
|
22
32
|
# returned.
|
data/lib/rspec/mocks/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rspec-mocks-diag
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.
|
|
4
|
+
version: 3.10.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Steven Baker
|
|
@@ -10,7 +10,7 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date:
|
|
13
|
+
date: 2021-07-10 00:00:00.000000000 Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: rspec-support
|
|
@@ -18,14 +18,14 @@ dependencies:
|
|
|
18
18
|
requirements:
|
|
19
19
|
- - "~>"
|
|
20
20
|
- !ruby/object:Gem::Version
|
|
21
|
-
version: 3.
|
|
21
|
+
version: 3.10.0
|
|
22
22
|
type: :runtime
|
|
23
23
|
prerelease: false
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
|
25
25
|
requirements:
|
|
26
26
|
- - "~>"
|
|
27
27
|
- !ruby/object:Gem::Version
|
|
28
|
-
version: 3.
|
|
28
|
+
version: 3.10.0
|
|
29
29
|
- !ruby/object:Gem::Dependency
|
|
30
30
|
name: diff-lcs
|
|
31
31
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -50,14 +50,14 @@ dependencies:
|
|
|
50
50
|
name: rake
|
|
51
51
|
requirement: !ruby/object:Gem::Requirement
|
|
52
52
|
requirements:
|
|
53
|
-
- - "
|
|
53
|
+
- - ">"
|
|
54
54
|
- !ruby/object:Gem::Version
|
|
55
55
|
version: 10.0.0
|
|
56
56
|
type: :development
|
|
57
57
|
prerelease: false
|
|
58
58
|
version_requirements: !ruby/object:Gem::Requirement
|
|
59
59
|
requirements:
|
|
60
|
-
- - "
|
|
60
|
+
- - ">"
|
|
61
61
|
- !ruby/object:Gem::Version
|
|
62
62
|
version: 10.0.0
|
|
63
63
|
- !ruby/object:Gem::Dependency
|
|
@@ -159,7 +159,7 @@ licenses:
|
|
|
159
159
|
- MIT
|
|
160
160
|
metadata:
|
|
161
161
|
bug_tracker_uri: https://github.com/p-mongo/rspec-mocks/issues
|
|
162
|
-
changelog_uri: https://github.com/p-mongo/rspec-mocks/blob/v3.
|
|
162
|
+
changelog_uri: https://github.com/p-mongo/rspec-mocks/blob/v3.10.2.1/Changelog.md
|
|
163
163
|
documentation_uri: https://rspec.info/documentation/
|
|
164
164
|
mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
|
|
165
165
|
source_code_uri: https://github.com/p-mongo/rspec-mocks
|
|
@@ -179,8 +179,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
179
179
|
- !ruby/object:Gem::Version
|
|
180
180
|
version: '0'
|
|
181
181
|
requirements: []
|
|
182
|
-
rubygems_version: 3.1.
|
|
182
|
+
rubygems_version: 3.1.6
|
|
183
183
|
signing_key:
|
|
184
184
|
specification_version: 4
|
|
185
|
-
summary: rspec-mocks-3.
|
|
185
|
+
summary: rspec-mocks-3.10.2.1
|
|
186
186
|
test_files: []
|