rspec-mocks 2.0.0.beta.22 → 2.0.0.rc
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/{History.md → History.markdown} +12 -0
- data/Rakefile +1 -0
- data/lib/rspec/mocks.rb +1 -1
- data/lib/rspec/mocks/framework.rb +1 -0
- data/lib/rspec/mocks/message_expectation.rb +3 -3
- data/lib/rspec/mocks/methods.rb +9 -4
- data/lib/rspec/mocks/proxy.rb +7 -0
- data/lib/rspec/mocks/serialization.rb +24 -0
- data/lib/rspec/mocks/version.rb +1 -1
- data/spec/rspec/mocks/mock_spec.rb +9 -0
- data/spec/rspec/mocks/serialization_spec.rb +69 -0
- data/spec/rspec/mocks/stub_spec.rb +2 -2
- metadata +23 -19
@@ -1,5 +1,17 @@
|
|
1
1
|
## rspec-mocks release history (incomplete)
|
2
2
|
|
3
|
+
### 2.0.0.rc / 2010-10-05
|
4
|
+
|
5
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.22...v2.0.0.rc)
|
6
|
+
|
7
|
+
* Enhancements
|
8
|
+
* support passing a block to an expecttation block (Nicolas Braem)
|
9
|
+
* obj.should_receive(:msg) {|&block| ... }
|
10
|
+
|
11
|
+
* Bug fixes
|
12
|
+
* Fix YAML serialization of stub (Myron Marston)
|
13
|
+
* Fix rdoc rake task (Hans de Graaff)
|
14
|
+
|
3
15
|
### 2.0.0.beta.22 / 2010-09-12
|
4
16
|
|
5
17
|
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.20...v2.0.0.beta.22)
|
data/Rakefile
CHANGED
data/lib/rspec/mocks.rb
CHANGED
@@ -26,7 +26,7 @@ module RSpec
|
|
26
26
|
# message some time before the example ends. If the message is received, the
|
27
27
|
# expectation is satisfied. If not, the example fails.
|
28
28
|
#
|
29
|
-
#
|
29
|
+
# validator = double("validator")
|
30
30
|
# validator.should_receive(:validate).with("02134")
|
31
31
|
# zipcode = Zipcode.new("02134", validator)
|
32
32
|
# zipcode.valid?
|
@@ -115,7 +115,7 @@ module RSpec
|
|
115
115
|
Kernel::throw @symbol_to_throw unless @symbol_to_throw.nil?
|
116
116
|
|
117
117
|
default_return_val = if !@method_block.nil?
|
118
|
-
invoke_method_block(*args)
|
118
|
+
invoke_method_block(*args, &block)
|
119
119
|
elsif !@args_to_yield.empty? || @eval_context
|
120
120
|
invoke_with_yield(&block)
|
121
121
|
else
|
@@ -141,9 +141,9 @@ module RSpec
|
|
141
141
|
|
142
142
|
protected
|
143
143
|
|
144
|
-
def invoke_method_block(*args)
|
144
|
+
def invoke_method_block(*args, &block)
|
145
145
|
begin
|
146
|
-
@method_block.call(*args)
|
146
|
+
@method_block.call(*args, &block)
|
147
147
|
rescue => detail
|
148
148
|
@error_generator.raise_block_failed_error(@sym, detail.message)
|
149
149
|
end
|
data/lib/rspec/mocks/methods.rb
CHANGED
@@ -73,10 +73,15 @@ module RSpec
|
|
73
73
|
private
|
74
74
|
|
75
75
|
def __mock_proxy
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
76
|
+
@mock_proxy ||= begin
|
77
|
+
mp = if Mock === self
|
78
|
+
Proxy.new(self, @name, @options)
|
79
|
+
else
|
80
|
+
Proxy.new(self)
|
81
|
+
end
|
82
|
+
|
83
|
+
Serialization.fix_for(self)
|
84
|
+
mp
|
80
85
|
end
|
81
86
|
end
|
82
87
|
|
data/lib/rspec/mocks/proxy.rb
CHANGED
@@ -105,6 +105,9 @@ module RSpec
|
|
105
105
|
elsif expectation = find_almost_matching_expectation(method_name, *args)
|
106
106
|
expectation.advise(*args) if null_object? unless expectation.expected_messages_received?
|
107
107
|
raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(method_name) or null_object?)
|
108
|
+
elsif stub = find_almost_matching_stub(method_name, *args)
|
109
|
+
stub.advise(*args)
|
110
|
+
raise_unexpected_message_args_error(stub, *args)
|
108
111
|
elsif @object.is_a?(Class)
|
109
112
|
@object.superclass.send(method_name, *args, &block)
|
110
113
|
else
|
@@ -145,6 +148,10 @@ module RSpec
|
|
145
148
|
method_double[method_name].stubs.find {|stub| stub.matches?(method_name, *args)}
|
146
149
|
end
|
147
150
|
|
151
|
+
def find_almost_matching_stub(method_name, *args)
|
152
|
+
method_double[method_name].stubs.find {|stub| stub.matches_name_but_not_args(method_name, *args)}
|
153
|
+
end
|
154
|
+
|
148
155
|
end
|
149
156
|
end
|
150
157
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RSpec
|
2
|
+
module Mocks
|
3
|
+
module Serialization
|
4
|
+
def self.fix_for(object)
|
5
|
+
object.extend(YAML) if defined?(::YAML)
|
6
|
+
end
|
7
|
+
|
8
|
+
module YAML
|
9
|
+
def to_yaml(*a)
|
10
|
+
return super(*a) unless instance_variable_defined?(:@mock_proxy)
|
11
|
+
|
12
|
+
mp = @mock_proxy
|
13
|
+
remove_instance_variable(:@mock_proxy)
|
14
|
+
|
15
|
+
begin
|
16
|
+
super(*a)
|
17
|
+
ensure
|
18
|
+
@mock_proxy = mp
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/rspec/mocks/version.rb
CHANGED
@@ -144,6 +144,15 @@ module RSpec
|
|
144
144
|
}.to raise_error(RSpec::Mocks::MockExpectationError, /Double \"test double\" received :something but passed block failed with: expected false to be true/)
|
145
145
|
end
|
146
146
|
|
147
|
+
it "passes block to expectation block" do
|
148
|
+
a = nil
|
149
|
+
@mock.should_receive(:something) { |&block| a = block }
|
150
|
+
b = lambda { }
|
151
|
+
@mock.something(&b)
|
152
|
+
a.should == b
|
153
|
+
@moc.rspec_verify
|
154
|
+
end
|
155
|
+
|
147
156
|
it "fails right away when method defined as never is received" do
|
148
157
|
@mock.should_receive(:not_expected).never
|
149
158
|
expect { @mock.not_expected }.to raise_error(
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module RSpec
|
5
|
+
module Mocks
|
6
|
+
class SerializableStruct < Struct.new(:foo, :bar); end
|
7
|
+
|
8
|
+
describe Serialization do
|
9
|
+
def self.with_yaml_loaded(&block)
|
10
|
+
context 'with YAML loaded' do
|
11
|
+
module_eval(&block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.without_yaml_loaded(&block)
|
16
|
+
context 'without YAML loaded' do
|
17
|
+
before(:each) do
|
18
|
+
# We can't really unload yaml, but we can fake it here...
|
19
|
+
@orig_yaml_constant = Object.send(:remove_const, :YAML)
|
20
|
+
Struct.class_eval do
|
21
|
+
alias __old_to_yaml to_yaml
|
22
|
+
undef to_yaml
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
module_eval(&block)
|
27
|
+
|
28
|
+
after(:each) do
|
29
|
+
Object.const_set(:YAML, @orig_yaml_constant)
|
30
|
+
Struct.class_eval do
|
31
|
+
alias to_yaml __old_to_yaml
|
32
|
+
undef __old_to_yaml
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
subject { SerializableStruct.new(7, "something") }
|
39
|
+
|
40
|
+
def set_stub
|
41
|
+
subject.stub(:bazz => 5)
|
42
|
+
end
|
43
|
+
|
44
|
+
with_yaml_loaded do
|
45
|
+
it 'serializes to yaml the same with and without stubbing, using #to_yaml' do
|
46
|
+
expect { set_stub }.to_not change { subject.to_yaml }
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'serializes to yaml the same with and without stubbing, using YAML.dump' do
|
50
|
+
expect { set_stub }.to_not change { YAML.dump(subject) }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
without_yaml_loaded do
|
55
|
+
it 'does not add #to_yaml to the stubbed object' do
|
56
|
+
subject.should_not respond_to(:to_yaml)
|
57
|
+
set_stub
|
58
|
+
subject.should_not respond_to(:to_yaml)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'marshals the same with and without stubbing' do
|
63
|
+
pending("not sure how to fix this yet") do
|
64
|
+
expect { set_stub }.to_not change { Marshal.dump(subject) }
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -199,13 +199,13 @@ module RSpec
|
|
199
199
|
it "complains if called with no arg" do
|
200
200
|
lambda do
|
201
201
|
@stub.foo
|
202
|
-
end.should raise_error
|
202
|
+
end.should raise_error(/received :foo with unexpected arguments/)
|
203
203
|
end
|
204
204
|
|
205
205
|
it "complains if called with other arg" do
|
206
206
|
lambda do
|
207
207
|
@stub.foo("other")
|
208
|
-
end.should raise_error
|
208
|
+
end.should raise_error(/received :foo with unexpected arguments/)
|
209
209
|
end
|
210
210
|
|
211
211
|
it "does not complain if also mocked w/ different args" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-mocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 7712058
|
4
5
|
prerelease: true
|
5
6
|
segments:
|
6
7
|
- 2
|
7
8
|
- 0
|
8
9
|
- 0
|
9
|
-
-
|
10
|
-
|
11
|
-
version: 2.0.0.beta.22
|
10
|
+
- rc
|
11
|
+
version: 2.0.0.rc
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- David Chelimsky
|
@@ -17,43 +17,43 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-
|
20
|
+
date: 2010-10-04 00:00:00 -05:00
|
21
21
|
default_executable:
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
24
|
-
|
25
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
25
|
none: false
|
27
26
|
requirements:
|
28
27
|
- - "="
|
29
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 7712058
|
30
30
|
segments:
|
31
31
|
- 2
|
32
32
|
- 0
|
33
33
|
- 0
|
34
|
-
-
|
35
|
-
|
36
|
-
|
34
|
+
- rc
|
35
|
+
version: 2.0.0.rc
|
36
|
+
requirement: *id001
|
37
37
|
type: :runtime
|
38
|
+
name: rspec-core
|
38
39
|
prerelease: false
|
39
|
-
version_requirements: *id001
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
|
-
|
42
|
-
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
43
42
|
none: false
|
44
43
|
requirements:
|
45
44
|
- - "="
|
46
45
|
- !ruby/object:Gem::Version
|
46
|
+
hash: 7712058
|
47
47
|
segments:
|
48
48
|
- 2
|
49
49
|
- 0
|
50
50
|
- 0
|
51
|
-
-
|
52
|
-
|
53
|
-
|
51
|
+
- rc
|
52
|
+
version: 2.0.0.rc
|
53
|
+
requirement: *id002
|
54
54
|
type: :runtime
|
55
|
+
name: rspec-expectations
|
55
56
|
prerelease: false
|
56
|
-
version_requirements: *id002
|
57
57
|
description: RSpec's 'test double' framework, with support for stubbing and mocking
|
58
58
|
email: dchelimsky@gmail.com;chad.humphries@gmail.com
|
59
59
|
executables: []
|
@@ -67,7 +67,7 @@ files:
|
|
67
67
|
- .document
|
68
68
|
- .gitignore
|
69
69
|
- Gemfile
|
70
|
-
- History.
|
70
|
+
- History.markdown
|
71
71
|
- License.txt
|
72
72
|
- README.markdown
|
73
73
|
- Rakefile
|
@@ -94,6 +94,7 @@ files:
|
|
94
94
|
- lib/rspec/mocks/mock.rb
|
95
95
|
- lib/rspec/mocks/order_group.rb
|
96
96
|
- lib/rspec/mocks/proxy.rb
|
97
|
+
- lib/rspec/mocks/serialization.rb
|
97
98
|
- lib/rspec/mocks/space.rb
|
98
99
|
- lib/rspec/mocks/spec_methods.rb
|
99
100
|
- lib/rspec/mocks/version.rb
|
@@ -134,6 +135,7 @@ files:
|
|
134
135
|
- spec/rspec/mocks/passing_argument_matchers_spec.rb
|
135
136
|
- spec/rspec/mocks/precise_counts_spec.rb
|
136
137
|
- spec/rspec/mocks/record_messages_spec.rb
|
138
|
+
- spec/rspec/mocks/serialization_spec.rb
|
137
139
|
- spec/rspec/mocks/stash_spec.rb
|
138
140
|
- spec/rspec/mocks/stub_chain_spec.rb
|
139
141
|
- spec/rspec/mocks/stub_implementation_spec.rb
|
@@ -157,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
159
|
requirements:
|
158
160
|
- - ">="
|
159
161
|
- !ruby/object:Gem::Version
|
160
|
-
hash:
|
162
|
+
hash: 3
|
161
163
|
segments:
|
162
164
|
- 0
|
163
165
|
version: "0"
|
@@ -166,6 +168,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
168
|
requirements:
|
167
169
|
- - ">"
|
168
170
|
- !ruby/object:Gem::Version
|
171
|
+
hash: 25
|
169
172
|
segments:
|
170
173
|
- 1
|
171
174
|
- 3
|
@@ -177,7 +180,7 @@ rubyforge_project: rspec
|
|
177
180
|
rubygems_version: 1.3.7
|
178
181
|
signing_key:
|
179
182
|
specification_version: 3
|
180
|
-
summary: rspec-mocks-2.0.0.
|
183
|
+
summary: rspec-mocks-2.0.0.rc
|
181
184
|
test_files:
|
182
185
|
- features/README.markdown
|
183
186
|
- features/configuration.feature
|
@@ -221,6 +224,7 @@ test_files:
|
|
221
224
|
- spec/rspec/mocks/passing_argument_matchers_spec.rb
|
222
225
|
- spec/rspec/mocks/precise_counts_spec.rb
|
223
226
|
- spec/rspec/mocks/record_messages_spec.rb
|
227
|
+
- spec/rspec/mocks/serialization_spec.rb
|
224
228
|
- spec/rspec/mocks/stash_spec.rb
|
225
229
|
- spec/rspec/mocks/stub_chain_spec.rb
|
226
230
|
- spec/rspec/mocks/stub_implementation_spec.rb
|