rspec-mocks 3.13.8 → 4.0.0.beta1
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
- checksums.yaml.gz.sig +0 -0
- data/Changelog.md +12 -6
- data/LICENSE.md +1 -0
- data/README.md +8 -39
- data/lib/rspec/mocks/any_instance/expectation_chain.rb +1 -1
- data/lib/rspec/mocks/any_instance/proxy.rb +3 -9
- data/lib/rspec/mocks/any_instance/recorder.rb +13 -27
- data/lib/rspec/mocks/any_instance/stub_chain.rb +1 -1
- data/lib/rspec/mocks/argument_list_matcher.rb +9 -11
- data/lib/rspec/mocks/configuration.rb +1 -73
- data/lib/rspec/mocks/error_generator.rb +14 -23
- data/lib/rspec/mocks/example_methods.rb +28 -28
- data/lib/rspec/mocks/instance_method_stasher.rb +25 -102
- data/lib/rspec/mocks/message_expectation.rb +2 -3
- data/lib/rspec/mocks/method_double.rb +61 -71
- data/lib/rspec/mocks/method_reference.rb +8 -26
- data/lib/rspec/mocks/minitest_integration.rb +1 -1
- data/lib/rspec/mocks/mutate_const.rb +0 -1
- data/lib/rspec/mocks/object_reference.rb +2 -8
- data/lib/rspec/mocks/order_group.rb +4 -15
- data/lib/rspec/mocks/proxy.rb +8 -27
- data/lib/rspec/mocks/space.rb +4 -17
- data/lib/rspec/mocks/standalone.rb +2 -0
- data/lib/rspec/mocks/test_double.rb +5 -3
- data/lib/rspec/mocks/verifying_double.rb +2 -3
- data/lib/rspec/mocks/verifying_proxy.rb +2 -4
- data/lib/rspec/mocks/version.rb +1 -1
- data/lib/rspec/mocks.rb +0 -2
- data.tar.gz.sig +0 -0
- metadata +14 -15
- metadata.gz.sig +0 -0
- data/lib/rspec/mocks/syntax.rb +0 -325
|
@@ -10,9 +10,8 @@ module RSpec
|
|
|
10
10
|
method_ref = __mock_proxy.method_reference[message]
|
|
11
11
|
|
|
12
12
|
case method_ref.visibility
|
|
13
|
-
when :public
|
|
14
|
-
when :private
|
|
15
|
-
when :protected then include_private || RUBY_VERSION.to_f < 2.0
|
|
13
|
+
when :public then true
|
|
14
|
+
when :private, :protected then include_private
|
|
16
15
|
else !method_ref.unimplemented?
|
|
17
16
|
end
|
|
18
17
|
end
|
|
@@ -147,13 +147,11 @@ module RSpec
|
|
|
147
147
|
end
|
|
148
148
|
|
|
149
149
|
def add_expectation(*args, &block)
|
|
150
|
-
|
|
151
|
-
super(*args, &block).tap { |x| x.method_reference = @method_reference }
|
|
150
|
+
super.tap { |x| x.method_reference = @method_reference }
|
|
152
151
|
end
|
|
153
152
|
|
|
154
153
|
def add_stub(*args, &block)
|
|
155
|
-
|
|
156
|
-
super(*args, &block).tap { |x| x.method_reference = @method_reference }
|
|
154
|
+
super.tap { |x| x.method_reference = @method_reference }
|
|
157
155
|
end
|
|
158
156
|
|
|
159
157
|
def proxy_method_invoked(obj, *args, &block)
|
data/lib/rspec/mocks/version.rb
CHANGED
data/lib/rspec/mocks.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
require 'rspec/support'
|
|
2
2
|
RSpec::Support.require_rspec_support 'caller_filter'
|
|
3
3
|
RSpec::Support.require_rspec_support 'warnings'
|
|
4
|
-
RSpec::Support.require_rspec_support 'ruby_features'
|
|
5
4
|
|
|
6
5
|
RSpec::Support.define_optimized_require_for_rspec(:mocks) { |f| require_relative f }
|
|
7
6
|
|
|
@@ -19,7 +18,6 @@ RSpec::Support.define_optimized_require_for_rspec(:mocks) { |f| require_relative
|
|
|
19
18
|
space
|
|
20
19
|
mutate_const
|
|
21
20
|
targets
|
|
22
|
-
syntax
|
|
23
21
|
configuration
|
|
24
22
|
verifying_double
|
|
25
23
|
version
|
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:
|
|
4
|
+
version: 4.0.0.beta1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Steven Baker
|
|
@@ -49,36 +49,36 @@ dependencies:
|
|
|
49
49
|
name: rspec-support
|
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- -
|
|
52
|
+
- - '='
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version:
|
|
54
|
+
version: 4.0.0.beta1
|
|
55
55
|
type: :runtime
|
|
56
56
|
prerelease: false
|
|
57
57
|
version_requirements: !ruby/object:Gem::Requirement
|
|
58
58
|
requirements:
|
|
59
|
-
- -
|
|
59
|
+
- - '='
|
|
60
60
|
- !ruby/object:Gem::Version
|
|
61
|
-
version:
|
|
61
|
+
version: 4.0.0.beta1
|
|
62
62
|
- !ruby/object:Gem::Dependency
|
|
63
63
|
name: diff-lcs
|
|
64
64
|
requirement: !ruby/object:Gem::Requirement
|
|
65
65
|
requirements:
|
|
66
66
|
- - ">="
|
|
67
67
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: 1.
|
|
68
|
+
version: 1.6.0
|
|
69
69
|
- - "<"
|
|
70
70
|
- !ruby/object:Gem::Version
|
|
71
|
-
version: '
|
|
71
|
+
version: '3.0'
|
|
72
72
|
type: :runtime
|
|
73
73
|
prerelease: false
|
|
74
74
|
version_requirements: !ruby/object:Gem::Requirement
|
|
75
75
|
requirements:
|
|
76
76
|
- - ">="
|
|
77
77
|
- !ruby/object:Gem::Version
|
|
78
|
-
version: 1.
|
|
78
|
+
version: 1.6.0
|
|
79
79
|
- - "<"
|
|
80
80
|
- !ruby/object:Gem::Version
|
|
81
|
-
version: '
|
|
81
|
+
version: '3.0'
|
|
82
82
|
description: RSpec's 'test double' framework, with support for stubbing and mocking
|
|
83
83
|
email: rspec@googlegroups.com
|
|
84
84
|
executables: []
|
|
@@ -124,7 +124,6 @@ files:
|
|
|
124
124
|
- lib/rspec/mocks/proxy.rb
|
|
125
125
|
- lib/rspec/mocks/space.rb
|
|
126
126
|
- lib/rspec/mocks/standalone.rb
|
|
127
|
-
- lib/rspec/mocks/syntax.rb
|
|
128
127
|
- lib/rspec/mocks/targets.rb
|
|
129
128
|
- lib/rspec/mocks/test_double.rb
|
|
130
129
|
- lib/rspec/mocks/verifying_double.rb
|
|
@@ -136,11 +135,11 @@ licenses:
|
|
|
136
135
|
- MIT
|
|
137
136
|
metadata:
|
|
138
137
|
bug_tracker_uri: https://github.com/rspec/rspec/issues
|
|
139
|
-
changelog_uri: https://github.com/rspec/rspec/
|
|
138
|
+
changelog_uri: https://github.com/rspec/rspec/tree/rspec-mocks-v4.0.0.beta1/rspec-mocks/Changelog.md
|
|
140
139
|
documentation_uri: https://rspec.info/documentation/
|
|
141
140
|
mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
|
|
141
|
+
source_code_uri: https://github.com/rspec/rspec/tree/rspec-mocks-v4.0.0.beta1/rspec-mocks
|
|
142
142
|
rubygems_mfa_required: 'true'
|
|
143
|
-
source_code_uri: https://github.com/rspec/rspec/blob/rspec-mocks-v3.13.8/rspec-mocks
|
|
144
143
|
rdoc_options:
|
|
145
144
|
- "--charset=UTF-8"
|
|
146
145
|
require_paths:
|
|
@@ -149,14 +148,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
149
148
|
requirements:
|
|
150
149
|
- - ">="
|
|
151
150
|
- !ruby/object:Gem::Version
|
|
152
|
-
version:
|
|
151
|
+
version: 3.0.0
|
|
153
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
153
|
requirements:
|
|
155
154
|
- - ">="
|
|
156
155
|
- !ruby/object:Gem::Version
|
|
157
156
|
version: '0'
|
|
158
157
|
requirements: []
|
|
159
|
-
rubygems_version: 4.0.
|
|
158
|
+
rubygems_version: 4.0.3
|
|
160
159
|
specification_version: 4
|
|
161
|
-
summary: rspec-mocks-
|
|
160
|
+
summary: rspec-mocks-4.0.0.beta1
|
|
162
161
|
test_files: []
|
metadata.gz.sig
CHANGED
|
Binary file
|
data/lib/rspec/mocks/syntax.rb
DELETED
|
@@ -1,325 +0,0 @@
|
|
|
1
|
-
module RSpec
|
|
2
|
-
module Mocks
|
|
3
|
-
# @api private
|
|
4
|
-
# Provides methods for enabling and disabling the available syntaxes
|
|
5
|
-
# provided by rspec-mocks.
|
|
6
|
-
module Syntax
|
|
7
|
-
# @private
|
|
8
|
-
def self.warn_about_should!
|
|
9
|
-
@warn_about_should = true
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# @private
|
|
13
|
-
def self.warn_unless_should_configured(method_name , replacement="the new `:expect` syntax or explicitly enable `:should`")
|
|
14
|
-
if @warn_about_should
|
|
15
|
-
RSpec.deprecate(
|
|
16
|
-
"Using `#{method_name}` from rspec-mocks' old `:should` syntax without explicitly enabling the syntax",
|
|
17
|
-
:replacement => replacement
|
|
18
|
-
)
|
|
19
|
-
|
|
20
|
-
@warn_about_should = false
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
# @api private
|
|
25
|
-
# Enables the should syntax (`dbl.stub`, `dbl.should_receive`, etc).
|
|
26
|
-
def self.enable_should(syntax_host=default_should_syntax_host)
|
|
27
|
-
@warn_about_should = false if syntax_host == default_should_syntax_host
|
|
28
|
-
return if should_enabled?(syntax_host)
|
|
29
|
-
|
|
30
|
-
syntax_host.class_exec do
|
|
31
|
-
def should_receive(message, opts={}, &block)
|
|
32
|
-
::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__)
|
|
33
|
-
::RSpec::Mocks.expect_message(self, message, opts, &block)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def should_not_receive(message, &block)
|
|
37
|
-
::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__)
|
|
38
|
-
::RSpec::Mocks.expect_message(self, message, {}, &block).never
|
|
39
|
-
end
|
|
40
|
-
|
|
41
|
-
def stub(message_or_hash, opts={}, &block)
|
|
42
|
-
::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__)
|
|
43
|
-
if ::Hash === message_or_hash
|
|
44
|
-
message_or_hash.each { |message, value| stub(message).and_return value }
|
|
45
|
-
else
|
|
46
|
-
::RSpec::Mocks.allow_message(self, message_or_hash, opts, &block)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
def unstub(message)
|
|
51
|
-
::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__, "`allow(...).to receive(...).and_call_original` or explicitly enable `:should`")
|
|
52
|
-
::RSpec::Mocks.space.proxy_for(self).remove_stub(message)
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def stub_chain(*chain, &blk)
|
|
56
|
-
::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__)
|
|
57
|
-
::RSpec::Mocks::StubChain.stub_chain_on(self, *chain, &blk)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def as_null_object
|
|
61
|
-
::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__)
|
|
62
|
-
@_null_object = true
|
|
63
|
-
::RSpec::Mocks.space.proxy_for(self).as_null_object
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
def null_object?
|
|
67
|
-
::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__)
|
|
68
|
-
defined?(@_null_object)
|
|
69
|
-
end
|
|
70
|
-
|
|
71
|
-
def received_message?(message, *args, &block)
|
|
72
|
-
::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__)
|
|
73
|
-
::RSpec::Mocks.space.proxy_for(self).received_message?(message, *args, &block)
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
unless Class.respond_to? :any_instance
|
|
77
|
-
Class.class_exec do
|
|
78
|
-
def any_instance
|
|
79
|
-
::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__)
|
|
80
|
-
::RSpec::Mocks.space.any_instance_proxy_for(self)
|
|
81
|
-
end
|
|
82
|
-
end
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# @api private
|
|
88
|
-
# Disables the should syntax (`dbl.stub`, `dbl.should_receive`, etc).
|
|
89
|
-
def self.disable_should(syntax_host=default_should_syntax_host)
|
|
90
|
-
return unless should_enabled?(syntax_host)
|
|
91
|
-
|
|
92
|
-
syntax_host.class_exec do
|
|
93
|
-
undef should_receive
|
|
94
|
-
undef should_not_receive
|
|
95
|
-
undef stub
|
|
96
|
-
undef unstub
|
|
97
|
-
undef stub_chain
|
|
98
|
-
undef as_null_object
|
|
99
|
-
undef null_object?
|
|
100
|
-
undef received_message?
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
Class.class_exec do
|
|
104
|
-
undef any_instance
|
|
105
|
-
end
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
# @api private
|
|
109
|
-
# Enables the expect syntax (`expect(dbl).to receive`, `allow(dbl).to receive`, etc).
|
|
110
|
-
def self.enable_expect(syntax_host=::RSpec::Mocks::ExampleMethods)
|
|
111
|
-
return if expect_enabled?(syntax_host)
|
|
112
|
-
|
|
113
|
-
syntax_host.class_exec do
|
|
114
|
-
def receive(method_name, &block)
|
|
115
|
-
Matchers::Receive.new(method_name, block)
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
def receive_messages(message_return_value_hash, &_block)
|
|
119
|
-
matcher = Matchers::ReceiveMessages.new(message_return_value_hash)
|
|
120
|
-
matcher.warn_about_block if block_given?
|
|
121
|
-
matcher
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
def receive_message_chain(*messages, &block)
|
|
125
|
-
Matchers::ReceiveMessageChain.new(messages, &block)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
def allow(target)
|
|
129
|
-
AllowanceTarget.new(target)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
def expect_any_instance_of(klass)
|
|
133
|
-
AnyInstanceExpectationTarget.new(klass)
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
def allow_any_instance_of(klass)
|
|
137
|
-
AnyInstanceAllowanceTarget.new(klass)
|
|
138
|
-
end
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
RSpec::Mocks::ExampleMethods::ExpectHost.class_exec do
|
|
142
|
-
def expect(target)
|
|
143
|
-
ExpectationTarget.new(target)
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
# @api private
|
|
149
|
-
# Disables the expect syntax (`expect(dbl).to receive`, `allow(dbl).to receive`, etc).
|
|
150
|
-
def self.disable_expect(syntax_host=::RSpec::Mocks::ExampleMethods)
|
|
151
|
-
return unless expect_enabled?(syntax_host)
|
|
152
|
-
|
|
153
|
-
syntax_host.class_exec do
|
|
154
|
-
undef receive
|
|
155
|
-
undef receive_messages
|
|
156
|
-
undef receive_message_chain
|
|
157
|
-
undef allow
|
|
158
|
-
undef expect_any_instance_of
|
|
159
|
-
undef allow_any_instance_of
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
RSpec::Mocks::ExampleMethods::ExpectHost.class_exec do
|
|
163
|
-
undef expect
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
# @api private
|
|
168
|
-
# Indicates whether or not the should syntax is enabled.
|
|
169
|
-
def self.should_enabled?(syntax_host=default_should_syntax_host)
|
|
170
|
-
syntax_host.method_defined?(:should_receive)
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
# @api private
|
|
174
|
-
# Indicates whether or not the expect syntax is enabled.
|
|
175
|
-
def self.expect_enabled?(syntax_host=::RSpec::Mocks::ExampleMethods)
|
|
176
|
-
syntax_host.method_defined?(:allow)
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
# @api private
|
|
180
|
-
# Determines where the methods like `should_receive`, and `stub` are added.
|
|
181
|
-
def self.default_should_syntax_host
|
|
182
|
-
# JRuby 1.7.4 introduces a regression whereby `defined?(::BasicObject) => nil`
|
|
183
|
-
# yet `BasicObject` still exists and patching onto ::Object breaks things
|
|
184
|
-
# e.g. SimpleDelegator expectations won't work
|
|
185
|
-
#
|
|
186
|
-
# See: https://github.com/jruby/jruby/issues/814
|
|
187
|
-
if defined?(JRUBY_VERSION) && JRUBY_VERSION == '1.7.4' && RUBY_VERSION.to_f > 1.8
|
|
188
|
-
return ::BasicObject
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
# On 1.8.7, Object.ancestors.last == Kernel but
|
|
192
|
-
# things blow up if we include `RSpec::Mocks::Methods`
|
|
193
|
-
# into Kernel...not sure why.
|
|
194
|
-
return Object unless defined?(::BasicObject)
|
|
195
|
-
|
|
196
|
-
# MacRuby has BasicObject but it's not the root class.
|
|
197
|
-
return Object unless Object.ancestors.last == ::BasicObject
|
|
198
|
-
|
|
199
|
-
::BasicObject
|
|
200
|
-
end
|
|
201
|
-
end
|
|
202
|
-
end
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
if defined?(BasicObject)
|
|
206
|
-
# The legacy `:should` syntax adds the following methods directly to
|
|
207
|
-
# `BasicObject` so that they are available off of any object. Note, however,
|
|
208
|
-
# that this syntax does not always play nice with delegate/proxy objects.
|
|
209
|
-
# We recommend you use the non-monkeypatching `:expect` syntax instead.
|
|
210
|
-
# @see Class
|
|
211
|
-
class BasicObject
|
|
212
|
-
# @method should_receive
|
|
213
|
-
# Sets an expectation that this object should receive a message before
|
|
214
|
-
# the end of the example.
|
|
215
|
-
#
|
|
216
|
-
# @example
|
|
217
|
-
# logger = double('logger')
|
|
218
|
-
# thing_that_logs = ThingThatLogs.new(logger)
|
|
219
|
-
# logger.should_receive(:log)
|
|
220
|
-
# thing_that_logs.do_something_that_logs_a_message
|
|
221
|
-
#
|
|
222
|
-
# @note This is only available when you have enabled the `should` syntax.
|
|
223
|
-
# @see RSpec::Mocks::ExampleMethods#expect
|
|
224
|
-
|
|
225
|
-
# @method should_not_receive
|
|
226
|
-
# Sets and expectation that this object should _not_ receive a message
|
|
227
|
-
# during this example.
|
|
228
|
-
# @see RSpec::Mocks::ExampleMethods#expect
|
|
229
|
-
|
|
230
|
-
# @method stub
|
|
231
|
-
# Tells the object to respond to the message with the specified value.
|
|
232
|
-
#
|
|
233
|
-
# @example
|
|
234
|
-
# counter.stub(:count).and_return(37)
|
|
235
|
-
# counter.stub(:count => 37)
|
|
236
|
-
# counter.stub(:count) { 37 }
|
|
237
|
-
#
|
|
238
|
-
# @note This is only available when you have enabled the `should` syntax.
|
|
239
|
-
# @see RSpec::Mocks::ExampleMethods#allow
|
|
240
|
-
|
|
241
|
-
# @method unstub
|
|
242
|
-
# Removes a stub. On a double, the object will no longer respond to
|
|
243
|
-
# `message`. On a real object, the original method (if it exists) is
|
|
244
|
-
# restored.
|
|
245
|
-
#
|
|
246
|
-
# This is rarely used, but can be useful when a stub is set up during a
|
|
247
|
-
# shared `before` hook for the common case, but you want to replace it
|
|
248
|
-
# for a special case.
|
|
249
|
-
#
|
|
250
|
-
# @note This is only available when you have enabled the `should` syntax.
|
|
251
|
-
|
|
252
|
-
# @method stub_chain
|
|
253
|
-
# @overload stub_chain(method1, method2)
|
|
254
|
-
# @overload stub_chain("method1.method2")
|
|
255
|
-
# @overload stub_chain(method1, method_to_value_hash)
|
|
256
|
-
#
|
|
257
|
-
# Stubs a chain of methods.
|
|
258
|
-
#
|
|
259
|
-
# ## Warning:
|
|
260
|
-
#
|
|
261
|
-
# Chains can be arbitrarily long, which makes it quite painless to
|
|
262
|
-
# violate the Law of Demeter in violent ways, so you should consider any
|
|
263
|
-
# use of `stub_chain` a code smell. Even though not all code smells
|
|
264
|
-
# indicate real problems (think fluent interfaces), `stub_chain` still
|
|
265
|
-
# results in brittle examples. For example, if you write
|
|
266
|
-
# `foo.stub_chain(:bar, :baz => 37)` in a spec and then the
|
|
267
|
-
# implementation calls `foo.baz.bar`, the stub will not work.
|
|
268
|
-
#
|
|
269
|
-
# @example
|
|
270
|
-
# double.stub_chain("foo.bar") { :baz }
|
|
271
|
-
# double.stub_chain(:foo, :bar => :baz)
|
|
272
|
-
# double.stub_chain(:foo, :bar) { :baz }
|
|
273
|
-
#
|
|
274
|
-
# # Given any of ^^ these three forms ^^:
|
|
275
|
-
# double.foo.bar # => :baz
|
|
276
|
-
#
|
|
277
|
-
# # Common use in Rails/ActiveRecord:
|
|
278
|
-
# Article.stub_chain("recent.published") { [Article.new] }
|
|
279
|
-
#
|
|
280
|
-
# @note This is only available when you have enabled the `should` syntax.
|
|
281
|
-
# @see RSpec::Mocks::ExampleMethods#receive_message_chain
|
|
282
|
-
|
|
283
|
-
# @method as_null_object
|
|
284
|
-
# Tells the object to respond to all messages. If specific stub values
|
|
285
|
-
# are declared, they'll work as expected. If not, the receiver is
|
|
286
|
-
# returned.
|
|
287
|
-
#
|
|
288
|
-
# @note This is only available when you have enabled the `should` syntax.
|
|
289
|
-
|
|
290
|
-
# @method null_object?
|
|
291
|
-
# Returns true if this object has received `as_null_object`
|
|
292
|
-
#
|
|
293
|
-
# @note This is only available when you have enabled the `should` syntax.
|
|
294
|
-
end
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
# The legacy `:should` syntax adds the `any_instance` to `Class`.
|
|
298
|
-
# We generally recommend you use the newer `:expect` syntax instead,
|
|
299
|
-
# which allows you to stub any instance of a class using
|
|
300
|
-
# `allow_any_instance_of(klass)` or mock any instance using
|
|
301
|
-
# `expect_any_instance_of(klass)`.
|
|
302
|
-
# @see BasicObject
|
|
303
|
-
class Class
|
|
304
|
-
# @method any_instance
|
|
305
|
-
# Used to set stubs and message expectations on any instance of a given
|
|
306
|
-
# class. Returns a [Recorder](Recorder), which records messages like
|
|
307
|
-
# `stub` and `should_receive` for later playback on instances of the
|
|
308
|
-
# class.
|
|
309
|
-
#
|
|
310
|
-
# @example
|
|
311
|
-
# Car.any_instance.should_receive(:go)
|
|
312
|
-
# race = Race.new
|
|
313
|
-
# race.cars << Car.new
|
|
314
|
-
# race.go # assuming this delegates to all of its cars
|
|
315
|
-
# # this example would pass
|
|
316
|
-
#
|
|
317
|
-
# Account.any_instance.stub(:balance) { Money.new(:USD, 25) }
|
|
318
|
-
# Account.new.balance # => Money.new(:USD, 25))
|
|
319
|
-
#
|
|
320
|
-
# @return [Recorder]
|
|
321
|
-
#
|
|
322
|
-
# @note This is only available when you have enabled the `should` syntax.
|
|
323
|
-
# @see RSpec::Mocks::ExampleMethods#expect_any_instance_of
|
|
324
|
-
# @see RSpec::Mocks::ExampleMethods#allow_any_instance_of
|
|
325
|
-
end
|