rspec-mocks 2.6.0.rc2 → 2.6.0.rc4
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/Gemfile +3 -3
- data/features/Changelog.md +8 -1
- data/features/Upgrade.md +10 -2
- data/lib/rspec/mocks/any_instance.rb +24 -14
- data/lib/rspec/mocks/argument_expectation.rb +9 -8
- data/lib/rspec/mocks/extensions/marshal.rb +0 -4
- data/lib/rspec/mocks/version.rb +1 -1
- data/spec/rspec/mocks/any_instance_spec.rb +30 -18
- metadata +6 -6
data/Gemfile
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
source "http://rubygems.org"
|
2
2
|
|
3
3
|
### rspec libs
|
4
|
-
%w[rspec-core rspec-expectations rspec-mocks].each do |lib|
|
4
|
+
%w[rspec rspec-core rspec-expectations rspec-mocks].each do |lib|
|
5
5
|
library_path = File.expand_path("../../#{lib}", __FILE__)
|
6
6
|
if File.exist?(library_path)
|
7
7
|
gem lib, :path => library_path
|
@@ -12,8 +12,8 @@ end
|
|
12
12
|
|
13
13
|
### dev dependencies
|
14
14
|
gem "rake", "0.8.7"
|
15
|
-
|
16
|
-
|
15
|
+
gem "cucumber", "~> 0.10.2"
|
16
|
+
gem "aruba", "~> 0.3.6"
|
17
17
|
gem "rcov", "0.9.9", :platforms => :mri
|
18
18
|
gem "relish", "0.2.0"
|
19
19
|
gem "guard-rspec", "0.1.9"
|
data/features/Changelog.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
+
### 2.6.0.rc4 / 2011-05-01
|
2
|
+
|
3
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.6.0.rc2...v2.6.0.rc4)
|
4
|
+
|
5
|
+
* Bug fixes
|
6
|
+
* Support multiple calls to any_instance in the same example (Sidu Ponnappa)
|
7
|
+
|
1
8
|
### 2.6.0.rc2 / 2011-04-18
|
2
9
|
|
3
|
-
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.5.0...v2.6.
|
10
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.5.0...v2.6.0.rc2)
|
4
11
|
|
5
12
|
* Enhancements
|
6
13
|
* Add support for any_instance.stub and any_instance.should_receive (Sidu
|
data/features/Upgrade.md
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
-
|
1
|
+
## rspec-mocks-2.6
|
2
2
|
|
3
|
-
|
3
|
+
### `any_instance`
|
4
|
+
|
5
|
+
Set method stubs and message expectations on any instance of a class:
|
6
|
+
|
7
|
+
class Foo; end
|
8
|
+
Foo.any_instance.stub(:bar) { 'bar' }
|
9
|
+
Foo.new.bar # => 'bar'
|
10
|
+
|
11
|
+
## rspec-mocks-2.2
|
4
12
|
|
5
13
|
### `require "rspec/mocks/standalone"`
|
6
14
|
|
@@ -23,12 +23,12 @@ module RSpec
|
|
23
23
|
|
24
24
|
def constrained_to_any_of?(*constraints)
|
25
25
|
constraints.any? do |constraint|
|
26
|
-
messages.any? do |message|
|
26
|
+
messages.any? do |message|
|
27
27
|
message.first.first == constraint
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
private
|
33
33
|
def messages
|
34
34
|
@messages ||= []
|
@@ -90,11 +90,11 @@ module RSpec
|
|
90
90
|
def expectation_fulfilled!
|
91
91
|
@expectation_fulfilled = true
|
92
92
|
end
|
93
|
-
|
93
|
+
|
94
94
|
def expectation_filfilled?
|
95
95
|
@expectation_fulfilled || constrained_to_any_of?(:never, :any_number_of_times)
|
96
96
|
end
|
97
|
-
|
97
|
+
|
98
98
|
private
|
99
99
|
def verify_invocation_order(rspec_method_name, *args, &block)
|
100
100
|
end
|
@@ -120,7 +120,7 @@ module RSpec
|
|
120
120
|
@message_chains[method_name] = ExpectationChain.new(method_name, *args, &block)
|
121
121
|
end
|
122
122
|
|
123
|
-
def
|
123
|
+
def stop_all_observation!
|
124
124
|
@observed_methods.each do |method_name|
|
125
125
|
restore_method!(method_name)
|
126
126
|
end
|
@@ -136,36 +136,36 @@ module RSpec
|
|
136
136
|
def instance_that_received(method_name)
|
137
137
|
@played_methods[method_name]
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
def verify
|
141
141
|
if @expectation_set && !each_expectation_filfilled?
|
142
142
|
raise RSpec::Mocks::MockExpectationError, "Exactly one instance should have received the following message(s) but didn't: #{unfulfilled_expectations.sort.join(', ')}"
|
143
143
|
end
|
144
144
|
end
|
145
|
-
|
145
|
+
|
146
146
|
private
|
147
147
|
def each_expectation_filfilled?
|
148
148
|
@message_chains.all? do |method_name, chain|
|
149
149
|
chain.expectation_filfilled?
|
150
150
|
end
|
151
151
|
end
|
152
|
-
|
152
|
+
|
153
153
|
def has_expectation?(method_name)
|
154
154
|
@message_chains[method_name].is_a?(ExpectationChain)
|
155
155
|
end
|
156
|
-
|
156
|
+
|
157
157
|
def unfulfilled_expectations
|
158
158
|
@message_chains.map do |method_name, chain|
|
159
159
|
method_name.to_s if chain.is_a?(ExpectationChain) unless chain.expectation_filfilled?
|
160
160
|
end.compact
|
161
161
|
end
|
162
|
-
|
162
|
+
|
163
163
|
def received_expected_message!(method_name)
|
164
164
|
@message_chains[method_name].expectation_fulfilled!
|
165
165
|
restore_method!(method_name)
|
166
166
|
mark_invoked!(method_name)
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
169
|
def restore_method!(method_name)
|
170
170
|
if @klass.method_defined?(build_alias_method_name(method_name))
|
171
171
|
restore_original_method!(method_name)
|
@@ -173,7 +173,7 @@ module RSpec
|
|
173
173
|
remove_dummy_method!(method_name)
|
174
174
|
end
|
175
175
|
end
|
176
|
-
|
176
|
+
|
177
177
|
def build_alias_method_name(method_name)
|
178
178
|
"__#{method_name}_without_any_instance__"
|
179
179
|
end
|
@@ -200,8 +200,18 @@ module RSpec
|
|
200
200
|
end
|
201
201
|
end
|
202
202
|
end
|
203
|
-
|
203
|
+
|
204
|
+
def stop_observing!(method_name)
|
205
|
+
restore_method!(method_name)
|
206
|
+
@observed_methods.delete(method_name)
|
207
|
+
end
|
208
|
+
|
209
|
+
def already_observing?(method_name)
|
210
|
+
@observed_methods.include?(method_name)
|
211
|
+
end
|
212
|
+
|
204
213
|
def observe!(method_name)
|
214
|
+
stop_observing!(method_name) if already_observing?(method_name)
|
205
215
|
@observed_methods << method_name
|
206
216
|
backup_method!(method_name)
|
207
217
|
@klass.class_eval(<<-EOM, __FILE__, __LINE__)
|
@@ -234,7 +244,7 @@ module RSpec
|
|
234
244
|
__recorder.verify
|
235
245
|
super
|
236
246
|
ensure
|
237
|
-
__recorder.
|
247
|
+
__recorder.stop_all_observation!
|
238
248
|
@__recorder = nil
|
239
249
|
end
|
240
250
|
|
@@ -5,7 +5,7 @@ module RSpec
|
|
5
5
|
|
6
6
|
def initialize(*args, &block)
|
7
7
|
@args = args
|
8
|
-
@
|
8
|
+
@block = args.empty? ? block : nil
|
9
9
|
@match_any_args = false
|
10
10
|
@matchers = nil
|
11
11
|
|
@@ -26,19 +26,20 @@ module RSpec
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def is_matcher?(obj)
|
29
|
-
!
|
29
|
+
!null_object?(obj) & obj.respond_to?(:matches?) & obj.respond_to?(:description)
|
30
30
|
end
|
31
31
|
|
32
|
-
def
|
33
|
-
|
32
|
+
def args_match?(*args)
|
33
|
+
match_any_args? || block_passes?(*args) || matchers_match?(*args)
|
34
34
|
end
|
35
35
|
|
36
|
-
|
37
|
-
|
36
|
+
private
|
37
|
+
def null_object?(obj)
|
38
|
+
obj.respond_to?(:__rspec_double_acting_as_null_object?) && obj.__rspec_double_acting_as_null_object?
|
38
39
|
end
|
39
40
|
|
40
|
-
def
|
41
|
-
@
|
41
|
+
def block_passes?(*args)
|
42
|
+
@block.call(*args) if @block
|
42
43
|
end
|
43
44
|
|
44
45
|
def matchers_match?(*args)
|
@@ -1,7 +1,5 @@
|
|
1
1
|
module Marshal
|
2
|
-
|
3
2
|
class << self
|
4
|
-
|
5
3
|
def dump_with_mocks(*args)
|
6
4
|
object = args.shift
|
7
5
|
return dump_without_mocks(*args.unshift(object)) unless object.instance_variable_defined?(:@mock_proxy)
|
@@ -21,7 +19,5 @@ module Marshal
|
|
21
19
|
alias_method :dump_without_mocks, :dump
|
22
20
|
undef_method :dump
|
23
21
|
alias_method :dump, :dump_with_mocks
|
24
|
-
|
25
22
|
end
|
26
|
-
|
27
23
|
end
|
data/lib/rspec/mocks/version.rb
CHANGED
@@ -8,7 +8,7 @@ module RSpec
|
|
8
8
|
let(:klass) do
|
9
9
|
Class.new do
|
10
10
|
def existing_method; :existing_method_return_value; end
|
11
|
-
def another_existing_method;
|
11
|
+
def another_existing_method; end
|
12
12
|
end
|
13
13
|
end
|
14
14
|
let(:existing_method_return_value){ :existing_method_return_value }
|
@@ -54,21 +54,21 @@ module RSpec
|
|
54
54
|
klass.any_instance.stub(:foo)
|
55
55
|
lambda{ klass.new.bar }.should raise_error(NoMethodError)
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
context "behaves as 'every instance'" do
|
59
59
|
it "stubs every instance in the spec" do
|
60
60
|
klass.any_instance.stub(:foo).and_return(result = Object.new)
|
61
61
|
klass.new.foo.should eq(result)
|
62
62
|
klass.new.foo.should eq(result)
|
63
63
|
end
|
64
|
-
|
64
|
+
|
65
65
|
it "stubs instance created before any_instance was called" do
|
66
66
|
instance = klass.new
|
67
67
|
klass.any_instance.stub(:foo).and_return(result = Object.new)
|
68
68
|
instance.foo.should eq(result)
|
69
69
|
end
|
70
70
|
end
|
71
|
-
|
71
|
+
|
72
72
|
context "with #and_return" do
|
73
73
|
it "stubs a method that doesn't exist" do
|
74
74
|
klass.any_instance.stub(:foo).and_return(1)
|
@@ -196,12 +196,12 @@ module RSpec
|
|
196
196
|
it "allows expectations on instances to take priority" do
|
197
197
|
klass.any_instance.should_receive(:foo)
|
198
198
|
klass.new.foo
|
199
|
-
|
199
|
+
|
200
200
|
instance = klass.new
|
201
201
|
instance.should_receive(:foo).and_return(result = Object.new)
|
202
202
|
instance.foo.should eq(result)
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
context "behaves as 'exactly one instance'" do
|
206
206
|
it "passes if subsequent invocations do not receive that message" do
|
207
207
|
klass.any_instance.should_receive(:foo)
|
@@ -220,7 +220,7 @@ module RSpec
|
|
220
220
|
end.to raise_error(RSpec::Mocks::MockExpectationError, "The message 'foo' was received by #{instance_two.inspect} but has already been received by #{instance_one.inspect}")
|
221
221
|
end
|
222
222
|
end
|
223
|
-
|
223
|
+
|
224
224
|
context "normal expectations on the class object" do
|
225
225
|
it "fail when unfulfilled" do
|
226
226
|
expect do
|
@@ -232,8 +232,8 @@ module RSpec
|
|
232
232
|
error.message.should_not eq(existing_method_expectation_error_message)
|
233
233
|
end)
|
234
234
|
end
|
235
|
-
|
236
|
-
|
235
|
+
|
236
|
+
|
237
237
|
it "pass when expectations are met" do
|
238
238
|
klass.any_instance.should_receive(:foo)
|
239
239
|
klass.should_receive(:woot).and_return(result = Object.new)
|
@@ -483,18 +483,18 @@ module RSpec
|
|
483
483
|
|
484
484
|
context "when resetting post-verification" do
|
485
485
|
let(:space) { RSpec::Mocks::Space.new }
|
486
|
-
|
486
|
+
|
487
487
|
context "existing method" do
|
488
488
|
before(:each) do
|
489
489
|
space.add(klass)
|
490
490
|
end
|
491
|
-
|
491
|
+
|
492
492
|
context "with stubbing" do
|
493
493
|
before(:each) do
|
494
494
|
klass.any_instance.stub(:existing_method).and_return(1)
|
495
495
|
klass.method_defined?(:__existing_method_without_any_instance__).should be_true
|
496
496
|
end
|
497
|
-
|
497
|
+
|
498
498
|
it "restores the class to its original state after each example when no instance is created" do
|
499
499
|
space.verify_all
|
500
500
|
|
@@ -521,7 +521,7 @@ module RSpec
|
|
521
521
|
klass.new.existing_method.should eq(existing_method_return_value)
|
522
522
|
end
|
523
523
|
end
|
524
|
-
|
524
|
+
|
525
525
|
context "with expectations" do
|
526
526
|
context "ensures that the subsequent specs do not see expectations set in previous specs" do
|
527
527
|
context "when the instance created after the expectation is set" do
|
@@ -529,28 +529,28 @@ module RSpec
|
|
529
529
|
klass.any_instance.should_receive(:existing_method).and_return(Object.new)
|
530
530
|
klass.new.existing_method
|
531
531
|
end
|
532
|
-
|
532
|
+
|
533
533
|
it "second spec" do
|
534
534
|
klass.new.existing_method.should eq(existing_method_return_value)
|
535
535
|
end
|
536
536
|
end
|
537
|
-
|
537
|
+
|
538
538
|
context "when the instance created before the expectation is set" do
|
539
539
|
before :each do
|
540
540
|
@instance = klass.new
|
541
541
|
end
|
542
|
-
|
542
|
+
|
543
543
|
it "first spec" do
|
544
544
|
klass.any_instance.should_receive(:existing_method).and_return(Object.new)
|
545
545
|
@instance.existing_method
|
546
546
|
end
|
547
|
-
|
547
|
+
|
548
548
|
it "second spec" do
|
549
549
|
@instance.existing_method.should eq(existing_method_return_value)
|
550
550
|
end
|
551
551
|
end
|
552
552
|
end
|
553
|
-
|
553
|
+
|
554
554
|
it "ensures that the next spec does not see that expectation" do
|
555
555
|
klass.any_instance.should_receive(:existing_method).and_return(Object.new)
|
556
556
|
klass.new.existing_method
|
@@ -561,6 +561,17 @@ module RSpec
|
|
561
561
|
end
|
562
562
|
end
|
563
563
|
|
564
|
+
context "with multiple calls to any_instance in the same example" do
|
565
|
+
it "does not prevent the change from being rolled back" do
|
566
|
+
klass.any_instance.stub(:existing_method).and_return(false)
|
567
|
+
klass.any_instance.stub(:existing_method).and_return(true)
|
568
|
+
|
569
|
+
klass.rspec_verify
|
570
|
+
klass.new.should respond_to(:existing_method)
|
571
|
+
klass.new.existing_method.should eq(existing_method_return_value)
|
572
|
+
end
|
573
|
+
end
|
574
|
+
|
564
575
|
it "adds an class to the current space when #any_instance is invoked" do
|
565
576
|
klass.any_instance
|
566
577
|
RSpec::Mocks::space.send(:mocks).should include(klass)
|
@@ -573,6 +584,7 @@ module RSpec
|
|
573
584
|
RSpec::Mocks::space.send(:mocks).should include(instance)
|
574
585
|
end
|
575
586
|
end
|
587
|
+
|
576
588
|
end
|
577
589
|
end
|
578
590
|
end
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-mocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15424061
|
5
5
|
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 6
|
9
9
|
- 0
|
10
10
|
- rc
|
11
|
-
-
|
12
|
-
version: 2.6.0.
|
11
|
+
- 4
|
12
|
+
version: 2.6.0.rc4
|
13
13
|
platform: ruby
|
14
14
|
authors:
|
15
15
|
- David Chelimsky
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2011-
|
21
|
+
date: 2011-05-01 00:00:00 -04:00
|
22
22
|
default_executable:
|
23
23
|
dependencies: []
|
24
24
|
|
@@ -161,10 +161,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
161
|
requirements: []
|
162
162
|
|
163
163
|
rubyforge_project: rspec
|
164
|
-
rubygems_version: 1.
|
164
|
+
rubygems_version: 1.6.2
|
165
165
|
signing_key:
|
166
166
|
specification_version: 3
|
167
|
-
summary: rspec-mocks-2.6.0.
|
167
|
+
summary: rspec-mocks-2.6.0.rc4
|
168
168
|
test_files:
|
169
169
|
- features/Changelog.md
|
170
170
|
- features/README.markdown
|