rspec-mocks 3.10.0 → 3.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a31e7a6d767908477670b8a92d2d8ec2d6e170441caed3fdca032ab679a48823
4
- data.tar.gz: 4de03ad5013551b8dfd17c68808df8353610907d4df35e9d0d795a0c56e3cfd7
3
+ metadata.gz: 12ce7d4b5f6accc3fb2b6af82646843de8ffd500352d4ca5367985e28fec0805
4
+ data.tar.gz: 9643bc17b54bd21725aa39946eacda8207e327bdb592a9e0be821ee42c59bddb
5
5
  SHA512:
6
- metadata.gz: 5035b0ce8fc5a4ddf37c7495fe72dbb75543efc706eef5c4b022c3eafb918bc79761b8060ebed43a9d89a5d18359334b63cf24b538d8e853e73fbb3609734168
7
- data.tar.gz: fb4974a5e0c9c9bb00818d5e083aa9061448c372e0ee6a76d30df37f59abe08def5d240c45967b07861fce2bf6d8e89d6a0b6b50fe0c46beec5b9b7c9faa67b2
6
+ metadata.gz: 1a1fc3ad0ca28d5371d74985f236f9c222fc310743062a5e8746c5f995803bfd5b63de26b673b94460c6ec47eedfbb150425fe3bb59f0e5bdaf4d639ffe0bc0d
7
+ data.tar.gz: 352761f69232f8b5afb6ac918bb596c5961017f622f2aec36052f5f69c426449a51ef2af26394951cad5c7706a165446a9d80d6e01adafeb87e4f6e0804a46af
checksums.yaml.gz.sig CHANGED
Binary file
data/Changelog.md CHANGED
@@ -1,3 +1,44 @@
1
+ ### Development
2
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.11.0...3-11-maintenance)
3
+
4
+ ### 3.11.0 / 2022-02-09
5
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.3...v3.11.0)
6
+
7
+ Enhancements:
8
+
9
+ * Add `and_invoke` implementation for configuring responses to `receive`
10
+ (and `receive_messages`) with multiple callable objects. (Kyle Smith, #1411)
11
+
12
+ ### 3.10.3 / 2022-01-28
13
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.2...v3.10.3)
14
+
15
+ Bug Fixes:
16
+
17
+ * Suppress warning by setting `$VERBOSE` to nil. (Nobuyoshi Nakada, #1414)
18
+ * Support keyword argument semantics when constraining argument expectations using
19
+ `with` on Ruby 3.0+ (Yusuke Endoh, #1394)
20
+
21
+ ### 3.10.2 / 2021-01-27
22
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.1...v3.10.2)
23
+
24
+ Bug Fixes:
25
+
26
+ * Support keyword arguments with `and_call_original` on Ruby 3.0.
27
+ (Bryan Powell, #1385)
28
+ * `RSpec::Mocks::Constant#previously_defined?` is now always a boolean.
29
+ (Phil Pirozhkov, #1397)
30
+ * Support keyword arguments on Ruby 3.0 when used with `expect_any_instance_of`
31
+ or `allow_any_instance_of` with `and_call_original`.
32
+ (Jess Hottenstein, #1407)
33
+
34
+ ### 3.10.1 / 2020-12-27
35
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.0...v3.10.1)
36
+
37
+ Bug Fixes:
38
+
39
+ * Issue `ArgumentError` rather than `TypeError` when unsupported methods on
40
+ unsupported objects are attempted to be stubbed. (@zhisme, #1357)
41
+
1
42
  ### 3.10.0 / 2020-10-30
2
43
  [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.9.1...v3.10.0)
3
44
 
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # RSpec Mocks [![Build Status](https://secure.travis-ci.org/rspec/rspec-mocks.svg?branch=main)](http://travis-ci.org/rspec/rspec-mocks) [![Code Climate](https://codeclimate.com/github/rspec/rspec-mocks.svg)](https://codeclimate.com/github/rspec/rspec-mocks)
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.
@@ -261,6 +261,7 @@ 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)
@@ -46,16 +46,30 @@ module RSpec
46
46
  @expected_args = expected_args
47
47
  ensure_expected_args_valid!
48
48
  end
49
+ ruby2_keywords :initialize if Module.private_method_defined?(:ruby2_keywords)
49
50
 
50
51
  # @api public
51
- # @param [Array] args
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?(*args)
58
- Support::FuzzyMatcher.values_match?(resolve_expected_args_based_on(args), args)
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
60
74
 
61
75
  # @private
@@ -62,6 +62,7 @@ module RSpec
62
62
  @recorded_customizations << ExpectationCustomization.new(method, args, block)
63
63
  self
64
64
  end
65
+ ruby2_keywords(method) if Module.private_method_defined?(:ruby2_keywords)
65
66
  end
66
67
 
67
68
  private
@@ -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 received for every subsequent call.
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
  #
@@ -322,6 +364,7 @@ module RSpec
322
364
  @argument_list_matcher = ArgumentListMatcher.new(*args)
323
365
  self
324
366
  end
367
+ ruby2_keywords(:with) if Module.private_method_defined?(:ruby2_keywords)
325
368
 
326
369
  # Expect messages to be received in a specific order.
327
370
  #
@@ -683,6 +726,24 @@ module RSpec
683
726
  end
684
727
  end
685
728
 
729
+ # Handles the implementation of an `and_invoke` implementation.
730
+ # @private
731
+ class AndInvokeImplementation
732
+ def initialize(procs_to_invoke)
733
+ @procs_to_invoke = procs_to_invoke
734
+ end
735
+
736
+ def call(*args, &block)
737
+ proc = if @procs_to_invoke.size > 1
738
+ @procs_to_invoke.shift
739
+ else
740
+ @procs_to_invoke.first
741
+ end
742
+
743
+ proc.call(*args, &block)
744
+ end
745
+ end
746
+
686
747
  # Represents a configured implementation. Takes into account
687
748
  # any number of sub-implementations.
688
749
  # @private
@@ -63,6 +63,7 @@ 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
+ ruby2_keywords(method_name) if Module.private_method_defined?(:ruby2_keywords)
66
67
  __send__(visibility, method_name)
67
68
  end
68
69
 
@@ -66,7 +66,7 @@ module RSpec
66
66
 
67
67
  # @private
68
68
  def self.unmutated(name)
69
- previously_defined = recursive_const_defined?(name)
69
+ previously_defined = !!recursive_const_defined?(name)
70
70
  rescue NameError
71
71
  new(name) do |c|
72
72
  c.valid_name = false
@@ -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
 
@@ -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, $stderr = $stderr, SilentIO
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
- $stderr = old
45
+ $VERBOSE = old
54
46
 
55
47
  def send(name, *args, &block)
56
48
  __send__(name, *args, &block)
@@ -3,7 +3,7 @@ module RSpec
3
3
  # Version information for RSpec mocks.
4
4
  module Version
5
5
  # Version of RSpec mocks currently in use in SemVer format.
6
- STRING = '3.10.0'
6
+ STRING = '3.11.0'
7
7
  end
8
8
  end
9
9
  end
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.10.0
4
+ version: 3.11.0
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: 2020-10-30 00:00:00.000000000 Z
48
+ date: 2022-02-09 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.10.0
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.10.0
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.15
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.15
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.10.0/Changelog.md
197
+ changelog_uri: https://github.com/rspec/rspec-mocks/blob/v3.11.0/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.1.3
217
+ rubygems_version: 3.3.3
218
218
  signing_key:
219
219
  specification_version: 4
220
- summary: rspec-mocks-3.10.0
220
+ summary: rspec-mocks-3.11.0
221
221
  test_files: []
metadata.gz.sig CHANGED
Binary file