rspec-mocks 3.10.3 → 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: a4977129849498908e5c8b2ca7cf93d16884a08ab6dd5511558e80a17ca59343
4
- data.tar.gz: e97a221ae0a1a0b79b809454095a0c0d4cef3048b4b17408d1c4f1e11efad075
3
+ metadata.gz: 12ce7d4b5f6accc3fb2b6af82646843de8ffd500352d4ca5367985e28fec0805
4
+ data.tar.gz: 9643bc17b54bd21725aa39946eacda8207e327bdb592a9e0be821ee42c59bddb
5
5
  SHA512:
6
- metadata.gz: 50d2119f48c3f066738682dec9ce64f7287204d620eb081bb6079b246e68219a0cf0dc3b9cfe0ca2681da097a8c6bbfc8827f55e29f2f584de741adb837814bd
7
- data.tar.gz: 39a62e9a35234b6021eff74dad5cb535e3b56b64060e8ea342ac38d8cfb24764d4971e52b47fa6c6963fcd2f6463231683fe54af4119f1389a98e20b9215286b
6
+ metadata.gz: 1a1fc3ad0ca28d5371d74985f236f9c222fc310743062a5e8746c5f995803bfd5b63de26b673b94460c6ec47eedfbb150425fe3bb59f0e5bdaf4d639ffe0bc0d
7
+ data.tar.gz: 352761f69232f8b5afb6ac918bb596c5961017f622f2aec36052f5f69c426449a51ef2af26394951cad5c7706a165446a9d80d6e01adafeb87e4f6e0804a46af
checksums.yaml.gz.sig CHANGED
Binary file
data/Changelog.md CHANGED
@@ -1,7 +1,15 @@
1
1
  ### Development
2
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.3...3-10-maintenance)
2
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.11.0...3-11-maintenance)
3
3
 
4
- ### 3.10.3 / 2021-01-28
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
5
13
  [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.10.2...v3.10.3)
6
14
 
7
15
  Bug Fixes:
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.
@@ -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
@@ -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
  #
@@ -684,6 +726,24 @@ module RSpec
684
726
  end
685
727
  end
686
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
+
687
747
  # Represents a configured implementation. Takes into account
688
748
  # any number of sub-implementations.
689
749
  # @private
@@ -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.3'
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.3
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: 2022-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
@@ -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.3/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
@@ -217,5 +217,5 @@ requirements: []
217
217
  rubygems_version: 3.3.3
218
218
  signing_key:
219
219
  specification_version: 4
220
- summary: rspec-mocks-3.10.3
220
+ summary: rspec-mocks-3.11.0
221
221
  test_files: []
metadata.gz.sig CHANGED
Binary file