rspec-mocks 2.99.4 → 3.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +14 -6
- checksums.yaml.gz.sig +2 -0
- data.tar.gz.sig +1 -0
- data/Changelog.md +89 -105
- data/License.txt +1 -0
- data/README.md +77 -57
- data/features/argument_matchers/explicit.feature +5 -5
- data/features/argument_matchers/general_matchers.feature +10 -10
- data/features/argument_matchers/type_matchers.feature +3 -3
- data/features/message_expectations/allow_any_instance_of.feature +1 -1
- data/features/message_expectations/any_instance.feature +27 -5
- data/features/message_expectations/call_original.feature +2 -2
- data/features/message_expectations/expect_message_using_expect.feature +2 -2
- data/features/message_expectations/expect_message_using_should_receive.feature +2 -2
- data/features/message_expectations/receive_counts.feature +7 -7
- data/features/message_expectations/warn_when_expectation_is_set_on_nil.feature +3 -3
- data/features/method_stubs/README.md +3 -0
- data/features/method_stubs/any_instance.feature +11 -11
- data/features/method_stubs/as_null_object.feature +4 -4
- data/features/method_stubs/simple_return_value_with_stub.feature +7 -7
- data/features/method_stubs/stub_chain.feature +3 -3
- data/features/method_stubs/stub_implementation.feature +2 -2
- data/features/method_stubs/to_ary.feature +2 -2
- data/features/mutating_constants/hiding_defined_constant.feature +2 -2
- data/features/mutating_constants/stub_defined_constant.feature +5 -5
- data/features/mutating_constants/stub_undefined_constant.feature +6 -6
- data/features/outside_rspec/configuration.feature +0 -2
- data/features/outside_rspec/standalone.feature +1 -1
- data/features/spies/spy_partial_mock_method.feature +2 -2
- data/features/spies/spy_pure_mock_method.feature +5 -5
- data/features/spies/spy_unstubbed_method.feature +1 -1
- data/features/support/env.rb +10 -1
- data/features/test_frameworks/test_unit.feature +1 -1
- data/features/verifying_doubles/class_doubles.feature +88 -0
- data/features/verifying_doubles/dynamic_classes.feature +72 -0
- data/features/verifying_doubles/introduction.feature +85 -0
- data/features/verifying_doubles/object_doubles.feature +65 -0
- data/features/verifying_doubles/partial_doubles.feature +34 -0
- data/lib/rspec/mocks.rb +8 -34
- data/lib/rspec/mocks/any_instance/chain.rb +4 -34
- data/lib/rspec/mocks/any_instance/expectation_chain.rb +14 -4
- data/lib/rspec/mocks/any_instance/message_chains.rb +27 -12
- data/lib/rspec/mocks/any_instance/recorder.rb +23 -31
- data/lib/rspec/mocks/any_instance/stub_chain.rb +9 -4
- data/lib/rspec/mocks/argument_list_matcher.rb +8 -1
- data/lib/rspec/mocks/argument_matchers.rb +26 -12
- data/lib/rspec/mocks/arity_calculator.rb +66 -0
- data/lib/rspec/mocks/configuration.rb +42 -14
- data/lib/rspec/mocks/error_generator.rb +34 -10
- data/lib/rspec/mocks/example_methods.rb +64 -19
- data/lib/rspec/mocks/extensions/marshal.rb +0 -15
- data/lib/rspec/mocks/framework.rb +4 -4
- data/lib/rspec/mocks/instance_method_stasher.rb +80 -62
- data/lib/rspec/mocks/matchers/have_received.rb +18 -14
- data/lib/rspec/mocks/matchers/receive.rb +29 -7
- data/lib/rspec/mocks/matchers/receive_messages.rb +72 -0
- data/lib/rspec/mocks/message_expectation.rb +95 -148
- data/lib/rspec/mocks/method_double.rb +77 -139
- data/lib/rspec/mocks/method_reference.rb +95 -0
- data/lib/rspec/mocks/mock.rb +1 -1
- data/lib/rspec/mocks/mutate_const.rb +12 -9
- data/lib/rspec/mocks/object_reference.rb +90 -0
- data/lib/rspec/mocks/order_group.rb +49 -7
- data/lib/rspec/mocks/proxy.rb +72 -33
- data/lib/rspec/mocks/proxy_for_nil.rb +2 -2
- data/lib/rspec/mocks/space.rb +13 -18
- data/lib/rspec/mocks/stub_chain.rb +2 -2
- data/lib/rspec/mocks/syntax.rb +61 -36
- data/lib/rspec/mocks/targets.rb +40 -19
- data/lib/rspec/mocks/test_double.rb +12 -56
- data/lib/rspec/mocks/verifying_double.rb +77 -0
- data/lib/rspec/mocks/verifying_message_expecation.rb +60 -0
- data/lib/rspec/mocks/verifying_proxy.rb +151 -0
- data/lib/rspec/mocks/version.rb +1 -1
- data/spec/rspec/mocks/and_call_original_spec.rb +34 -30
- data/spec/rspec/mocks/and_yield_spec.rb +2 -2
- data/spec/rspec/mocks/any_instance/message_chains_spec.rb +1 -1
- data/spec/rspec/mocks/any_instance_spec.rb +53 -260
- data/spec/rspec/mocks/argument_expectation_spec.rb +4 -4
- data/spec/rspec/mocks/arity_calculator_spec.rb +95 -0
- data/spec/rspec/mocks/array_including_matcher_spec.rb +41 -0
- data/spec/rspec/mocks/at_least_spec.rb +4 -32
- data/spec/rspec/mocks/block_return_value_spec.rb +4 -135
- data/spec/rspec/mocks/combining_implementation_instructions_spec.rb +10 -11
- data/spec/rspec/mocks/configuration_spec.rb +79 -0
- data/spec/rspec/mocks/double_spec.rb +10 -78
- data/spec/rspec/mocks/extensions/marshal_spec.rb +0 -8
- data/spec/rspec/mocks/failing_argument_matchers_spec.rb +49 -4
- data/spec/rspec/mocks/instance_method_stasher_spec.rb +20 -3
- data/spec/rspec/mocks/matchers/have_received_spec.rb +74 -0
- data/spec/rspec/mocks/matchers/receive_messages_spec.rb +140 -0
- data/spec/rspec/mocks/matchers/receive_spec.rb +82 -42
- data/spec/rspec/mocks/methods_spec.rb +1 -1
- data/spec/rspec/mocks/{bug_report_830_spec.rb → mock_expectation_error_spec.rb} +4 -3
- data/spec/rspec/mocks/mock_ordering_spec.rb +11 -0
- data/spec/rspec/mocks/mock_space_spec.rb +10 -1
- data/spec/rspec/mocks/mock_spec.rb +26 -82
- data/spec/rspec/mocks/multiple_return_value_spec.rb +1 -1
- data/spec/rspec/mocks/mutate_const_spec.rb +18 -5
- data/spec/rspec/mocks/null_object_mock_spec.rb +6 -4
- data/spec/rspec/mocks/options_hash_spec.rb +3 -3
- data/spec/rspec/mocks/order_group_spec.rb +27 -0
- data/spec/rspec/mocks/partial_mock_spec.rb +101 -1
- data/spec/rspec/mocks/passing_argument_matchers_spec.rb +3 -20
- data/spec/rspec/mocks/record_messages_spec.rb +4 -4
- data/spec/rspec/mocks/serialization_spec.rb +4 -6
- data/spec/rspec/mocks/space_spec.rb +3 -3
- data/spec/rspec/mocks/stub_chain_spec.rb +0 -12
- data/spec/rspec/mocks/stub_spec.rb +23 -44
- data/spec/rspec/mocks/test_double_spec.rb +3 -22
- data/spec/rspec/mocks/verifying_double_spec.rb +327 -0
- data/spec/rspec/mocks/verifying_message_expecation_spec.rb +68 -0
- data/spec/rspec/mocks_spec.rb +16 -39
- data/spec/spec_helper.rb +29 -18
- metadata +131 -86
- metadata.gz.sig +1 -0
- data/features/message_expectations/expect_any_instance_of.feature +0 -27
- data/lib/rspec/mocks/caller_filter.rb +0 -60
- data/lib/rspec/mocks/deprecation.rb +0 -26
- data/lib/rspec/mocks/extensions/instance_exec.rb +0 -34
- data/lib/rspec/mocks/extensions/proc.rb +0 -63
- data/lib/spec/mocks.rb +0 -4
- data/spec/rspec/mocks/and_return_spec.rb +0 -17
- data/spec/rspec/mocks/any_number_of_times_spec.rb +0 -36
- data/spec/rspec/mocks/before_all_spec.rb +0 -74
- data/spec/rspec/mocks/bug_report_10260_spec.rb +0 -8
- data/spec/rspec/mocks/bug_report_10263_spec.rb +0 -27
- data/spec/rspec/mocks/bug_report_11545_spec.rb +0 -32
- data/spec/rspec/mocks/bug_report_496_spec.rb +0 -17
- data/spec/rspec/mocks/bug_report_600_spec.rb +0 -22
- data/spec/rspec/mocks/bug_report_7611_spec.rb +0 -16
- data/spec/rspec/mocks/bug_report_8165_spec.rb +0 -31
- data/spec/rspec/mocks/bug_report_957_spec.rb +0 -22
@@ -0,0 +1,90 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Mocks
|
3
|
+
|
4
|
+
# @api private
|
5
|
+
class ObjectReference
|
6
|
+
# Returns an appropriate Object or Module reference based
|
7
|
+
# on the given argument.
|
8
|
+
def self.for(object_module_or_name, allow_direct_object_refs = false)
|
9
|
+
case object_module_or_name
|
10
|
+
when Module then DirectModuleReference.new(object_module_or_name)
|
11
|
+
when String then NamedObjectReference.new(object_module_or_name)
|
12
|
+
else
|
13
|
+
if allow_direct_object_refs
|
14
|
+
DirectObjectReference.new(object_module_or_name)
|
15
|
+
else
|
16
|
+
raise ArgumentError,
|
17
|
+
"Module or String expected, got #{object_module_or_name.inspect}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
# Used when an object is passed to `object_double`.
|
24
|
+
# Represents a reference to that object.
|
25
|
+
# @api private
|
26
|
+
class DirectObjectReference
|
27
|
+
def initialize(object)
|
28
|
+
@object = object
|
29
|
+
end
|
30
|
+
|
31
|
+
def description
|
32
|
+
@object.inspect
|
33
|
+
end
|
34
|
+
|
35
|
+
def const_to_replace
|
36
|
+
raise ArgumentError,
|
37
|
+
"Can not perform constant replacement with an object."
|
38
|
+
end
|
39
|
+
|
40
|
+
def defined?
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
def when_loaded
|
45
|
+
yield @object
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# Used when a module is passed to `class_double` or `instance_double`.
|
50
|
+
# Represents a reference to that module.
|
51
|
+
# @api private
|
52
|
+
class DirectModuleReference < DirectObjectReference
|
53
|
+
def const_to_replace
|
54
|
+
@object.name
|
55
|
+
end
|
56
|
+
alias description const_to_replace
|
57
|
+
end
|
58
|
+
|
59
|
+
# Used when a string is passed to `class_double`, `instance_double`
|
60
|
+
# or `object_double`.
|
61
|
+
# Represents a reference to the object named (via a constant lookup)
|
62
|
+
# by the string.
|
63
|
+
# @api private
|
64
|
+
class NamedObjectReference
|
65
|
+
def initialize(const_name)
|
66
|
+
@const_name = const_name
|
67
|
+
end
|
68
|
+
|
69
|
+
def defined?
|
70
|
+
!!object
|
71
|
+
end
|
72
|
+
|
73
|
+
def const_to_replace
|
74
|
+
@const_name
|
75
|
+
end
|
76
|
+
alias description const_to_replace
|
77
|
+
|
78
|
+
def when_loaded(&block)
|
79
|
+
yield object if object
|
80
|
+
end
|
81
|
+
|
82
|
+
private
|
83
|
+
|
84
|
+
def object
|
85
|
+
@object ||= Constant.original(@const_name).original_value
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
@@ -3,38 +3,80 @@ module RSpec
|
|
3
3
|
# @private
|
4
4
|
class OrderGroup
|
5
5
|
def initialize
|
6
|
-
@
|
6
|
+
@expectations = []
|
7
|
+
@invocation_order = []
|
8
|
+
@index = 0
|
7
9
|
end
|
8
10
|
|
9
11
|
# @private
|
10
12
|
def register(expectation)
|
11
|
-
@
|
13
|
+
@expectations << expectation
|
14
|
+
end
|
15
|
+
|
16
|
+
def invoked(message)
|
17
|
+
@invocation_order << message
|
12
18
|
end
|
13
19
|
|
14
20
|
# @private
|
15
21
|
def ready_for?(expectation)
|
16
|
-
|
22
|
+
remaining_expectations.find(&:ordered?) == expectation
|
17
23
|
end
|
18
24
|
|
19
25
|
# @private
|
20
26
|
def consume
|
21
|
-
|
27
|
+
remaining_expectations.each_with_index do |expectation, index|
|
28
|
+
if expectation.ordered?
|
29
|
+
@index += index + 1
|
30
|
+
return expectation
|
31
|
+
end
|
32
|
+
end
|
33
|
+
nil
|
22
34
|
end
|
23
35
|
|
24
36
|
# @private
|
25
37
|
def handle_order_constraint(expectation)
|
26
|
-
return unless
|
38
|
+
return unless expectation.ordered? && remaining_expectations.include?(expectation)
|
27
39
|
return consume if ready_for?(expectation)
|
28
40
|
expectation.raise_out_of_order_error
|
29
41
|
end
|
30
42
|
|
43
|
+
def verify_invocation_order(expectation)
|
44
|
+
expectation.raise_out_of_order_error unless expectations_invoked_in_order?
|
45
|
+
true
|
46
|
+
end
|
47
|
+
|
31
48
|
def clear
|
32
|
-
@
|
49
|
+
@index = 0
|
50
|
+
@invocation_order.clear
|
51
|
+
@expectations.clear
|
33
52
|
end
|
34
53
|
|
35
54
|
def empty?
|
36
|
-
@
|
55
|
+
@expectations.empty?
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
def remaining_expectations
|
61
|
+
@expectations[@index..-1] || []
|
62
|
+
end
|
63
|
+
|
64
|
+
def expectations_invoked_in_order?
|
65
|
+
invoked_expectations == expected_invocations
|
66
|
+
end
|
67
|
+
|
68
|
+
def invoked_expectations
|
69
|
+
@expectations.select { |e| e.ordered? && @invocation_order.include?(e) }
|
70
|
+
end
|
71
|
+
|
72
|
+
def expected_invocations
|
73
|
+
@invocation_order.map { |invocation| expectation_for(invocation) }.compact
|
74
|
+
end
|
75
|
+
|
76
|
+
def expectation_for(message)
|
77
|
+
@expectations.find { |e| message == e }
|
37
78
|
end
|
79
|
+
|
38
80
|
end
|
39
81
|
end
|
40
82
|
end
|
data/lib/rspec/mocks/proxy.rb
CHANGED
@@ -2,17 +2,23 @@ module RSpec
|
|
2
2
|
module Mocks
|
3
3
|
# @private
|
4
4
|
class Proxy
|
5
|
+
SpecificMessage = Struct.new(:object,:message) do
|
6
|
+
def ==(expectation)
|
7
|
+
expectation.orig_object == object && expectation.message == message
|
8
|
+
end
|
9
|
+
end
|
5
10
|
|
6
11
|
# @private
|
7
|
-
def initialize(object, name=nil, options={})
|
12
|
+
def initialize(object, order_group, name=nil, options={})
|
8
13
|
@object = object
|
14
|
+
@order_group = order_group
|
9
15
|
@name = name
|
10
|
-
@error_generator = ErrorGenerator.new
|
16
|
+
@error_generator = ErrorGenerator.new(object, name)
|
11
17
|
@expectation_ordering = RSpec::Mocks::space.expectation_ordering
|
12
18
|
@messages_received = []
|
13
19
|
@options = options
|
14
|
-
@already_proxied_respond_to = false
|
15
20
|
@null_object = false
|
21
|
+
@method_doubles = Hash.new { |h, k| h[k] = MethodDouble.new(@object, k, self) }
|
16
22
|
end
|
17
23
|
|
18
24
|
# @private
|
@@ -32,18 +38,13 @@ module RSpec
|
|
32
38
|
end
|
33
39
|
|
34
40
|
# @private
|
35
|
-
def
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
# @private
|
40
|
-
def already_proxied_respond_to?
|
41
|
-
@already_proxied_respond_to
|
41
|
+
def method_handle_for(message)
|
42
|
+
nil
|
42
43
|
end
|
43
44
|
|
44
45
|
# @private
|
45
46
|
def add_message_expectation(location, method_name, opts={}, &block)
|
46
|
-
meth_double =
|
47
|
+
meth_double = method_double_for(method_name)
|
47
48
|
|
48
49
|
if null_object? && !block
|
49
50
|
meth_double.add_default_stub(@error_generator, @expectation_ordering, location, opts) do
|
@@ -54,9 +55,14 @@ module RSpec
|
|
54
55
|
meth_double.add_expectation @error_generator, @expectation_ordering, location, opts, &block
|
55
56
|
end
|
56
57
|
|
58
|
+
# @private
|
59
|
+
def add_simple_expectation(method_name, response, location)
|
60
|
+
method_double_for(method_name).add_simple_expectation method_name, response, @error_generator, location
|
61
|
+
end
|
62
|
+
|
57
63
|
# @private
|
58
64
|
def build_expectation(method_name)
|
59
|
-
meth_double =
|
65
|
+
meth_double = method_double_for(method_name)
|
60
66
|
|
61
67
|
meth_double.build_expectation(
|
62
68
|
@error_generator,
|
@@ -65,9 +71,9 @@ module RSpec
|
|
65
71
|
end
|
66
72
|
|
67
73
|
# @private
|
68
|
-
def replay_received_message_on(expectation)
|
74
|
+
def replay_received_message_on(expectation, &block)
|
69
75
|
expected_method_name = expectation.message
|
70
|
-
meth_double =
|
76
|
+
meth_double = method_double_for(expected_method_name)
|
71
77
|
|
72
78
|
if meth_double.expectations.any?
|
73
79
|
@error_generator.raise_expectation_on_mocked_method(expected_method_name)
|
@@ -80,8 +86,10 @@ module RSpec
|
|
80
86
|
@messages_received.each do |(actual_method_name, args, _)|
|
81
87
|
if expectation.matches?(actual_method_name, *args)
|
82
88
|
expectation.invoke(nil)
|
89
|
+
block.call(*args) if block
|
83
90
|
end
|
84
91
|
end
|
92
|
+
|
85
93
|
end
|
86
94
|
|
87
95
|
# @private
|
@@ -95,28 +103,34 @@ module RSpec
|
|
95
103
|
|
96
104
|
# @private
|
97
105
|
def add_stub(location, method_name, opts={}, &implementation)
|
98
|
-
|
106
|
+
method_double_for(method_name).add_stub @error_generator, @expectation_ordering, location, opts, &implementation
|
107
|
+
end
|
108
|
+
|
109
|
+
# @private
|
110
|
+
def add_simple_stub(method_name, response)
|
111
|
+
method_double_for(method_name).add_simple_stub method_name, response
|
99
112
|
end
|
100
113
|
|
101
114
|
# @private
|
102
115
|
def remove_stub(method_name)
|
103
|
-
|
116
|
+
method_double_for(method_name).remove_stub
|
104
117
|
end
|
105
118
|
|
119
|
+
# @private
|
106
120
|
def remove_single_stub(method_name, stub)
|
107
|
-
|
121
|
+
method_double_for(method_name).remove_single_stub(stub)
|
108
122
|
end
|
109
123
|
|
110
124
|
# @private
|
111
125
|
def verify
|
112
|
-
method_doubles.
|
126
|
+
@method_doubles.each_value {|d| d.verify}
|
113
127
|
ensure
|
114
128
|
reset
|
115
129
|
end
|
116
130
|
|
117
131
|
# @private
|
118
132
|
def reset
|
119
|
-
method_doubles.
|
133
|
+
@method_doubles.each_value {|d| d.reset}
|
120
134
|
@messages_received.clear
|
121
135
|
end
|
122
136
|
|
@@ -127,11 +141,12 @@ module RSpec
|
|
127
141
|
|
128
142
|
# @private
|
129
143
|
def has_negative_expectation?(message)
|
130
|
-
|
144
|
+
method_double_for(message).expectations.detect {|expectation| expectation.negative_expectation_for?(message)}
|
131
145
|
end
|
132
146
|
|
133
147
|
# @private
|
134
148
|
def record_message_received(message, *args, &block)
|
149
|
+
@order_group.invoked SpecificMessage.new(object, message)
|
135
150
|
@messages_received << [message, args, block]
|
136
151
|
end
|
137
152
|
|
@@ -155,7 +170,7 @@ module RSpec
|
|
155
170
|
elsif stub = find_almost_matching_stub(message, *args)
|
156
171
|
stub.advise(*args)
|
157
172
|
raise_missing_default_stub_error(stub, *args)
|
158
|
-
elsif @object
|
173
|
+
elsif Class === @object
|
159
174
|
@object.superclass.__send__(message, *args, &block)
|
160
175
|
else
|
161
176
|
@object.__send__(:method_missing, message, *args, &block)
|
@@ -179,12 +194,8 @@ module RSpec
|
|
179
194
|
|
180
195
|
private
|
181
196
|
|
182
|
-
def
|
183
|
-
@
|
184
|
-
end
|
185
|
-
|
186
|
-
def method_doubles
|
187
|
-
method_double.values
|
197
|
+
def method_double_for(message)
|
198
|
+
@method_doubles[message.to_sym]
|
188
199
|
end
|
189
200
|
|
190
201
|
def find_matching_expectation(method_name, *args)
|
@@ -202,7 +213,7 @@ module RSpec
|
|
202
213
|
def find_best_matching_expectation_for(method_name)
|
203
214
|
first_match = nil
|
204
215
|
|
205
|
-
|
216
|
+
method_double_for(method_name).expectations.each do |expectation|
|
206
217
|
next unless yield expectation
|
207
218
|
return expectation unless expectation.called_max_times?
|
208
219
|
first_match ||= expectation
|
@@ -212,19 +223,47 @@ module RSpec
|
|
212
223
|
end
|
213
224
|
|
214
225
|
def find_matching_method_stub(method_name, *args)
|
215
|
-
|
226
|
+
method_double_for(method_name).stubs.find {|stub| stub.matches?(method_name, *args)}
|
216
227
|
end
|
217
228
|
|
218
229
|
def find_almost_matching_stub(method_name, *args)
|
219
|
-
|
230
|
+
method_double_for(method_name).stubs.find {|stub| stub.matches_name_but_not_args(method_name, *args)}
|
220
231
|
end
|
221
232
|
end
|
222
233
|
|
223
|
-
class
|
224
|
-
def
|
225
|
-
object.
|
234
|
+
class PartialMockProxy < Proxy
|
235
|
+
def method_handle_for(message)
|
236
|
+
if any_instance_class_recorder_observing_method?(@object.class, message)
|
237
|
+
message = ::RSpec::Mocks.
|
238
|
+
any_instance_recorder_for(@object.class).
|
239
|
+
build_alias_method_name(message)
|
240
|
+
end
|
241
|
+
|
242
|
+
::RSpec::Mocks.method_handle_for(@object, message)
|
243
|
+
rescue NameError
|
244
|
+
nil
|
245
|
+
end
|
246
|
+
|
247
|
+
# @private
|
248
|
+
def add_simple_expectation(method_name, response, location)
|
249
|
+
method_double_for(method_name).configure_method
|
226
250
|
super
|
227
251
|
end
|
252
|
+
|
253
|
+
# @private
|
254
|
+
def add_simple_stub(method_name, response)
|
255
|
+
method_double_for(method_name).configure_method
|
256
|
+
super
|
257
|
+
end
|
258
|
+
|
259
|
+
private
|
260
|
+
|
261
|
+
def any_instance_class_recorder_observing_method?(klass, method_name)
|
262
|
+
return true if ::RSpec::Mocks.any_instance_recorder_for(klass).already_observing?(method_name)
|
263
|
+
superklass = klass.superclass
|
264
|
+
return false if superklass.nil?
|
265
|
+
any_instance_class_recorder_observing_method?(superklass, method_name)
|
266
|
+
end
|
228
267
|
end
|
229
268
|
end
|
230
269
|
end
|
@@ -3,9 +3,9 @@ module RSpec
|
|
3
3
|
# @private
|
4
4
|
class ProxyForNil < Proxy
|
5
5
|
|
6
|
-
def initialize
|
6
|
+
def initialize(order_group)
|
7
7
|
@warn_about_expectations = true
|
8
|
-
super nil
|
8
|
+
super nil, order_group
|
9
9
|
end
|
10
10
|
attr_accessor :warn_about_expectations
|
11
11
|
alias warn_about_expectations? warn_about_expectations
|
data/lib/rspec/mocks/space.rb
CHANGED
@@ -2,13 +2,11 @@ module RSpec
|
|
2
2
|
module Mocks
|
3
3
|
# @api private
|
4
4
|
class Space
|
5
|
-
attr_reader
|
6
|
-
attr_accessor :outside_example
|
5
|
+
attr_reader :proxies, :any_instance_recorders
|
7
6
|
|
8
7
|
def initialize
|
9
8
|
@proxies = {}
|
10
9
|
@any_instance_recorders = {}
|
11
|
-
self.outside_example = true
|
12
10
|
end
|
13
11
|
|
14
12
|
def verify_all
|
@@ -29,11 +27,6 @@ module RSpec
|
|
29
27
|
end
|
30
28
|
|
31
29
|
proxies.clear
|
32
|
-
|
33
|
-
any_instance_recorders.each_value do |recorder|
|
34
|
-
recorder.stop_all_observation!
|
35
|
-
end
|
36
|
-
|
37
30
|
any_instance_recorders.clear
|
38
31
|
expectation_ordering.clear
|
39
32
|
end
|
@@ -43,26 +36,32 @@ module RSpec
|
|
43
36
|
end
|
44
37
|
|
45
38
|
def any_instance_recorder_for(klass)
|
46
|
-
print_out_of_example_deprecation if outside_example
|
47
39
|
id = klass.__id__
|
48
40
|
any_instance_recorders.fetch(id) do
|
49
41
|
any_instance_recorders[id] = AnyInstance::Recorder.new(klass)
|
50
42
|
end
|
51
43
|
end
|
52
44
|
|
45
|
+
def remove_any_instance_recorder_for(klass)
|
46
|
+
any_instance_recorders.delete(klass.__id__)
|
47
|
+
end
|
48
|
+
|
53
49
|
def proxies_of(klass)
|
54
50
|
proxies.values.select { |proxy| klass === proxy.object }
|
55
51
|
end
|
56
52
|
|
57
53
|
def proxy_for(object)
|
58
|
-
print_out_of_example_deprecation if outside_example
|
59
54
|
id = id_for(object)
|
60
55
|
proxies.fetch(id) do
|
61
56
|
proxies[id] = case object
|
62
|
-
when NilClass then ProxyForNil.new
|
63
|
-
when TestDouble then object.__build_mock_proxy
|
57
|
+
when NilClass then ProxyForNil.new(expectation_ordering)
|
58
|
+
when TestDouble then object.__build_mock_proxy(expectation_ordering)
|
64
59
|
else
|
65
|
-
|
60
|
+
if RSpec::Mocks.configuration.verify_partial_doubles?
|
61
|
+
VerifyingPartialMockProxy.new(object, expectation_ordering)
|
62
|
+
else
|
63
|
+
PartialMockProxy.new(object, expectation_ordering)
|
64
|
+
end
|
66
65
|
end
|
67
66
|
end
|
68
67
|
end
|
@@ -73,10 +72,6 @@ module RSpec
|
|
73
72
|
proxies.has_key?(id_for object)
|
74
73
|
end
|
75
74
|
|
76
|
-
def print_out_of_example_deprecation
|
77
|
-
RSpec.deprecate("Using rspec-mocks doubles or partial doubles outside the per-test lifecycle (such as in a `before(:all)` hook)")
|
78
|
-
end
|
79
|
-
|
80
75
|
if defined?(::BasicObject) && !::BasicObject.method_defined?(:__id__) # for 1.9.2
|
81
76
|
require 'securerandom'
|
82
77
|
|
@@ -86,7 +81,7 @@ module RSpec
|
|
86
81
|
return id if object.equal?(::ObjectSpace._id2ref(id))
|
87
82
|
# this suggests that object.__id__ is proxying through to some wrapped object
|
88
83
|
|
89
|
-
object.
|
84
|
+
object.instance_exec do
|
90
85
|
@__id_for_rspec_mocks_space ||= ::SecureRandom.uuid
|
91
86
|
end
|
92
87
|
end
|