rspec-mocks 2.11.2 → 2.11.3
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 +14 -0
- data/README.md +1 -1
- data/lib/rspec/mocks/any_instance/recorder.rb +2 -2
- data/lib/rspec/mocks/framework.rb +1 -0
- data/lib/rspec/mocks/method_double.rb +22 -54
- data/lib/rspec/mocks/methods.rb +1 -1
- data/lib/rspec/mocks/proxy.rb +5 -1
- data/lib/rspec/mocks/stashed_instance_method.rb +60 -0
- data/lib/rspec/mocks/stub_const.rb +24 -11
- data/lib/rspec/mocks/version.rb +1 -1
- data/spec/rspec/mocks/any_instance_spec.rb +27 -0
- data/spec/rspec/mocks/partial_mock_spec.rb +15 -0
- data/spec/rspec/mocks/serialization_spec.rb +3 -3
- data/spec/rspec/mocks/stashed_instance_method_spec.rb +53 -0
- data/spec/rspec/mocks/stub_chain_spec.rb +5 -0
- data/spec/rspec/mocks/stub_const_spec.rb +22 -0
- data/spec/rspec/mocks/stub_implementation_spec.rb +13 -0
- data/spec/rspec/mocks/stub_spec.rb +9 -0
- data/spec/spec_helper.rb +6 -0
- metadata +70 -57
data/Changelog.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
### 2.11.3 / 2012-09-19
|
2
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.11.2...v2.11.3)
|
3
|
+
|
4
|
+
Bug fixes
|
5
|
+
|
6
|
+
* Fix `:transfer_nested_constants` option of `stub_const` so that it
|
7
|
+
doesn't blow up when there are inherited constants. (Myron Marston)
|
8
|
+
* `any_instance` stubs can be used on classes that override `Object#method`.
|
9
|
+
(Andy Lindeman)
|
10
|
+
* Methods stubbed with `any_instance` are unstubbed after the test finishes.
|
11
|
+
(Andy Lindeman)
|
12
|
+
* Fix confusing error message when calling a mocked class method an
|
13
|
+
extra time with the wrong arguments (Myron Marston).
|
14
|
+
|
1
15
|
### 2.11.2 / 2012-08-11
|
2
16
|
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.11.1...v2.11.2)
|
3
17
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# RSpec Mocks [](https://codeclimate.com/github/rspec/rspec-mocks)
|
1
|
+
# RSpec Mocks [](http://travis-ci.org/rspec/rspec-mocks) [](https://codeclimate.com/github/rspec/rspec-mocks)
|
2
2
|
|
3
3
|
rspec-mocks is a test-double framework for rspec with support for method stubs,
|
4
4
|
fakes, and message expectations on generated test-doubles and real objects
|
@@ -175,7 +175,7 @@ module RSpec
|
|
175
175
|
backup_method!(method_name)
|
176
176
|
@klass.class_eval(<<-EOM, __FILE__, __LINE__)
|
177
177
|
def #{method_name}(*args, &blk)
|
178
|
-
klass =
|
178
|
+
klass = ::Object.instance_method(:method).bind(self).call(:#{method_name}).owner
|
179
179
|
klass.__recorder.playback!(self, :#{method_name})
|
180
180
|
self.__send__(:#{method_name}, *args, &blk)
|
181
181
|
end
|
@@ -187,7 +187,7 @@ module RSpec
|
|
187
187
|
@klass.class_eval(<<-EOM, __FILE__, __LINE__)
|
188
188
|
def #{method_name}(*args, &blk)
|
189
189
|
method_name = :#{method_name}
|
190
|
-
klass =
|
190
|
+
klass = ::Object.instance_method(:method).bind(self).call(:#{method_name}).owner
|
191
191
|
invoked_instance = klass.__recorder.instance_that_received(method_name)
|
192
192
|
raise RSpec::Mocks::MockExpectationError, "The message '#{method_name}' was received by \#{self.inspect} but has already been received by \#{invoked_instance}"
|
193
193
|
end
|
@@ -10,7 +10,9 @@ module RSpec
|
|
10
10
|
@method_name = method_name
|
11
11
|
@object = object
|
12
12
|
@proxy = proxy
|
13
|
-
|
13
|
+
|
14
|
+
@stashed_method = StashedInstanceMethod.new(object_singleton_class, @method_name)
|
15
|
+
@method_is_proxied = false
|
14
16
|
store(:expectations, [])
|
15
17
|
store(:stubs, [])
|
16
18
|
end
|
@@ -43,73 +45,39 @@ module RSpec
|
|
43
45
|
class << @object; self; end
|
44
46
|
end
|
45
47
|
|
46
|
-
# @private
|
47
|
-
def obfuscate(method_name)
|
48
|
-
"obfuscated_by_rspec_mocks__#{method_name}"
|
49
|
-
end
|
50
|
-
|
51
|
-
# @private
|
52
|
-
def stashed_method_name
|
53
|
-
obfuscate(method_name)
|
54
|
-
end
|
55
|
-
|
56
|
-
# @private
|
57
|
-
def object_responds_to?(method_name)
|
58
|
-
if @proxy.already_proxied_respond_to?
|
59
|
-
@object.__send__(obfuscate(:respond_to?), method_name)
|
60
|
-
elsif method_name == :respond_to?
|
61
|
-
@proxy.already_proxied_respond_to
|
62
|
-
else
|
63
|
-
@object.respond_to?(method_name, true)
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
48
|
# @private
|
68
49
|
def configure_method
|
69
50
|
RSpec::Mocks::space.add(@object) if RSpec::Mocks::space
|
70
51
|
warn_if_nil_class
|
71
|
-
unless @
|
72
|
-
|
73
|
-
define_proxy_method
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
# @private
|
78
|
-
def stash_original_method
|
79
|
-
stashed = stashed_method_name
|
80
|
-
orig = @method_name
|
81
|
-
object_singleton_class.class_eval do
|
82
|
-
alias_method(stashed, orig) if method_defined?(orig) || private_method_defined?(orig)
|
83
|
-
end
|
84
|
-
@stashed = true
|
52
|
+
@stashed_method.stash unless @method_is_proxied
|
53
|
+
define_proxy_method
|
85
54
|
end
|
86
55
|
|
87
56
|
# @private
|
88
57
|
def define_proxy_method
|
89
|
-
|
90
|
-
|
91
|
-
object_singleton_class.class_eval
|
92
|
-
def #{method_name}(*args, &block)
|
93
|
-
__mock_proxy.message_received :#{method_name}, *args, &block
|
58
|
+
return if @method_is_proxied
|
59
|
+
|
60
|
+
object_singleton_class.class_eval <<-EOF, __FILE__, __LINE__ + 1
|
61
|
+
def #{@method_name}(*args, &block)
|
62
|
+
__mock_proxy.message_received :#{@method_name}, *args, &block
|
94
63
|
end
|
95
|
-
|
64
|
+
#{visibility_for_method}
|
96
65
|
EOF
|
66
|
+
@method_is_proxied = true
|
67
|
+
end
|
68
|
+
|
69
|
+
# @private
|
70
|
+
def visibility_for_method
|
71
|
+
"#{visibility} :#{method_name}"
|
97
72
|
end
|
98
73
|
|
99
74
|
# @private
|
100
75
|
def restore_original_method
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
if method_defined?(stashed_method_name) || private_method_defined?(stashed_method_name)
|
107
|
-
alias_method method_name, stashed_method_name
|
108
|
-
remove_method stashed_method_name
|
109
|
-
end
|
110
|
-
end
|
111
|
-
@stashed = false
|
112
|
-
end
|
76
|
+
return unless @method_is_proxied
|
77
|
+
|
78
|
+
object_singleton_class.__send__(:remove_method, @method_name)
|
79
|
+
@stashed_method.restore
|
80
|
+
@method_is_proxied = false
|
113
81
|
end
|
114
82
|
|
115
83
|
# @private
|
data/lib/rspec/mocks/methods.rb
CHANGED
data/lib/rspec/mocks/proxy.rb
CHANGED
@@ -175,7 +175,11 @@ module RSpec
|
|
175
175
|
end
|
176
176
|
|
177
177
|
def find_almost_matching_expectation(method_name, *args)
|
178
|
-
method_double[method_name].expectations.find
|
178
|
+
method_double[method_name].expectations.find do |expectation|
|
179
|
+
expectation.matches_name_but_not_args(method_name, *args) && !expectation.called_max_times?
|
180
|
+
end || method_double[method_name].expectations.find do |expectation|
|
181
|
+
expectation.matches_name_but_not_args(method_name, *args)
|
182
|
+
end
|
179
183
|
end
|
180
184
|
|
181
185
|
def find_matching_method_stub(method_name, *args)
|
@@ -0,0 +1,60 @@
|
|
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
|
@@ -10,17 +10,22 @@ module RSpec
|
|
10
10
|
# we need to conditionally define methods to ignore the top-level/inherited
|
11
11
|
# constants.
|
12
12
|
#
|
13
|
-
# Given
|
13
|
+
# Given:
|
14
|
+
# class A; B = 1; end
|
15
|
+
# class C < A; end
|
14
16
|
#
|
15
17
|
# On 1.8:
|
16
|
-
# -
|
17
|
-
# -
|
18
|
-
# -
|
18
|
+
# - C.const_get("Hash") # => ::Hash
|
19
|
+
# - C.const_defined?("Hash") # => false
|
20
|
+
# - C.constants # => ["A"]
|
21
|
+
# - None of these methods accept the extra `inherit` argument
|
19
22
|
# On 1.9:
|
20
|
-
# -
|
21
|
-
# -
|
22
|
-
# -
|
23
|
-
# -
|
23
|
+
# - C.const_get("Hash") # => ::Hash
|
24
|
+
# - C.const_defined?("Hash") # => true
|
25
|
+
# - C.const_get("Hash", false) # => raises NameError
|
26
|
+
# - C.const_defined?("Hash", false) # => false
|
27
|
+
# - C.constants # => [:A]
|
28
|
+
# - C.constants(false) #=> []
|
24
29
|
if Module.method(:const_defined?).arity == 1
|
25
30
|
def const_defined_on?(mod, const_name)
|
26
31
|
mod.const_defined?(const_name)
|
@@ -33,6 +38,10 @@ module RSpec
|
|
33
38
|
|
34
39
|
raise NameError, "uninitialized constant #{mod.name}::#{const_name}"
|
35
40
|
end
|
41
|
+
|
42
|
+
def constants_defined_on(mod)
|
43
|
+
mod.constants.select { |c| const_defined_on?(mod, c) }
|
44
|
+
end
|
36
45
|
else
|
37
46
|
def const_defined_on?(mod, const_name)
|
38
47
|
mod.const_defined?(const_name, false)
|
@@ -41,6 +50,10 @@ module RSpec
|
|
41
50
|
def get_const_defined_on(mod, const_name)
|
42
51
|
mod.const_get(const_name, false)
|
43
52
|
end
|
53
|
+
|
54
|
+
def constants_defined_on(mod)
|
55
|
+
mod.constants(false)
|
56
|
+
end
|
44
57
|
end
|
45
58
|
|
46
59
|
def recursive_const_get(const_name)
|
@@ -217,10 +230,10 @@ module RSpec
|
|
217
230
|
|
218
231
|
if @transfer_nested_constants.is_a?(Array)
|
219
232
|
@transfer_nested_constants = @transfer_nested_constants.map(&:to_s) if RUBY_VERSION == '1.8.7'
|
220
|
-
undefined_constants = @transfer_nested_constants - @original_value
|
233
|
+
undefined_constants = @transfer_nested_constants - constants_defined_on(@original_value)
|
221
234
|
|
222
235
|
if undefined_constants.any?
|
223
|
-
available_constants = @original_value
|
236
|
+
available_constants = constants_defined_on(@original_value) - @transfer_nested_constants
|
224
237
|
raise ArgumentError,
|
225
238
|
"Cannot transfer nested constant(s) #{undefined_constants.join(' and ')} " +
|
226
239
|
"for #{@full_constant_name} since they are not defined. Did you mean " +
|
@@ -229,7 +242,7 @@ module RSpec
|
|
229
242
|
|
230
243
|
@transfer_nested_constants
|
231
244
|
else
|
232
|
-
@original_value
|
245
|
+
constants_defined_on(@original_value)
|
233
246
|
end
|
234
247
|
end
|
235
248
|
end
|
data/lib/rspec/mocks/version.rb
CHANGED
@@ -845,6 +845,33 @@ module RSpec
|
|
845
845
|
end.to raise_error(RSpec::Mocks::MockExpectationError, "The message 'existing_method' was received by #{instance_two.inspect} but has already been received by #{instance_one.inspect}")
|
846
846
|
end
|
847
847
|
end
|
848
|
+
|
849
|
+
context "when a class overrides Object#method" do
|
850
|
+
let(:http_request_class) { Struct.new(:method, :uri) }
|
851
|
+
|
852
|
+
it "stubs the method correctly" do
|
853
|
+
http_request_class.any_instance.stub(:existing_method).and_return("foo")
|
854
|
+
http_request_class.new.existing_method.should == "foo"
|
855
|
+
end
|
856
|
+
|
857
|
+
it "mocks the method correctly" do
|
858
|
+
http_request_class.any_instance.should_receive(:existing_method).and_return("foo")
|
859
|
+
http_request_class.new.existing_method.should == "foo"
|
860
|
+
end
|
861
|
+
end
|
862
|
+
|
863
|
+
context "when used after the test has finished" do
|
864
|
+
it "restores the original behavior of a stubbed method" do
|
865
|
+
klass.any_instance.stub(:existing_method).and_return(:stubbed_return_value)
|
866
|
+
|
867
|
+
instance = klass.new
|
868
|
+
instance.existing_method.should == :stubbed_return_value
|
869
|
+
|
870
|
+
RSpec::Mocks.verify
|
871
|
+
|
872
|
+
instance.existing_method.should == :existing_method_return_value
|
873
|
+
end
|
874
|
+
end
|
848
875
|
end
|
849
876
|
end
|
850
877
|
end
|
@@ -93,6 +93,21 @@ module RSpec
|
|
93
93
|
%Q|(nil).foobar(any args)\n expected: 1 time\n received: 0 times|
|
94
94
|
)
|
95
95
|
end
|
96
|
+
|
97
|
+
it "includes the class name in the error when mocking a class method that is called an extra time with the wrong args" do
|
98
|
+
klass = Class.new do
|
99
|
+
def self.to_s
|
100
|
+
"MyClass"
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
klass.should_receive(:bar).with(1)
|
105
|
+
klass.bar(1)
|
106
|
+
|
107
|
+
expect {
|
108
|
+
klass.bar(2)
|
109
|
+
}.to raise_error(RSpec::Mocks::MockExpectationError, /MyClass/)
|
110
|
+
end
|
96
111
|
end
|
97
112
|
|
98
113
|
describe "Partially mocking an object that defines ==, after another mock has been defined" do
|
@@ -59,7 +59,7 @@ module RSpec
|
|
59
59
|
end
|
60
60
|
|
61
61
|
it 'serializes to yaml the same with and without stubbing, using YAML.dump' do
|
62
|
-
expect { set_stub }.to_not change { YAML.dump(serializable_object) }
|
62
|
+
expect { set_stub }.to_not change { ::YAML.dump(serializable_object) }
|
63
63
|
end
|
64
64
|
end
|
65
65
|
|
@@ -73,12 +73,12 @@ module RSpec
|
|
73
73
|
|
74
74
|
if compiled_with_psych
|
75
75
|
context 'using Syck as the YAML engine' do
|
76
|
-
before(:each) { YAML::ENGINE.yamler = 'syck' }
|
76
|
+
before(:each) { ::YAML::ENGINE.yamler = 'syck' }
|
77
77
|
it_behaves_like 'normal YAML serialization'
|
78
78
|
end
|
79
79
|
|
80
80
|
context 'using Psych as the YAML engine' do
|
81
|
-
before(:each) { YAML::ENGINE.yamler = 'psych' }
|
81
|
+
before(:each) { ::YAML::ENGINE.yamler = 'psych' }
|
82
82
|
it_behaves_like 'normal YAML serialization'
|
83
83
|
end
|
84
84
|
else
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StashedInstanceMethod do
|
4
|
+
class ExampleClass
|
5
|
+
def hello
|
6
|
+
:hello_defined_on_class
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
def singleton_class_for(obj)
|
11
|
+
class << obj; self; end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "stashes the current implementation of an instance method so it can be temporarily replaced" do
|
15
|
+
obj = Object.new
|
16
|
+
def obj.hello; :hello_defined_on_singleton_class; end;
|
17
|
+
|
18
|
+
stashed_method = StashedInstanceMethod.new(singleton_class_for(obj), :hello)
|
19
|
+
stashed_method.stash
|
20
|
+
|
21
|
+
def obj.hello; :overridden_hello; end
|
22
|
+
expect(obj.hello).to eql :overridden_hello
|
23
|
+
|
24
|
+
stashed_method.restore
|
25
|
+
expect(obj.hello).to eql :hello_defined_on_singleton_class
|
26
|
+
end
|
27
|
+
|
28
|
+
it "stashes private instance methods" do
|
29
|
+
obj = Object.new
|
30
|
+
def obj.hello; :hello_defined_on_singleton_class; end;
|
31
|
+
singleton_class_for(obj).__send__(:private, :hello)
|
32
|
+
|
33
|
+
stashed_method = StashedInstanceMethod.new(singleton_class_for(obj), :hello)
|
34
|
+
stashed_method.stash
|
35
|
+
|
36
|
+
def obj.hello; :overridden_hello; end
|
37
|
+
stashed_method.restore
|
38
|
+
expect(obj.send(:hello)).to eql :hello_defined_on_singleton_class
|
39
|
+
end
|
40
|
+
|
41
|
+
it "only stashes methods directly defined on the given class, not its ancestors" do
|
42
|
+
obj = ExampleClass.new
|
43
|
+
|
44
|
+
stashed_method = StashedInstanceMethod.new(singleton_class_for(obj), :hello)
|
45
|
+
stashed_method.stash
|
46
|
+
|
47
|
+
def obj.hello; :overridden_hello; end;
|
48
|
+
expect(obj.hello).to eql :overridden_hello
|
49
|
+
|
50
|
+
stashed_method.restore
|
51
|
+
expect(obj.hello).to eql :overridden_hello
|
52
|
+
end
|
53
|
+
end
|
@@ -144,6 +144,11 @@ module RSpec
|
|
144
144
|
object.msg1.msg2.msg3.msg4.should equal(:first)
|
145
145
|
object.msg1.msg2.msg3.msg5.should equal(:second)
|
146
146
|
end
|
147
|
+
|
148
|
+
it "handles private instance methods (like Object#select) in the middle of a chain" do
|
149
|
+
object.stub_chain(:msg1, :select, :msg3 => 'answer')
|
150
|
+
expect(object.msg1.select.msg3).to eq 'answer'
|
151
|
+
end
|
147
152
|
end
|
148
153
|
end
|
149
154
|
end
|
@@ -12,6 +12,10 @@ class TestClass
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
class TestSubClass < TestClass
|
16
|
+
P = :p
|
17
|
+
end
|
18
|
+
|
15
19
|
module RSpec
|
16
20
|
module Mocks
|
17
21
|
describe "Constant Stubbing" do
|
@@ -121,6 +125,24 @@ module RSpec
|
|
121
125
|
stub::Nested.should be(tc_nested)
|
122
126
|
end
|
123
127
|
|
128
|
+
it 'does not transfer nested constants that are inherited from a superclass' do
|
129
|
+
stub = Module.new
|
130
|
+
stub_const("TestSubClass", stub, :transfer_nested_constants => true)
|
131
|
+
stub::P.should eq(:p)
|
132
|
+
defined?(stub::M).should be_false
|
133
|
+
defined?(stub::N).should be_false
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'raises an error when asked to transfer a nested inherited constant' do
|
137
|
+
original_tsc = TestSubClass
|
138
|
+
|
139
|
+
expect {
|
140
|
+
stub_const("TestSubClass", Module.new, :transfer_nested_constants => [:M])
|
141
|
+
}.to raise_error(ArgumentError)
|
142
|
+
|
143
|
+
TestSubClass.should be(original_tsc)
|
144
|
+
end
|
145
|
+
|
124
146
|
it 'allows nested constants to be selectively transferred to a stub module' do
|
125
147
|
stub = Module.new
|
126
148
|
stub_const("TestClass", stub, :transfer_nested_constants => [:M, :N])
|
@@ -56,6 +56,19 @@ module RSpec
|
|
56
56
|
obj.unstub(:foo)
|
57
57
|
obj.foo(3).should eq :three
|
58
58
|
end
|
59
|
+
|
60
|
+
it "restores the correct implementations when stubbed and unstubbed on a parent and child class" do
|
61
|
+
parent = Class.new
|
62
|
+
child = Class.new(parent)
|
63
|
+
|
64
|
+
parent.stub(:new)
|
65
|
+
child.stub(:new)
|
66
|
+
parent.unstub(:new)
|
67
|
+
child.unstub(:new)
|
68
|
+
|
69
|
+
parent.new.should be_an_instance_of parent
|
70
|
+
child.new.should be_an_instance_of child
|
71
|
+
end
|
59
72
|
|
60
73
|
it "raises a MockExpectationError if the method has not been stubbed" do
|
61
74
|
obj = Object.new
|
@@ -112,6 +112,15 @@ module RSpec
|
|
112
112
|
@class.rspec_reset
|
113
113
|
@class.send(:existing_private_class_method).should eq(:original_value)
|
114
114
|
end
|
115
|
+
|
116
|
+
it "does not remove existing methods that have been stubbed twice" do
|
117
|
+
@instance.stub(:existing_instance_method)
|
118
|
+
@instance.stub(:existing_instance_method)
|
119
|
+
|
120
|
+
@instance.rspec_reset
|
121
|
+
|
122
|
+
@instance.existing_instance_method.should eq(:original_value)
|
123
|
+
end
|
115
124
|
end
|
116
125
|
|
117
126
|
it "returns values in order to consecutive calls" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,71 +1,80 @@
|
|
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
|
+
hash: 37
|
5
5
|
prerelease:
|
6
|
+
segments:
|
7
|
+
- 2
|
8
|
+
- 11
|
9
|
+
- 3
|
10
|
+
version: 2.11.3
|
6
11
|
platform: ruby
|
7
|
-
authors:
|
12
|
+
authors:
|
8
13
|
- Steven Baker
|
9
14
|
- David Chelimsky
|
10
15
|
autorequire:
|
11
16
|
bindir: bin
|
12
17
|
cert_chain: []
|
13
|
-
|
14
|
-
|
15
|
-
|
18
|
+
|
19
|
+
date: 2012-09-20 00:00:00 Z
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
16
22
|
name: rake
|
17
|
-
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
|
-
requirements:
|
20
|
-
- - ~>
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 0.9.2
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
26
|
none: false
|
27
|
-
requirements:
|
27
|
+
requirements:
|
28
28
|
- - ~>
|
29
|
-
- !ruby/object:Gem::Version
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 63
|
31
|
+
segments:
|
32
|
+
- 0
|
33
|
+
- 9
|
34
|
+
- 2
|
30
35
|
version: 0.9.2
|
31
|
-
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
32
38
|
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: !ruby/object:Gem::Requirement
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
42
|
none: false
|
43
|
-
requirements:
|
43
|
+
requirements:
|
44
44
|
- - ~>
|
45
|
-
- !ruby/object:Gem::Version
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 1
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 1
|
50
|
+
- 9
|
46
51
|
version: 1.1.9
|
47
|
-
|
52
|
+
requirement: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
48
54
|
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: !ruby/object:Gem::Requirement
|
57
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
58
58
|
none: false
|
59
|
-
requirements:
|
59
|
+
requirements:
|
60
60
|
- - ~>
|
61
|
-
- !ruby/object:Gem::Version
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 25
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
- 4
|
66
|
+
- 11
|
62
67
|
version: 0.4.11
|
68
|
+
requirement: *id003
|
63
69
|
description: RSpec's 'test double' framework, with support for stubbing and mocking
|
64
70
|
email: rspec-users@rubyforge.org
|
65
71
|
executables: []
|
72
|
+
|
66
73
|
extensions: []
|
74
|
+
|
67
75
|
extra_rdoc_files: []
|
68
|
-
|
76
|
+
|
77
|
+
files:
|
69
78
|
- lib/rspec/mocks.rb
|
70
79
|
- lib/rspec/mocks/any_instance.rb
|
71
80
|
- lib/rspec/mocks/any_instance/chain.rb
|
@@ -92,6 +101,7 @@ files:
|
|
92
101
|
- lib/rspec/mocks/serialization.rb
|
93
102
|
- lib/rspec/mocks/space.rb
|
94
103
|
- lib/rspec/mocks/standalone.rb
|
104
|
+
- lib/rspec/mocks/stashed_instance_method.rb
|
95
105
|
- lib/rspec/mocks/stub_const.rb
|
96
106
|
- lib/rspec/mocks/test_double.rb
|
97
107
|
- lib/rspec/mocks/version.rb
|
@@ -164,6 +174,7 @@ files:
|
|
164
174
|
- spec/rspec/mocks/record_messages_spec.rb
|
165
175
|
- spec/rspec/mocks/serialization_spec.rb
|
166
176
|
- spec/rspec/mocks/stash_spec.rb
|
177
|
+
- spec/rspec/mocks/stashed_instance_method_spec.rb
|
167
178
|
- spec/rspec/mocks/stub_chain_spec.rb
|
168
179
|
- spec/rspec/mocks/stub_const_spec.rb
|
169
180
|
- spec/rspec/mocks/stub_implementation_spec.rb
|
@@ -175,38 +186,39 @@ files:
|
|
175
186
|
- spec/rspec/mocks_spec.rb
|
176
187
|
- spec/spec_helper.rb
|
177
188
|
homepage: http://github.com/rspec/rspec-mocks
|
178
|
-
licenses:
|
189
|
+
licenses:
|
179
190
|
- MIT
|
180
191
|
post_install_message:
|
181
|
-
rdoc_options:
|
192
|
+
rdoc_options:
|
182
193
|
- --charset=UTF-8
|
183
|
-
require_paths:
|
194
|
+
require_paths:
|
184
195
|
- lib
|
185
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
196
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
186
197
|
none: false
|
187
|
-
requirements:
|
188
|
-
- -
|
189
|
-
- !ruby/object:Gem::Version
|
190
|
-
|
191
|
-
segments:
|
198
|
+
requirements:
|
199
|
+
- - ">="
|
200
|
+
- !ruby/object:Gem::Version
|
201
|
+
hash: 3
|
202
|
+
segments:
|
192
203
|
- 0
|
193
|
-
|
194
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
204
|
+
version: "0"
|
205
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
195
206
|
none: false
|
196
|
-
requirements:
|
197
|
-
- -
|
198
|
-
- !ruby/object:Gem::Version
|
199
|
-
|
200
|
-
segments:
|
207
|
+
requirements:
|
208
|
+
- - ">="
|
209
|
+
- !ruby/object:Gem::Version
|
210
|
+
hash: 3
|
211
|
+
segments:
|
201
212
|
- 0
|
202
|
-
|
213
|
+
version: "0"
|
203
214
|
requirements: []
|
215
|
+
|
204
216
|
rubyforge_project: rspec
|
205
|
-
rubygems_version: 1.8.
|
217
|
+
rubygems_version: 1.8.6
|
206
218
|
signing_key:
|
207
219
|
specification_version: 3
|
208
|
-
summary: rspec-mocks-2.11.
|
209
|
-
test_files:
|
220
|
+
summary: rspec-mocks-2.11.3
|
221
|
+
test_files:
|
210
222
|
- features/README.md
|
211
223
|
- features/Scope.md
|
212
224
|
- features/Upgrade.md
|
@@ -270,6 +282,7 @@ test_files:
|
|
270
282
|
- spec/rspec/mocks/record_messages_spec.rb
|
271
283
|
- spec/rspec/mocks/serialization_spec.rb
|
272
284
|
- spec/rspec/mocks/stash_spec.rb
|
285
|
+
- spec/rspec/mocks/stashed_instance_method_spec.rb
|
273
286
|
- spec/rspec/mocks/stub_chain_spec.rb
|
274
287
|
- spec/rspec/mocks/stub_const_spec.rb
|
275
288
|
- spec/rspec/mocks/stub_implementation_spec.rb
|