rspec-mocks 2.14.3 → 2.14.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Changelog.md +10 -0
- data/lib/rspec/mocks.rb +4 -0
- data/lib/rspec/mocks/any_instance/chain.rb +2 -1
- data/lib/rspec/mocks/any_instance/recorder.rb +9 -4
- data/lib/rspec/mocks/any_instance/stub_chain.rb +3 -1
- data/lib/rspec/mocks/matchers/receive.rb +1 -0
- data/lib/rspec/mocks/method_double.rb +6 -0
- data/lib/rspec/mocks/proxy.rb +7 -0
- data/lib/rspec/mocks/space.rb +6 -2
- data/lib/rspec/mocks/version.rb +1 -1
- data/spec/rspec/mocks/any_instance/message_chains_spec.rb +5 -4
- data/spec/rspec/mocks/any_instance_spec.rb +24 -0
- data/spec/rspec/mocks/matchers/receive_spec.rb +8 -0
- data/spec/rspec/mocks/space_spec.rb +32 -0
- metadata +20 -32
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
NjllZTA4NjU4ZGRkZWQxYjQ1ZGRhNmNjMWU1NjBjZDk2MzVmMDE3Zg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
M2I4Yjc1MDdhODcwOTJkY2UxOGUzMjdhNmVjNjMyYjBiN2YzN2ZkOA==
|
7
|
+
!binary "U0hBNTEy":
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
OGU0Y2Y4ZmQ1OTFiYzU4YjM2OTYxYTMzMmExYWUzZWE0NGNjYTFiODlmYjli
|
10
|
+
YzIxMzUxZTVkZDFjNmYzY2Q1ZDQ2MmM1NjEwYWQ0OGU2YzM4MjhhN2FkNWQ5
|
11
|
+
YTNjNWZiYTg1NDNhODYyZGMxZjJiOTVhNDc4MDFjNDBlYTY3ZGM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDBmNWNkYzMxZTA1M2UwYjE2YmRlMGFiYTc4YTZmN2FhMDk4ZmU5YWY5NTU5
|
14
|
+
NzU3NjhmNjllMzU0ZTM4OWE2YmFjMThlNGYyMWFjZTI5NjQxNjQ0NzJlMzdh
|
15
|
+
OWFkZmE1MDg2NDk2MzdkYmY1MjMyZGFiZGRkNGFjN2VkNzMzNDU=
|
data/Changelog.md
CHANGED
@@ -1,3 +1,13 @@
|
|
1
|
+
### 2.14.4 / 2013-10-15
|
2
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.3...v2.14.4)
|
3
|
+
|
4
|
+
Bug Fixes:
|
5
|
+
|
6
|
+
* Fix issue where unstubing methods on "any instances" would not
|
7
|
+
remove stubs on existing instances (Jon Rowe)
|
8
|
+
* Fix issue with receive(:message) do ... end precedence preventing
|
9
|
+
the usage of modifications (`and_return` etc) (Jon Rowe)
|
10
|
+
|
1
11
|
### 2.14.3 / 2013-08-08
|
2
12
|
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.14.2...v2.14.3)
|
3
13
|
|
data/lib/rspec/mocks.rb
CHANGED
@@ -11,10 +11,11 @@ module RSpec
|
|
11
11
|
# @see Chain
|
12
12
|
class Recorder
|
13
13
|
# @private
|
14
|
-
attr_reader :message_chains
|
14
|
+
attr_reader :message_chains, :stubs
|
15
15
|
|
16
16
|
def initialize(klass)
|
17
17
|
@message_chains = MessageChains.new
|
18
|
+
@stubs = Hash.new { |hash,key| hash[key] = [] }
|
18
19
|
@observed_methods = []
|
19
20
|
@played_methods = {}
|
20
21
|
@klass = klass
|
@@ -32,7 +33,7 @@ module RSpec
|
|
32
33
|
end
|
33
34
|
else
|
34
35
|
observe!(method_name_or_method_map)
|
35
|
-
message_chains.add(method_name_or_method_map, StubChain.new(method_name_or_method_map, &block))
|
36
|
+
message_chains.add(method_name_or_method_map, StubChain.new(self, method_name_or_method_map, &block))
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
@@ -44,7 +45,7 @@ module RSpec
|
|
44
45
|
def stub_chain(*method_names_and_optional_return_values, &block)
|
45
46
|
normalize_chain(*method_names_and_optional_return_values) do |method_name, args|
|
46
47
|
observe!(method_name)
|
47
|
-
message_chains.add(method_name, StubChainChain.new(*args, &block))
|
48
|
+
message_chains.add(method_name, StubChainChain.new(self, *args, &block))
|
48
49
|
end
|
49
50
|
end
|
50
51
|
|
@@ -56,7 +57,7 @@ module RSpec
|
|
56
57
|
def should_receive(method_name, &block)
|
57
58
|
@expectation_set = true
|
58
59
|
observe!(method_name)
|
59
|
-
message_chains.add(method_name, PositiveExpectationChain.new(method_name, &block))
|
60
|
+
message_chains.add(method_name, PositiveExpectationChain.new(self, method_name, &block))
|
60
61
|
end
|
61
62
|
|
62
63
|
def should_not_receive(method_name, &block)
|
@@ -72,6 +73,10 @@ module RSpec
|
|
72
73
|
raise RSpec::Mocks::MockExpectationError, "The method `#{method_name}` was not stubbed or was already unstubbed"
|
73
74
|
end
|
74
75
|
message_chains.remove_stub_chains_for!(method_name)
|
76
|
+
::RSpec::Mocks.proxies_of(@klass).each do |proxy|
|
77
|
+
stubs[method_name].each { |stub| proxy.remove_single_stub(method_name, stub) }
|
78
|
+
end
|
79
|
+
stubs[method_name].clear
|
75
80
|
stop_observing!(method_name) unless message_chains.has_expectation?(method_name)
|
76
81
|
end
|
77
82
|
|
@@ -14,7 +14,9 @@ module RSpec
|
|
14
14
|
def create_message_expectation_on(instance)
|
15
15
|
proxy = ::RSpec::Mocks.proxy_for(instance)
|
16
16
|
expected_from = IGNORED_BACKTRACE_LINE
|
17
|
-
proxy.add_stub(expected_from, *@expectation_args, &@expectation_block)
|
17
|
+
stub = proxy.add_stub(expected_from, *@expectation_args, &@expectation_block)
|
18
|
+
@recorder.stubs[stub.message] << stub
|
19
|
+
stub
|
18
20
|
end
|
19
21
|
|
20
22
|
def invocation_order
|
@@ -253,6 +253,12 @@ module RSpec
|
|
253
253
|
expectations.empty? ? reset : stubs.clear
|
254
254
|
end
|
255
255
|
|
256
|
+
# @private
|
257
|
+
def remove_single_stub(stub)
|
258
|
+
stubs.delete(stub)
|
259
|
+
restore_original_method if stubs.empty? && expectations.empty?
|
260
|
+
end
|
261
|
+
|
256
262
|
# @private
|
257
263
|
def raise_method_not_stubbed_error
|
258
264
|
raise MockExpectationError, "The method `#{method_name}` was not stubbed or was already unstubbed"
|
data/lib/rspec/mocks/proxy.rb
CHANGED
@@ -15,6 +15,9 @@ module RSpec
|
|
15
15
|
@null_object = false
|
16
16
|
end
|
17
17
|
|
18
|
+
# @private
|
19
|
+
attr_reader :object
|
20
|
+
|
18
21
|
# @private
|
19
22
|
def null_object?
|
20
23
|
@null_object
|
@@ -100,6 +103,10 @@ module RSpec
|
|
100
103
|
method_double[method_name].remove_stub
|
101
104
|
end
|
102
105
|
|
106
|
+
def remove_single_stub(method_name, stub)
|
107
|
+
method_double[method_name].remove_single_stub(stub)
|
108
|
+
end
|
109
|
+
|
103
110
|
# @private
|
104
111
|
def verify
|
105
112
|
method_doubles.each {|d| d.verify}
|
data/lib/rspec/mocks/space.rb
CHANGED
@@ -5,8 +5,8 @@ module RSpec
|
|
5
5
|
attr_reader :proxies, :any_instance_recorders
|
6
6
|
|
7
7
|
def initialize
|
8
|
-
@proxies
|
9
|
-
@any_instance_recorders
|
8
|
+
@proxies = {}
|
9
|
+
@any_instance_recorders = {}
|
10
10
|
end
|
11
11
|
|
12
12
|
def verify_all
|
@@ -46,6 +46,10 @@ module RSpec
|
|
46
46
|
any_instance_recorders.delete(klass.__id__)
|
47
47
|
end
|
48
48
|
|
49
|
+
def proxies_of(klass)
|
50
|
+
proxies.values.select { |proxy| klass === proxy.object }
|
51
|
+
end
|
52
|
+
|
49
53
|
def proxy_for(object)
|
50
54
|
id = id_for(object)
|
51
55
|
proxies.fetch(id) do
|
data/lib/rspec/mocks/version.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe RSpec::Mocks::AnyInstance::MessageChains do
|
4
|
+
let(:recorder) { double }
|
4
5
|
let(:chains) { RSpec::Mocks::AnyInstance::MessageChains.new }
|
5
|
-
let(:stub_chain) { RSpec::Mocks::AnyInstance::StubChain.new }
|
6
|
-
let(:expectation_chain) { RSpec::Mocks::AnyInstance::PositiveExpectationChain.new }
|
6
|
+
let(:stub_chain) { RSpec::Mocks::AnyInstance::StubChain.new recorder }
|
7
|
+
let(:expectation_chain) { RSpec::Mocks::AnyInstance::PositiveExpectationChain.new recorder }
|
7
8
|
|
8
9
|
it "knows if a method does not have an expectation set on it" do
|
9
10
|
chains.add(:method_name, stub_chain)
|
@@ -19,7 +20,7 @@ describe RSpec::Mocks::AnyInstance::MessageChains do
|
|
19
20
|
it "can remove all stub chains" do
|
20
21
|
chains.add(:method_name, stub_chain)
|
21
22
|
chains.add(:method_name, expectation_chain)
|
22
|
-
chains.add(:method_name, RSpec::Mocks::AnyInstance::StubChain.new)
|
23
|
+
chains.add(:method_name, RSpec::Mocks::AnyInstance::StubChain.new(recorder))
|
23
24
|
|
24
25
|
chains.remove_stub_chains_for!(:method_name)
|
25
26
|
expect(chains[:method_name]).to eq([expectation_chain])
|
@@ -33,7 +34,7 @@ describe RSpec::Mocks::AnyInstance::MessageChains do
|
|
33
34
|
|
34
35
|
it "allows multiple stub chains for a method" do
|
35
36
|
chains.add(:method_name, stub_chain)
|
36
|
-
chains.add(:method_name, another_stub_chain = RSpec::Mocks::AnyInstance::StubChain.new)
|
37
|
+
chains.add(:method_name, another_stub_chain = RSpec::Mocks::AnyInstance::StubChain.new(recorder))
|
37
38
|
expect(chains[:method_name]).to eq([stub_chain, another_stub_chain])
|
38
39
|
end
|
39
40
|
end
|
@@ -295,6 +295,30 @@ module RSpec
|
|
295
295
|
expect(klass.new.existing_method).to eq(:existing_method_return_value)
|
296
296
|
end
|
297
297
|
|
298
|
+
it "removes stubs even if they have already been invoked" do
|
299
|
+
klass.any_instance.stub(:existing_method).and_return(:any_instance_value)
|
300
|
+
obj = klass.new
|
301
|
+
obj.existing_method
|
302
|
+
klass.any_instance.unstub(:existing_method)
|
303
|
+
expect(obj.existing_method).to eq(:existing_method_return_value)
|
304
|
+
end
|
305
|
+
|
306
|
+
it "removes stubs from sub class after invokation when super class was originally stubbed" do
|
307
|
+
klass.any_instance.stub(:existing_method).and_return(:any_instance_value)
|
308
|
+
obj = Class.new(klass).new
|
309
|
+
expect(obj.existing_method).to eq(:any_instance_value)
|
310
|
+
klass.any_instance.unstub(:existing_method)
|
311
|
+
expect(obj.existing_method).to eq(:existing_method_return_value)
|
312
|
+
end
|
313
|
+
|
314
|
+
it "does not remove any stubs set directly on an instance" do
|
315
|
+
klass.any_instance.stub(:existing_method).and_return(:any_instance_value)
|
316
|
+
obj = klass.new
|
317
|
+
obj.stub(:existing_method).and_return(:local_method)
|
318
|
+
klass.any_instance.unstub(:existing_method)
|
319
|
+
expect(obj.existing_method).to eq(:local_method)
|
320
|
+
end
|
321
|
+
|
298
322
|
it "does not remove any expectations with the same method name" do
|
299
323
|
klass.any_instance.should_receive(:existing_method_with_arguments).with(3).and_return(:three)
|
300
324
|
klass.any_instance.stub(:existing_method_with_arguments).with(1)
|
@@ -32,6 +32,14 @@ module RSpec
|
|
32
32
|
expect(receiver.foo).to eq(4)
|
33
33
|
end
|
34
34
|
|
35
|
+
it 'allows chaining off a `do...end` block implementation to be provided' do
|
36
|
+
wrapped.to receive(:foo) do
|
37
|
+
4
|
38
|
+
end.and_return(6)
|
39
|
+
|
40
|
+
expect(receiver.foo).to eq(6)
|
41
|
+
end
|
42
|
+
|
35
43
|
it 'allows a `{ ... }` block implementation to be provided' do
|
36
44
|
wrapped.to receive(:foo) { 5 }
|
37
45
|
expect(receiver.foo).to eq(5)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module RSpec::Mocks
|
4
|
+
describe Space do
|
5
|
+
|
6
|
+
describe "#proxies_of(klass)" do
|
7
|
+
let(:space) { Space.new }
|
8
|
+
|
9
|
+
it 'returns proxies' do
|
10
|
+
space.proxy_for("")
|
11
|
+
expect(space.proxies_of(String).map(&:class)).to eq([Proxy])
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'returns only the proxies whose object is an instance of the given class' do
|
15
|
+
grandparent_class = Class.new
|
16
|
+
parent_class = Class.new(grandparent_class)
|
17
|
+
child_class = Class.new(parent_class)
|
18
|
+
|
19
|
+
grandparent = grandparent_class.new
|
20
|
+
parent = parent_class.new
|
21
|
+
child = child_class.new
|
22
|
+
|
23
|
+
grandparent_proxy = space.proxy_for(grandparent)
|
24
|
+
parent_proxy = space.proxy_for(parent)
|
25
|
+
child_proxy = space.proxy_for(child)
|
26
|
+
|
27
|
+
expect(space.proxies_of(parent_class)).to match_array([parent_proxy, child_proxy])
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-mocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
version: 2.14.3
|
4
|
+
version: 2.14.4
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Steven Baker
|
@@ -10,56 +9,50 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2013-
|
12
|
+
date: 2013-10-16 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
|
-
version_requirements: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ~>
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: 10.0.0
|
21
|
-
none: false
|
22
|
-
prerelease: false
|
23
15
|
name: rake
|
24
16
|
requirement: !ruby/object:Gem::Requirement
|
25
17
|
requirements:
|
26
18
|
- - ~>
|
27
19
|
- !ruby/object:Gem::Version
|
28
20
|
version: 10.0.0
|
29
|
-
none: false
|
30
21
|
type: :development
|
31
|
-
|
22
|
+
prerelease: false
|
32
23
|
version_requirements: !ruby/object:Gem::Requirement
|
33
24
|
requirements:
|
34
25
|
- - ~>
|
35
26
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
37
|
-
|
38
|
-
prerelease: false
|
27
|
+
version: 10.0.0
|
28
|
+
- !ruby/object:Gem::Dependency
|
39
29
|
name: cucumber
|
40
30
|
requirement: !ruby/object:Gem::Requirement
|
41
31
|
requirements:
|
42
32
|
- - ~>
|
43
33
|
- !ruby/object:Gem::Version
|
44
34
|
version: 1.1.9
|
45
|
-
none: false
|
46
35
|
type: :development
|
47
|
-
|
36
|
+
prerelease: false
|
48
37
|
version_requirements: !ruby/object:Gem::Requirement
|
49
38
|
requirements:
|
50
39
|
- - ~>
|
51
40
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
53
|
-
|
54
|
-
prerelease: false
|
41
|
+
version: 1.1.9
|
42
|
+
- !ruby/object:Gem::Dependency
|
55
43
|
name: aruba
|
56
44
|
requirement: !ruby/object:Gem::Requirement
|
57
45
|
requirements:
|
58
46
|
- - ~>
|
59
47
|
- !ruby/object:Gem::Version
|
60
48
|
version: '0.5'
|
61
|
-
none: false
|
62
49
|
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ~>
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0.5'
|
63
56
|
description: RSpec's 'test double' framework, with support for stubbing and mocking
|
64
57
|
email: rspec-users@rubyforge.org
|
65
58
|
executables: []
|
@@ -188,6 +181,7 @@ files:
|
|
188
181
|
- spec/rspec/mocks/precise_counts_spec.rb
|
189
182
|
- spec/rspec/mocks/record_messages_spec.rb
|
190
183
|
- spec/rspec/mocks/serialization_spec.rb
|
184
|
+
- spec/rspec/mocks/space_spec.rb
|
191
185
|
- spec/rspec/mocks/stash_spec.rb
|
192
186
|
- spec/rspec/mocks/stub_chain_spec.rb
|
193
187
|
- spec/rspec/mocks/stub_implementation_spec.rb
|
@@ -202,6 +196,7 @@ files:
|
|
202
196
|
homepage: http://github.com/rspec/rspec-mocks
|
203
197
|
licenses:
|
204
198
|
- MIT
|
199
|
+
metadata: {}
|
205
200
|
post_install_message:
|
206
201
|
rdoc_options:
|
207
202
|
- --charset=UTF-8
|
@@ -212,25 +207,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
212
207
|
- - ! '>='
|
213
208
|
- !ruby/object:Gem::Version
|
214
209
|
version: '0'
|
215
|
-
segments:
|
216
|
-
- 0
|
217
|
-
hash: -4603029701728341322
|
218
|
-
none: false
|
219
210
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
220
211
|
requirements:
|
221
212
|
- - ! '>='
|
222
213
|
- !ruby/object:Gem::Version
|
223
214
|
version: '0'
|
224
|
-
segments:
|
225
|
-
- 0
|
226
|
-
hash: -4603029701728341322
|
227
|
-
none: false
|
228
215
|
requirements: []
|
229
216
|
rubyforge_project: rspec
|
230
|
-
rubygems_version:
|
217
|
+
rubygems_version: 2.0.7
|
231
218
|
signing_key:
|
232
|
-
specification_version:
|
233
|
-
summary: rspec-mocks-2.14.
|
219
|
+
specification_version: 4
|
220
|
+
summary: rspec-mocks-2.14.4
|
234
221
|
test_files:
|
235
222
|
- features/README.md
|
236
223
|
- features/Scope.md
|
@@ -314,6 +301,7 @@ test_files:
|
|
314
301
|
- spec/rspec/mocks/precise_counts_spec.rb
|
315
302
|
- spec/rspec/mocks/record_messages_spec.rb
|
316
303
|
- spec/rspec/mocks/serialization_spec.rb
|
304
|
+
- spec/rspec/mocks/space_spec.rb
|
317
305
|
- spec/rspec/mocks/stash_spec.rb
|
318
306
|
- spec/rspec/mocks/stub_chain_spec.rb
|
319
307
|
- spec/rspec/mocks/stub_implementation_spec.rb
|