rspec-mocks 2.11.3 → 2.12.0
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.
- data/Changelog.md +16 -0
- data/README.md +26 -1
- data/features/argument_matchers/explicit.feature +2 -2
- data/features/argument_matchers/general_matchers.feature +4 -4
- data/features/argument_matchers/type_matchers.feature +1 -1
- data/features/message_expectations/README.md +4 -0
- data/features/message_expectations/any_instance.feature +1 -1
- data/features/message_expectations/call_original.feature +24 -0
- data/features/message_expectations/expect_message.feature +5 -5
- 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/any_instance.feature +6 -7
- data/features/method_stubs/as_null_object.feature +1 -1
- data/features/method_stubs/simple_return_value.feature +2 -2
- data/features/method_stubs/stub_chain.feature +1 -1
- data/features/method_stubs/stub_implementation.feature +1 -1
- data/features/method_stubs/to_ary.feature +1 -1
- data/features/{stubbing_constants → mutating_constants}/README.md +21 -1
- data/features/mutating_constants/hiding_defined_constant.feature +64 -0
- data/features/{stubbing_constants → mutating_constants}/stub_defined_constant.feature +0 -0
- data/features/{stubbing_constants → mutating_constants}/stub_undefined_constant.feature +0 -0
- data/features/outside_rspec/configuration.feature +3 -3
- data/features/outside_rspec/standalone.feature +6 -5
- data/lib/rspec/mocks.rb +17 -1
- data/lib/rspec/mocks/any_instance.rb +12 -12
- data/lib/rspec/mocks/configuration.rb +28 -0
- data/lib/rspec/mocks/error_generator.rb +6 -0
- data/lib/rspec/mocks/example_methods.rb +34 -9
- data/lib/rspec/mocks/framework.rb +3 -2
- data/lib/rspec/mocks/instance_method_stasher.rb +70 -0
- data/lib/rspec/mocks/message_expectation.rb +49 -29
- data/lib/rspec/mocks/method_double.rb +84 -7
- data/lib/rspec/mocks/{stub_const.rb → mutate_const.rb} +117 -40
- data/lib/rspec/mocks/proxy.rb +16 -5
- data/lib/rspec/mocks/version.rb +1 -1
- data/spec/rspec/mocks/and_call_original_spec.rb +162 -0
- data/spec/rspec/mocks/any_instance_spec.rb +18 -7
- data/spec/rspec/mocks/configuration_spec.rb +26 -0
- data/spec/rspec/mocks/failing_argument_matchers_spec.rb +9 -10
- data/spec/rspec/mocks/instance_method_stasher_spec.rb +58 -0
- data/spec/rspec/mocks/mock_spec.rb +35 -35
- data/spec/rspec/mocks/{stub_const_spec.rb → mutate_const_spec.rb} +142 -13
- data/spec/rspec/mocks/null_object_mock_spec.rb +3 -2
- data/spec/rspec/mocks/partial_mock_spec.rb +102 -77
- data/spec/rspec/mocks/serialization_spec.rb +1 -2
- data/spec/rspec/mocks/stub_implementation_spec.rb +6 -6
- data/spec/rspec/mocks_spec.rb +7 -0
- data/spec/spec_helper.rb +11 -0
- metadata +79 -80
- data/lib/rspec/mocks/stashed_instance_method.rb +0 -60
- data/spec/rspec/mocks/stashed_instance_method_spec.rb +0 -53
@@ -28,7 +28,7 @@ module RSpec
|
|
28
28
|
context 'without YAML loaded' do
|
29
29
|
before do
|
30
30
|
# We can't really unload yaml, but we can fake it here...
|
31
|
-
|
31
|
+
hide_const("YAML")
|
32
32
|
Struct.class_eval do
|
33
33
|
alias __old_to_yaml to_yaml
|
34
34
|
undef to_yaml
|
@@ -38,7 +38,6 @@ module RSpec
|
|
38
38
|
module_eval(&block)
|
39
39
|
|
40
40
|
after do
|
41
|
-
Object.const_set(:YAML, @orig_yaml_constant)
|
42
41
|
Struct.class_eval do
|
43
42
|
alias to_yaml __old_to_yaml
|
44
43
|
undef __old_to_yaml
|
@@ -24,12 +24,12 @@ module RSpec
|
|
24
24
|
obj = stub()
|
25
25
|
obj.stub(:foo) {|*given| given.first}
|
26
26
|
obj.foo(:bar).should eq :bar
|
27
|
-
end
|
27
|
+
end
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
|
32
|
-
describe "unstub implementation" do
|
31
|
+
|
32
|
+
describe "unstub implementation" do
|
33
33
|
it "replaces the stubbed method with the original method" do
|
34
34
|
obj = Object.new
|
35
35
|
def obj.foo; :original; end
|
@@ -37,7 +37,7 @@ module RSpec
|
|
37
37
|
obj.unstub(:foo)
|
38
38
|
obj.foo.should eq :original
|
39
39
|
end
|
40
|
-
|
40
|
+
|
41
41
|
it "removes all stubs with the supplied method name" do
|
42
42
|
obj = Object.new
|
43
43
|
def obj.foo; :original; end
|
@@ -46,7 +46,7 @@ module RSpec
|
|
46
46
|
obj.unstub(:foo)
|
47
47
|
obj.foo.should eq :original
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
it "does not remove any expectations with the same method name" do
|
51
51
|
obj = Object.new
|
52
52
|
def obj.foo; :original; end
|
@@ -69,7 +69,7 @@ module RSpec
|
|
69
69
|
parent.new.should be_an_instance_of parent
|
70
70
|
child.new.should be_an_instance_of child
|
71
71
|
end
|
72
|
-
|
72
|
+
|
73
73
|
it "raises a MockExpectationError if the method has not been stubbed" do
|
74
74
|
obj = Object.new
|
75
75
|
lambda do
|
data/spec/rspec/mocks_spec.rb
CHANGED
@@ -48,4 +48,11 @@ describe RSpec::Mocks do
|
|
48
48
|
end.to raise_error(/received unexpected message/)
|
49
49
|
end
|
50
50
|
end
|
51
|
+
|
52
|
+
describe ".configuration" do
|
53
|
+
it 'returns a memoized configuration instance' do
|
54
|
+
RSpec::Mocks.configuration.should be_a(RSpec::Mocks::Configuration)
|
55
|
+
RSpec::Mocks.configuration.should be(RSpec::Mocks.configuration)
|
56
|
+
end
|
57
|
+
end
|
51
58
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -18,4 +18,15 @@ RSpec.configure do |config|
|
|
18
18
|
config.run_all_when_everything_filtered = true
|
19
19
|
config.treat_symbols_as_metadata_keys_with_true_values = true
|
20
20
|
config.filter_run_including :focus
|
21
|
+
|
22
|
+
old_verbose = nil
|
23
|
+
config.before(:each, :silence_warnings) do
|
24
|
+
old_verbose = $VERBOSE
|
25
|
+
$VERBOSE = nil
|
26
|
+
end
|
27
|
+
|
28
|
+
config.after(:each, :silence_warnings) do
|
29
|
+
$VERBOSE = old_verbose
|
30
|
+
end
|
21
31
|
end
|
32
|
+
|
metadata
CHANGED
@@ -1,80 +1,71 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-mocks
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.12.0
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 2
|
8
|
-
- 11
|
9
|
-
- 3
|
10
|
-
version: 2.11.3
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Steven Baker
|
14
9
|
- David Chelimsky
|
15
10
|
autorequire:
|
16
11
|
bindir: bin
|
17
12
|
cert_chain: []
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
- !ruby/object:Gem::Dependency
|
13
|
+
date: 2012-11-13 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
22
16
|
name: rake
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 10.0.0
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements:
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
27
|
-
requirements:
|
27
|
+
requirements:
|
28
28
|
- - ~>
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
|
31
|
-
|
32
|
-
- 0
|
33
|
-
- 9
|
34
|
-
- 2
|
35
|
-
version: 0.9.2
|
36
|
-
requirement: *id001
|
37
|
-
- !ruby/object:Gem::Dependency
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
version: 10.0.0
|
31
|
+
- !ruby/object:Gem::Dependency
|
38
32
|
name: cucumber
|
33
|
+
requirement: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ~>
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: 1.1.9
|
39
39
|
type: :development
|
40
40
|
prerelease: false
|
41
|
-
version_requirements:
|
41
|
+
version_requirements: !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
|
-
requirements:
|
43
|
+
requirements:
|
44
44
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
hash: 1
|
47
|
-
segments:
|
48
|
-
- 1
|
49
|
-
- 1
|
50
|
-
- 9
|
45
|
+
- !ruby/object:Gem::Version
|
51
46
|
version: 1.1.9
|
52
|
-
|
53
|
-
- !ruby/object:Gem::Dependency
|
47
|
+
- !ruby/object:Gem::Dependency
|
54
48
|
name: aruba
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.4.11
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements:
|
57
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
58
|
none: false
|
59
|
-
requirements:
|
59
|
+
requirements:
|
60
60
|
- - ~>
|
61
|
-
- !ruby/object:Gem::Version
|
62
|
-
hash: 25
|
63
|
-
segments:
|
64
|
-
- 0
|
65
|
-
- 4
|
66
|
-
- 11
|
61
|
+
- !ruby/object:Gem::Version
|
67
62
|
version: 0.4.11
|
68
|
-
requirement: *id003
|
69
63
|
description: RSpec's 'test double' framework, with support for stubbing and mocking
|
70
64
|
email: rspec-users@rubyforge.org
|
71
65
|
executables: []
|
72
|
-
|
73
66
|
extensions: []
|
74
|
-
|
75
67
|
extra_rdoc_files: []
|
76
|
-
|
77
|
-
files:
|
68
|
+
files:
|
78
69
|
- lib/rspec/mocks.rb
|
79
70
|
- lib/rspec/mocks/any_instance.rb
|
80
71
|
- lib/rspec/mocks/any_instance/chain.rb
|
@@ -85,6 +76,7 @@ files:
|
|
85
76
|
- lib/rspec/mocks/any_instance/stub_chain_chain.rb
|
86
77
|
- lib/rspec/mocks/argument_list_matcher.rb
|
87
78
|
- lib/rspec/mocks/argument_matchers.rb
|
79
|
+
- lib/rspec/mocks/configuration.rb
|
88
80
|
- lib/rspec/mocks/error_generator.rb
|
89
81
|
- lib/rspec/mocks/errors.rb
|
90
82
|
- lib/rspec/mocks/example_methods.rb
|
@@ -92,17 +84,17 @@ files:
|
|
92
84
|
- lib/rspec/mocks/extensions/marshal.rb
|
93
85
|
- lib/rspec/mocks/extensions/psych.rb
|
94
86
|
- lib/rspec/mocks/framework.rb
|
87
|
+
- lib/rspec/mocks/instance_method_stasher.rb
|
95
88
|
- lib/rspec/mocks/message_expectation.rb
|
96
89
|
- lib/rspec/mocks/method_double.rb
|
97
90
|
- lib/rspec/mocks/methods.rb
|
98
91
|
- lib/rspec/mocks/mock.rb
|
92
|
+
- lib/rspec/mocks/mutate_const.rb
|
99
93
|
- lib/rspec/mocks/order_group.rb
|
100
94
|
- lib/rspec/mocks/proxy.rb
|
101
95
|
- lib/rspec/mocks/serialization.rb
|
102
96
|
- lib/rspec/mocks/space.rb
|
103
97
|
- lib/rspec/mocks/standalone.rb
|
104
|
-
- lib/rspec/mocks/stashed_instance_method.rb
|
105
|
-
- lib/rspec/mocks/stub_const.rb
|
106
98
|
- lib/rspec/mocks/test_double.rb
|
107
99
|
- lib/rspec/mocks/version.rb
|
108
100
|
- lib/spec/mocks.rb
|
@@ -121,6 +113,7 @@ files:
|
|
121
113
|
- features/message_expectations/README.md
|
122
114
|
- features/message_expectations/any_instance.feature
|
123
115
|
- features/message_expectations/block_local_expectations.feature.pending
|
116
|
+
- features/message_expectations/call_original.feature
|
124
117
|
- features/message_expectations/expect_message.feature
|
125
118
|
- features/message_expectations/receive_counts.feature
|
126
119
|
- features/message_expectations/warn_when_expectation_is_set_on_nil.feature
|
@@ -131,13 +124,15 @@ files:
|
|
131
124
|
- features/method_stubs/stub_chain.feature
|
132
125
|
- features/method_stubs/stub_implementation.feature
|
133
126
|
- features/method_stubs/to_ary.feature
|
127
|
+
- features/mutating_constants/README.md
|
128
|
+
- features/mutating_constants/hiding_defined_constant.feature
|
129
|
+
- features/mutating_constants/stub_defined_constant.feature
|
130
|
+
- features/mutating_constants/stub_undefined_constant.feature
|
134
131
|
- features/outside_rspec/configuration.feature
|
135
132
|
- features/outside_rspec/standalone.feature
|
136
133
|
- features/step_definitions/additional_cli_steps.rb
|
137
|
-
- features/stubbing_constants/README.md
|
138
|
-
- features/stubbing_constants/stub_defined_constant.feature
|
139
|
-
- features/stubbing_constants/stub_undefined_constant.feature
|
140
134
|
- features/support/env.rb
|
135
|
+
- spec/rspec/mocks/and_call_original_spec.rb
|
141
136
|
- spec/rspec/mocks/and_yield_spec.rb
|
142
137
|
- spec/rspec/mocks/any_instance/message_chains_spec.rb
|
143
138
|
- spec/rspec/mocks/any_instance_spec.rb
|
@@ -155,14 +150,17 @@ files:
|
|
155
150
|
- spec/rspec/mocks/bug_report_8165_spec.rb
|
156
151
|
- spec/rspec/mocks/bug_report_830_spec.rb
|
157
152
|
- spec/rspec/mocks/bug_report_957_spec.rb
|
153
|
+
- spec/rspec/mocks/configuration_spec.rb
|
158
154
|
- spec/rspec/mocks/double_spec.rb
|
159
155
|
- spec/rspec/mocks/failing_argument_matchers_spec.rb
|
160
156
|
- spec/rspec/mocks/hash_excluding_matcher_spec.rb
|
161
157
|
- spec/rspec/mocks/hash_including_matcher_spec.rb
|
158
|
+
- spec/rspec/mocks/instance_method_stasher_spec.rb
|
162
159
|
- spec/rspec/mocks/mock_ordering_spec.rb
|
163
160
|
- spec/rspec/mocks/mock_space_spec.rb
|
164
161
|
- spec/rspec/mocks/mock_spec.rb
|
165
162
|
- spec/rspec/mocks/multiple_return_value_spec.rb
|
163
|
+
- spec/rspec/mocks/mutate_const_spec.rb
|
166
164
|
- spec/rspec/mocks/nil_expectation_warning_spec.rb
|
167
165
|
- spec/rspec/mocks/null_object_mock_spec.rb
|
168
166
|
- spec/rspec/mocks/once_counts_spec.rb
|
@@ -174,9 +172,7 @@ files:
|
|
174
172
|
- spec/rspec/mocks/record_messages_spec.rb
|
175
173
|
- spec/rspec/mocks/serialization_spec.rb
|
176
174
|
- spec/rspec/mocks/stash_spec.rb
|
177
|
-
- spec/rspec/mocks/stashed_instance_method_spec.rb
|
178
175
|
- spec/rspec/mocks/stub_chain_spec.rb
|
179
|
-
- spec/rspec/mocks/stub_const_spec.rb
|
180
176
|
- spec/rspec/mocks/stub_implementation_spec.rb
|
181
177
|
- spec/rspec/mocks/stub_spec.rb
|
182
178
|
- spec/rspec/mocks/stubbed_message_expectations_spec.rb
|
@@ -186,39 +182,38 @@ files:
|
|
186
182
|
- spec/rspec/mocks_spec.rb
|
187
183
|
- spec/spec_helper.rb
|
188
184
|
homepage: http://github.com/rspec/rspec-mocks
|
189
|
-
licenses:
|
185
|
+
licenses:
|
190
186
|
- MIT
|
191
187
|
post_install_message:
|
192
|
-
rdoc_options:
|
188
|
+
rdoc_options:
|
193
189
|
- --charset=UTF-8
|
194
|
-
require_paths:
|
190
|
+
require_paths:
|
195
191
|
- lib
|
196
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
192
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
197
193
|
none: false
|
198
|
-
requirements:
|
199
|
-
- -
|
200
|
-
- !ruby/object:Gem::Version
|
201
|
-
|
202
|
-
segments:
|
194
|
+
requirements:
|
195
|
+
- - ! '>='
|
196
|
+
- !ruby/object:Gem::Version
|
197
|
+
version: '0'
|
198
|
+
segments:
|
203
199
|
- 0
|
204
|
-
|
205
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
200
|
+
hash: -450868354806899778
|
201
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
206
202
|
none: false
|
207
|
-
requirements:
|
208
|
-
- -
|
209
|
-
- !ruby/object:Gem::Version
|
210
|
-
|
211
|
-
segments:
|
203
|
+
requirements:
|
204
|
+
- - ! '>='
|
205
|
+
- !ruby/object:Gem::Version
|
206
|
+
version: '0'
|
207
|
+
segments:
|
212
208
|
- 0
|
213
|
-
|
209
|
+
hash: -450868354806899778
|
214
210
|
requirements: []
|
215
|
-
|
216
211
|
rubyforge_project: rspec
|
217
|
-
rubygems_version: 1.8.
|
212
|
+
rubygems_version: 1.8.24
|
218
213
|
signing_key:
|
219
214
|
specification_version: 3
|
220
|
-
summary: rspec-mocks-2.
|
221
|
-
test_files:
|
215
|
+
summary: rspec-mocks-2.12.0
|
216
|
+
test_files:
|
222
217
|
- features/README.md
|
223
218
|
- features/Scope.md
|
224
219
|
- features/Upgrade.md
|
@@ -229,6 +224,7 @@ test_files:
|
|
229
224
|
- features/message_expectations/README.md
|
230
225
|
- features/message_expectations/any_instance.feature
|
231
226
|
- features/message_expectations/block_local_expectations.feature.pending
|
227
|
+
- features/message_expectations/call_original.feature
|
232
228
|
- features/message_expectations/expect_message.feature
|
233
229
|
- features/message_expectations/receive_counts.feature
|
234
230
|
- features/message_expectations/warn_when_expectation_is_set_on_nil.feature
|
@@ -239,13 +235,15 @@ test_files:
|
|
239
235
|
- features/method_stubs/stub_chain.feature
|
240
236
|
- features/method_stubs/stub_implementation.feature
|
241
237
|
- features/method_stubs/to_ary.feature
|
238
|
+
- features/mutating_constants/README.md
|
239
|
+
- features/mutating_constants/hiding_defined_constant.feature
|
240
|
+
- features/mutating_constants/stub_defined_constant.feature
|
241
|
+
- features/mutating_constants/stub_undefined_constant.feature
|
242
242
|
- features/outside_rspec/configuration.feature
|
243
243
|
- features/outside_rspec/standalone.feature
|
244
244
|
- features/step_definitions/additional_cli_steps.rb
|
245
|
-
- features/stubbing_constants/README.md
|
246
|
-
- features/stubbing_constants/stub_defined_constant.feature
|
247
|
-
- features/stubbing_constants/stub_undefined_constant.feature
|
248
245
|
- features/support/env.rb
|
246
|
+
- spec/rspec/mocks/and_call_original_spec.rb
|
249
247
|
- spec/rspec/mocks/and_yield_spec.rb
|
250
248
|
- spec/rspec/mocks/any_instance/message_chains_spec.rb
|
251
249
|
- spec/rspec/mocks/any_instance_spec.rb
|
@@ -263,14 +261,17 @@ test_files:
|
|
263
261
|
- spec/rspec/mocks/bug_report_8165_spec.rb
|
264
262
|
- spec/rspec/mocks/bug_report_830_spec.rb
|
265
263
|
- spec/rspec/mocks/bug_report_957_spec.rb
|
264
|
+
- spec/rspec/mocks/configuration_spec.rb
|
266
265
|
- spec/rspec/mocks/double_spec.rb
|
267
266
|
- spec/rspec/mocks/failing_argument_matchers_spec.rb
|
268
267
|
- spec/rspec/mocks/hash_excluding_matcher_spec.rb
|
269
268
|
- spec/rspec/mocks/hash_including_matcher_spec.rb
|
269
|
+
- spec/rspec/mocks/instance_method_stasher_spec.rb
|
270
270
|
- spec/rspec/mocks/mock_ordering_spec.rb
|
271
271
|
- spec/rspec/mocks/mock_space_spec.rb
|
272
272
|
- spec/rspec/mocks/mock_spec.rb
|
273
273
|
- spec/rspec/mocks/multiple_return_value_spec.rb
|
274
|
+
- spec/rspec/mocks/mutate_const_spec.rb
|
274
275
|
- spec/rspec/mocks/nil_expectation_warning_spec.rb
|
275
276
|
- spec/rspec/mocks/null_object_mock_spec.rb
|
276
277
|
- spec/rspec/mocks/once_counts_spec.rb
|
@@ -282,9 +283,7 @@ test_files:
|
|
282
283
|
- spec/rspec/mocks/record_messages_spec.rb
|
283
284
|
- spec/rspec/mocks/serialization_spec.rb
|
284
285
|
- spec/rspec/mocks/stash_spec.rb
|
285
|
-
- spec/rspec/mocks/stashed_instance_method_spec.rb
|
286
286
|
- spec/rspec/mocks/stub_chain_spec.rb
|
287
|
-
- spec/rspec/mocks/stub_const_spec.rb
|
288
287
|
- spec/rspec/mocks/stub_implementation_spec.rb
|
289
288
|
- spec/rspec/mocks/stub_spec.rb
|
290
289
|
- spec/rspec/mocks/stubbed_message_expectations_spec.rb
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# @private
|
2
|
-
class StashedInstanceMethod
|
3
|
-
def initialize(klass, method)
|
4
|
-
@klass = klass
|
5
|
-
@method = method
|
6
|
-
|
7
|
-
@method_is_stashed = false
|
8
|
-
end
|
9
|
-
|
10
|
-
# @private
|
11
|
-
def stash
|
12
|
-
return if !method_defined_directly_on_klass? || @method_is_stashed
|
13
|
-
|
14
|
-
@klass.__send__(:alias_method, stashed_method_name, @method)
|
15
|
-
@method_is_stashed = true
|
16
|
-
end
|
17
|
-
|
18
|
-
private
|
19
|
-
|
20
|
-
# @private
|
21
|
-
def method_defined_directly_on_klass?
|
22
|
-
method_defined_on_klass? && method_owned_by_klass?
|
23
|
-
end
|
24
|
-
|
25
|
-
# @private
|
26
|
-
def method_defined_on_klass?
|
27
|
-
@klass.method_defined?(@method) || @klass.private_method_defined?(@method)
|
28
|
-
end
|
29
|
-
|
30
|
-
if ::UnboundMethod.method_defined?(:owner)
|
31
|
-
# @private
|
32
|
-
def method_owned_by_klass?
|
33
|
-
@klass.instance_method(@method).owner == @klass
|
34
|
-
end
|
35
|
-
else
|
36
|
-
# @private
|
37
|
-
def method_owned_by_klass?
|
38
|
-
# On 1.8.6, which does not support Method#owner, we have no choice but
|
39
|
-
# to assume it's defined on the klass even if it may be defined on
|
40
|
-
# a superclass.
|
41
|
-
true
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
# @private
|
46
|
-
def stashed_method_name
|
47
|
-
"obfuscated_by_rspec_mocks__#{@method}"
|
48
|
-
end
|
49
|
-
|
50
|
-
public
|
51
|
-
|
52
|
-
# @private
|
53
|
-
def restore
|
54
|
-
return unless @method_is_stashed
|
55
|
-
|
56
|
-
@klass.__send__(:alias_method, @method, stashed_method_name)
|
57
|
-
@klass.__send__(:remove_method, stashed_method_name)
|
58
|
-
@method_is_stashed = false
|
59
|
-
end
|
60
|
-
end
|