rspec-mocks-diag 3.8.1.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.
Files changed (48) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.yardopts +6 -0
  4. data/Changelog.md +1108 -0
  5. data/LICENSE.md +25 -0
  6. data/README.md +460 -0
  7. data/lib/rspec/mocks.rb +130 -0
  8. data/lib/rspec/mocks/any_instance.rb +11 -0
  9. data/lib/rspec/mocks/any_instance/chain.rb +110 -0
  10. data/lib/rspec/mocks/any_instance/error_generator.rb +31 -0
  11. data/lib/rspec/mocks/any_instance/expect_chain_chain.rb +31 -0
  12. data/lib/rspec/mocks/any_instance/expectation_chain.rb +50 -0
  13. data/lib/rspec/mocks/any_instance/message_chains.rb +83 -0
  14. data/lib/rspec/mocks/any_instance/proxy.rb +116 -0
  15. data/lib/rspec/mocks/any_instance/recorder.rb +289 -0
  16. data/lib/rspec/mocks/any_instance/stub_chain.rb +51 -0
  17. data/lib/rspec/mocks/any_instance/stub_chain_chain.rb +23 -0
  18. data/lib/rspec/mocks/argument_list_matcher.rb +100 -0
  19. data/lib/rspec/mocks/argument_matchers.rb +320 -0
  20. data/lib/rspec/mocks/configuration.rb +212 -0
  21. data/lib/rspec/mocks/error_generator.rb +378 -0
  22. data/lib/rspec/mocks/example_methods.rb +434 -0
  23. data/lib/rspec/mocks/instance_method_stasher.rb +146 -0
  24. data/lib/rspec/mocks/marshal_extension.rb +41 -0
  25. data/lib/rspec/mocks/matchers/expectation_customization.rb +20 -0
  26. data/lib/rspec/mocks/matchers/have_received.rb +134 -0
  27. data/lib/rspec/mocks/matchers/receive.rb +132 -0
  28. data/lib/rspec/mocks/matchers/receive_message_chain.rb +82 -0
  29. data/lib/rspec/mocks/matchers/receive_messages.rb +77 -0
  30. data/lib/rspec/mocks/message_chain.rb +87 -0
  31. data/lib/rspec/mocks/message_expectation.rb +748 -0
  32. data/lib/rspec/mocks/method_double.rb +287 -0
  33. data/lib/rspec/mocks/method_reference.rb +202 -0
  34. data/lib/rspec/mocks/minitest_integration.rb +68 -0
  35. data/lib/rspec/mocks/mutate_const.rb +339 -0
  36. data/lib/rspec/mocks/object_reference.rb +149 -0
  37. data/lib/rspec/mocks/order_group.rb +81 -0
  38. data/lib/rspec/mocks/proxy.rb +485 -0
  39. data/lib/rspec/mocks/space.rb +238 -0
  40. data/lib/rspec/mocks/standalone.rb +3 -0
  41. data/lib/rspec/mocks/syntax.rb +325 -0
  42. data/lib/rspec/mocks/targets.rb +124 -0
  43. data/lib/rspec/mocks/test_double.rb +171 -0
  44. data/lib/rspec/mocks/verifying_double.rb +129 -0
  45. data/lib/rspec/mocks/verifying_message_expectation.rb +54 -0
  46. data/lib/rspec/mocks/verifying_proxy.rb +220 -0
  47. data/lib/rspec/mocks/version.rb +9 -0
  48. metadata +186 -0
@@ -0,0 +1,220 @@
1
+ RSpec::Support.require_rspec_mocks 'verifying_message_expectation'
2
+ RSpec::Support.require_rspec_mocks 'method_reference'
3
+
4
+ module RSpec
5
+ module Mocks
6
+ # @private
7
+ class CallbackInvocationStrategy
8
+ def call(doubled_module)
9
+ RSpec::Mocks.configuration.verifying_double_callbacks.each do |block|
10
+ block.call doubled_module
11
+ end
12
+ end
13
+ end
14
+
15
+ # @private
16
+ class NoCallbackInvocationStrategy
17
+ def call(_doubled_module)
18
+ end
19
+ end
20
+
21
+ # @private
22
+ module VerifyingProxyMethods
23
+ def add_stub(method_name, opts={}, &implementation)
24
+ ensure_implemented(method_name)
25
+ super
26
+ end
27
+
28
+ def add_simple_stub(method_name, *args)
29
+ ensure_implemented(method_name)
30
+ super
31
+ end
32
+
33
+ def add_message_expectation(method_name, opts={}, &block)
34
+ ensure_implemented(method_name)
35
+ super
36
+ end
37
+
38
+ def ensure_implemented(method_name)
39
+ return unless method_reference[method_name].unimplemented?
40
+
41
+ @error_generator.raise_unimplemented_error(
42
+ @doubled_module,
43
+ method_name,
44
+ @object
45
+ )
46
+ end
47
+
48
+ def ensure_publicly_implemented(method_name, _object)
49
+ ensure_implemented(method_name)
50
+ visibility = method_reference[method_name].visibility
51
+
52
+ return if visibility == :public
53
+ @error_generator.raise_non_public_error(method_name, visibility)
54
+ end
55
+ end
56
+
57
+ # A verifying proxy mostly acts like a normal proxy, except that it
58
+ # contains extra logic to try and determine the validity of any expectation
59
+ # set on it. This includes whether or not methods have been defined and the
60
+ # validatiy of arguments on method calls.
61
+ #
62
+ # In all other ways this behaves like a normal proxy. It only adds the
63
+ # verification behaviour to specific methods then delegates to the parent
64
+ # implementation.
65
+ #
66
+ # These checks are only activated if the doubled class has already been
67
+ # loaded, otherwise they are disabled. This allows for testing in
68
+ # isolation.
69
+ #
70
+ # @private
71
+ class VerifyingProxy < TestDoubleProxy
72
+ include VerifyingProxyMethods
73
+
74
+ def initialize(object, order_group, doubled_module, method_reference_class)
75
+ super(object, order_group)
76
+ @object = object
77
+ @doubled_module = doubled_module
78
+ @method_reference_class = method_reference_class
79
+
80
+ # A custom method double is required to pass through a way to lookup
81
+ # methods to determine their parameters. This is only relevant if the doubled
82
+ # class is loaded.
83
+ @method_doubles = Hash.new do |h, k|
84
+ h[k] = VerifyingMethodDouble.new(@object, k, self, method_reference[k])
85
+ end
86
+ end
87
+
88
+ def method_reference
89
+ @method_reference ||= Hash.new do |h, k|
90
+ h[k] = @method_reference_class.for(@doubled_module, k)
91
+ end
92
+ end
93
+
94
+ def visibility_for(method_name)
95
+ method_reference[method_name].visibility
96
+ end
97
+
98
+ def validate_arguments!(method_name, args)
99
+ @method_doubles[method_name].validate_arguments!(args)
100
+ end
101
+ end
102
+
103
+ # @private
104
+ DEFAULT_CALLBACK_INVOCATION_STRATEGY = CallbackInvocationStrategy.new
105
+
106
+ # @private
107
+ class VerifyingPartialDoubleProxy < PartialDoubleProxy
108
+ include VerifyingProxyMethods
109
+
110
+ def initialize(object, expectation_ordering, optional_callback_invocation_strategy=DEFAULT_CALLBACK_INVOCATION_STRATEGY)
111
+ super(object, expectation_ordering)
112
+ @doubled_module = DirectObjectReference.new(object)
113
+
114
+ # A custom method double is required to pass through a way to lookup
115
+ # methods to determine their parameters.
116
+ @method_doubles = Hash.new do |h, k|
117
+ h[k] = VerifyingExistingMethodDouble.for(object, k, self)
118
+ end
119
+
120
+ optional_callback_invocation_strategy.call(@doubled_module)
121
+ end
122
+
123
+ def ensure_implemented(_method_name)
124
+ return if Mocks.configuration.temporarily_suppress_partial_double_verification
125
+ super
126
+ end
127
+
128
+ def method_reference
129
+ @method_doubles
130
+ end
131
+ end
132
+
133
+ # @private
134
+ class VerifyingPartialClassDoubleProxy < VerifyingPartialDoubleProxy
135
+ include PartialClassDoubleProxyMethods
136
+ end
137
+
138
+ # @private
139
+ class VerifyingMethodDouble < MethodDouble
140
+ def initialize(object, method_name, proxy, method_reference)
141
+ super(object, method_name, proxy)
142
+ @method_reference = method_reference
143
+ end
144
+
145
+ def message_expectation_class
146
+ VerifyingMessageExpectation
147
+ end
148
+
149
+ def add_expectation(*args, &block)
150
+ # explict params necessary for 1.8.7 see #626
151
+ super(*args, &block).tap { |x| x.method_reference = @method_reference }
152
+ end
153
+
154
+ def add_stub(*args, &block)
155
+ # explict params necessary for 1.8.7 see #626
156
+ super(*args, &block).tap { |x| x.method_reference = @method_reference }
157
+ end
158
+
159
+ def proxy_method_invoked(obj, *args, &block)
160
+ validate_arguments!(args)
161
+ super
162
+ end
163
+
164
+ def validate_arguments!(actual_args)
165
+ @method_reference.with_signature do |signature|
166
+ verifier = Support::StrictSignatureVerifier.new(signature, actual_args)
167
+ raise ArgumentError, verifier.error_message unless verifier.valid?
168
+ end
169
+ end
170
+ end
171
+
172
+ # A VerifyingMethodDouble fetches the method to verify against from the
173
+ # original object, using a MethodReference. This works for pure doubles,
174
+ # but when the original object is itself the one being modified we need to
175
+ # collapse the reference and the method double into a single object so that
176
+ # we can access the original pristine method definition.
177
+ #
178
+ # @private
179
+ class VerifyingExistingMethodDouble < VerifyingMethodDouble
180
+ def initialize(object, method_name, proxy)
181
+ super(object, method_name, proxy, self)
182
+
183
+ @valid_method = object.respond_to?(method_name, true)
184
+
185
+ # Trigger an eager find of the original method since if we find it any
186
+ # later we end up getting a stubbed method with incorrect arity.
187
+ save_original_implementation_callable!
188
+ end
189
+
190
+ def with_signature
191
+ yield Support::MethodSignature.new(original_implementation_callable)
192
+ end
193
+
194
+ def unimplemented?
195
+ !@valid_method
196
+ end
197
+
198
+ def self.for(object, method_name, proxy)
199
+ if ClassNewMethodReference.applies_to?(method_name) { object }
200
+ VerifyingExistingClassNewMethodDouble
201
+ elsif Mocks.configuration.temporarily_suppress_partial_double_verification
202
+ MethodDouble
203
+ else
204
+ self
205
+ end.new(object, method_name, proxy)
206
+ end
207
+ end
208
+
209
+ # Used in place of a `VerifyingExistingMethodDouble` for the specific case
210
+ # of mocking or stubbing a `new` method on a class. In this case, we substitute
211
+ # the method signature from `#initialize` since new's signature is just `*args`.
212
+ #
213
+ # @private
214
+ class VerifyingExistingClassNewMethodDouble < VerifyingExistingMethodDouble
215
+ def with_signature
216
+ yield Support::MethodSignature.new(object.instance_method(:initialize))
217
+ end
218
+ end
219
+ end
220
+ end
@@ -0,0 +1,9 @@
1
+ module RSpec
2
+ module Mocks
3
+ # Version information for RSpec mocks.
4
+ module Version
5
+ # Version of RSpec mocks currently in use in SemVer format.
6
+ STRING = '3.8.1.1'
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rspec-mocks-diag
3
+ version: !ruby/object:Gem::Version
4
+ version: 3.8.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Steven Baker
8
+ - David Chelimsky
9
+ - Myron Marston
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2019-08-12 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rspec-support
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: 3.8.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: 3.8.0
29
+ - !ruby/object:Gem::Dependency
30
+ name: diff-lcs
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 1.2.0
36
+ - - "<"
37
+ - !ruby/object:Gem::Version
38
+ version: '2.0'
39
+ type: :runtime
40
+ prerelease: false
41
+ version_requirements: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.0
46
+ - - "<"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.0'
49
+ - !ruby/object:Gem::Dependency
50
+ name: rake
51
+ requirement: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: 10.0.0
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 10.0.0
63
+ - !ruby/object:Gem::Dependency
64
+ name: cucumber
65
+ requirement: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 1.3.15
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 1.3.15
77
+ - !ruby/object:Gem::Dependency
78
+ name: aruba
79
+ requirement: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 0.6.2
84
+ type: :development
85
+ prerelease: false
86
+ version_requirements: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: 0.6.2
91
+ - !ruby/object:Gem::Dependency
92
+ name: minitest
93
+ requirement: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '5.2'
98
+ type: :development
99
+ prerelease: false
100
+ version_requirements: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - "~>"
103
+ - !ruby/object:Gem::Version
104
+ version: '5.2'
105
+ description: rspec-mocks with additional diagnostics
106
+ email: rspec@googlegroups.com
107
+ executables: []
108
+ extensions: []
109
+ extra_rdoc_files: []
110
+ files:
111
+ - ".document"
112
+ - ".yardopts"
113
+ - Changelog.md
114
+ - LICENSE.md
115
+ - README.md
116
+ - lib/rspec/mocks.rb
117
+ - lib/rspec/mocks/any_instance.rb
118
+ - lib/rspec/mocks/any_instance/chain.rb
119
+ - lib/rspec/mocks/any_instance/error_generator.rb
120
+ - lib/rspec/mocks/any_instance/expect_chain_chain.rb
121
+ - lib/rspec/mocks/any_instance/expectation_chain.rb
122
+ - lib/rspec/mocks/any_instance/message_chains.rb
123
+ - lib/rspec/mocks/any_instance/proxy.rb
124
+ - lib/rspec/mocks/any_instance/recorder.rb
125
+ - lib/rspec/mocks/any_instance/stub_chain.rb
126
+ - lib/rspec/mocks/any_instance/stub_chain_chain.rb
127
+ - lib/rspec/mocks/argument_list_matcher.rb
128
+ - lib/rspec/mocks/argument_matchers.rb
129
+ - lib/rspec/mocks/configuration.rb
130
+ - lib/rspec/mocks/error_generator.rb
131
+ - lib/rspec/mocks/example_methods.rb
132
+ - lib/rspec/mocks/instance_method_stasher.rb
133
+ - lib/rspec/mocks/marshal_extension.rb
134
+ - lib/rspec/mocks/matchers/expectation_customization.rb
135
+ - lib/rspec/mocks/matchers/have_received.rb
136
+ - lib/rspec/mocks/matchers/receive.rb
137
+ - lib/rspec/mocks/matchers/receive_message_chain.rb
138
+ - lib/rspec/mocks/matchers/receive_messages.rb
139
+ - lib/rspec/mocks/message_chain.rb
140
+ - lib/rspec/mocks/message_expectation.rb
141
+ - lib/rspec/mocks/method_double.rb
142
+ - lib/rspec/mocks/method_reference.rb
143
+ - lib/rspec/mocks/minitest_integration.rb
144
+ - lib/rspec/mocks/mutate_const.rb
145
+ - lib/rspec/mocks/object_reference.rb
146
+ - lib/rspec/mocks/order_group.rb
147
+ - lib/rspec/mocks/proxy.rb
148
+ - lib/rspec/mocks/space.rb
149
+ - lib/rspec/mocks/standalone.rb
150
+ - lib/rspec/mocks/syntax.rb
151
+ - lib/rspec/mocks/targets.rb
152
+ - lib/rspec/mocks/test_double.rb
153
+ - lib/rspec/mocks/verifying_double.rb
154
+ - lib/rspec/mocks/verifying_message_expectation.rb
155
+ - lib/rspec/mocks/verifying_proxy.rb
156
+ - lib/rspec/mocks/version.rb
157
+ homepage: https://github.com/p-mongo/rspec-mocks
158
+ licenses:
159
+ - MIT
160
+ metadata:
161
+ bug_tracker_uri: https://github.com/p-mongo/rspec-mocks/issues
162
+ changelog_uri: https://github.com/p-mongo/rspec-mocks/blob/v3.8.1.1/Changelog.md
163
+ documentation_uri: https://rspec.info/documentation/
164
+ mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
165
+ source_code_uri: https://github.com/p-mongo/rspec-mocks
166
+ post_install_message:
167
+ rdoc_options:
168
+ - "--charset=UTF-8"
169
+ require_paths:
170
+ - lib
171
+ required_ruby_version: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: 1.8.7
176
+ required_rubygems_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ requirements: []
182
+ rubygems_version: 3.0.3
183
+ signing_key:
184
+ specification_version: 4
185
+ summary: rspec-mocks-3.8.1.1
186
+ test_files: []