rspec-mocks 3.10.2 → 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: 8df50d671b287d9eea08c7e0af0cc98ae18da52ce63543c0e48378d4230a889f
4
- data.tar.gz: 0e8e4186d4eefc8344439185e0533a53b980fd983f80d8faf600c5fe7f5ebf2d
3
+ metadata.gz: 12ce7d4b5f6accc3fb2b6af82646843de8ffd500352d4ca5367985e28fec0805
4
+ data.tar.gz: 9643bc17b54bd21725aa39946eacda8207e327bdb592a9e0be821ee42c59bddb
5
5
  SHA512:
6
- metadata.gz: 0b687302ef0bd48764d9b78df91c0ce9f4918e9697493fbf0d4083f77ac4bd99879a68975bca874b06a887d1f83bcaaca35f476d4a4036286684c37bb3e040c6
7
- data.tar.gz: 102e13e93f56865812cf40a46e3be075f67984dde3eaae091b3b14ffae2c96623f6c2e85112c6ffe759fc7be83c4ba8d0133b59fa91d5d0a3055307dc5c13273
6
+ metadata.gz: 1a1fc3ad0ca28d5371d74985f236f9c222fc310743062a5e8746c5f995803bfd5b63de26b673b94460c6ec47eedfbb150425fe3bb59f0e5bdaf4d639ffe0bc0d
7
+ data.tar.gz: 352761f69232f8b5afb6ac918bb596c5961017f622f2aec36052f5f69c426449a51ef2af26394951cad5c7706a165446a9d80d6e01adafeb87e4f6e0804a46af
checksums.yaml.gz.sig CHANGED
Binary file
data/Changelog.md CHANGED
@@ -1,5 +1,22 @@
1
1
  ### Development
2
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.2...main)
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)
3
20
 
4
21
  ### 3.10.2 / 2021-01-27
5
22
  [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?branch=3-10-maintenance)](https://github.com/rspec/rspec-mocks/actions) [![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.
@@ -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
@@ -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.2'
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.2
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: 2021-01-28 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.2/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.2.4
217
+ rubygems_version: 3.3.3
218
218
  signing_key:
219
219
  specification_version: 4
220
- summary: rspec-mocks-3.10.2
220
+ summary: rspec-mocks-3.11.0
221
221
  test_files: []
metadata.gz.sig CHANGED
Binary file