rspec-mocks 2.8.0 → 2.9.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.yardopts +7 -0
- data/Changelog.md +147 -0
- data/features/method_stubs/as_null_object.feature +0 -1
- data/features/step_definitions/additional_cli_steps.rb +2 -2
- data/lib/rspec/mocks/argument_expectation.rb +9 -12
- data/lib/rspec/mocks/argument_matchers.rb +1 -1
- data/lib/rspec/mocks/error_generator.rb +10 -10
- data/lib/rspec/mocks/extensions/psych.rb +1 -1
- data/lib/rspec/mocks/message_expectation.rb +38 -33
- data/lib/rspec/mocks/methods.rb +4 -3
- data/lib/rspec/mocks/mock.rb +6 -6
- data/lib/rspec/mocks/order_group.rb +13 -6
- data/lib/rspec/mocks/proxy.rb +15 -15
- data/lib/rspec/mocks/serialization.rb +2 -0
- data/lib/rspec/mocks/space.rb +12 -7
- data/lib/rspec/mocks/version.rb +1 -1
- data/spec/rspec/mocks/any_instance_spec.rb +2 -2
- data/spec/rspec/mocks/argument_expectation_spec.rb +2 -5
- data/spec/rspec/mocks/bug_report_11545_spec.rb +2 -2
- data/spec/rspec/mocks/bug_report_8165_spec.rb +5 -5
- data/spec/rspec/mocks/mock_ordering_spec.rb +36 -27
- data/spec/rspec/mocks/mock_space_spec.rb +5 -1
- data/spec/rspec/mocks/mock_spec.rb +42 -29
- data/spec/rspec/mocks/serialization_spec.rb +0 -1
- data/spec/rspec/mocks/stubbed_message_expectations_spec.rb +41 -20
- metadata +70 -17
data/.document
ADDED
data/.yardopts
ADDED
data/Changelog.md
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
### 2.9.0.rc2 / 2012-03-12
|
2
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.8.0...v2.9.0.rc2)
|
3
|
+
|
4
|
+
Enhancements
|
5
|
+
|
6
|
+
* Support order constraints across objects (preethiramdev)
|
7
|
+
|
8
|
+
Bug fixes
|
9
|
+
|
10
|
+
* Allow a `as_null_object` to be passed to `with`
|
11
|
+
* Pass proc to block passed to stub (Aubrey Rhodes)
|
12
|
+
* Initialize child message expectation args to match any args (#109 -
|
13
|
+
preethiramdev)
|
14
|
+
|
15
|
+
### 2.8.0 / 2012-01-04
|
16
|
+
|
17
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.8.0.rc2...v2.8.0)
|
18
|
+
|
19
|
+
No changes for this release. Just releasing with the other rspec gems.
|
20
|
+
|
21
|
+
### 2.8.0.rc2 / 2011-12-19
|
22
|
+
|
23
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.8.0.rc1...v2.8.0.rc2)
|
24
|
+
|
25
|
+
No changes for this release. Just releasing with the other rspec gems.
|
26
|
+
|
27
|
+
### 2.8.0.rc1 / 2011-11-06
|
28
|
+
|
29
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.7.0...v2.8.0.rc1)
|
30
|
+
|
31
|
+
Enhancements
|
32
|
+
|
33
|
+
* Eliminate Ruby warnings (Matijs van Zuijlen)
|
34
|
+
|
35
|
+
### 2.7.0 / 2011-10-16
|
36
|
+
|
37
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.6.0...v2.7.0)
|
38
|
+
|
39
|
+
Enhancements
|
40
|
+
|
41
|
+
* Use `__send__` rather than `send` (alextk)
|
42
|
+
* Add support for `any_instance.stub_chain` (Sidu Ponnappa)
|
43
|
+
* Add support for `any_instance` argument matching based on `with` (Sidu
|
44
|
+
Ponnappa and Andy Lindeman)
|
45
|
+
|
46
|
+
Changes
|
47
|
+
|
48
|
+
* Check for `failure_message_for_should` or `failure_message` instead of
|
49
|
+
`description` to detect a matcher (Tibor Claassen)
|
50
|
+
|
51
|
+
Bug fixes
|
52
|
+
|
53
|
+
* pass a hash to `any_instance.stub`. (Justin Ko)
|
54
|
+
* allow `to_ary` to be called without raising `NoMethodError` (Mikhail
|
55
|
+
Dieterle)
|
56
|
+
* `any_instance` properly restores private methods (Sidu Ponnappa)
|
57
|
+
|
58
|
+
### 2.6.0 / 2011-05-12
|
59
|
+
|
60
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.5.0...v2.6.0)
|
61
|
+
|
62
|
+
Enhancements
|
63
|
+
|
64
|
+
* Add support for `any_instance.stub` and `any_instance.should_receive` (Sidu
|
65
|
+
Ponnappa and Andy Lindeman)
|
66
|
+
|
67
|
+
Bug fixes
|
68
|
+
|
69
|
+
* fix bug in which multiple chains with shared messages ending in hashes failed
|
70
|
+
to return the correct value
|
71
|
+
|
72
|
+
### 2.5.0 / 2011-02-05
|
73
|
+
|
74
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.4.0...v2.5.0)
|
75
|
+
|
76
|
+
Bug fixes
|
77
|
+
|
78
|
+
* message expectation counts now work in combination with a stub (Damian
|
79
|
+
Nurzynski)
|
80
|
+
* fix failure message when message received with incorrect args (Josep M.
|
81
|
+
Bach)
|
82
|
+
|
83
|
+
### 2.4.0 / 2011-01-02
|
84
|
+
|
85
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.3.0...v2.4.0)
|
86
|
+
|
87
|
+
No functional changes in this release, which was made to align with the
|
88
|
+
rspec-core-2.4.0 release.
|
89
|
+
|
90
|
+
### 2.3.0 / 2010-12-12
|
91
|
+
|
92
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.2.0...v2.3.0)
|
93
|
+
|
94
|
+
Bug fixes
|
95
|
+
|
96
|
+
* Fix our Marshal extension so that it does not interfere with objects that
|
97
|
+
have their own `@mock_proxy` instance variable. (Myron Marston)
|
98
|
+
|
99
|
+
### 2.2.0 / 2010-11-28
|
100
|
+
|
101
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.1.0...v2.2.0)
|
102
|
+
|
103
|
+
Enhancements
|
104
|
+
|
105
|
+
* Added "rspec/mocks/standalone" for exploring the rspec-mocks in irb.
|
106
|
+
|
107
|
+
Bug fix
|
108
|
+
|
109
|
+
* Eliminate warning on splat args without parens (Gioele Barabucci)
|
110
|
+
* Fix bug where `obj.should_receive(:foo).with(stub.as_null_object)` would pass
|
111
|
+
with a false positive.
|
112
|
+
|
113
|
+
### 2.1.0 / 2010-11-07
|
114
|
+
|
115
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.1...v2.1.0)
|
116
|
+
|
117
|
+
Bug fixes
|
118
|
+
|
119
|
+
* Fix serialization of stubbed object (Josep M Bach)
|
120
|
+
|
121
|
+
### 2.0.0 / 2010-10-10
|
122
|
+
|
123
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.22...v2.0.0)
|
124
|
+
|
125
|
+
### 2.0.0.rc / 2010-10-05
|
126
|
+
|
127
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.22...v2.0.0.rc)
|
128
|
+
|
129
|
+
Enhancements
|
130
|
+
|
131
|
+
* support passing a block to an expectation block (Nicolas Braem)
|
132
|
+
* `obj.should_receive(:msg) {|&block| ... }`
|
133
|
+
|
134
|
+
Bug fixes
|
135
|
+
|
136
|
+
* Fix YAML serialization of stub (Myron Marston)
|
137
|
+
* Fix rdoc rake task (Hans de Graaff)
|
138
|
+
|
139
|
+
### 2.0.0.beta.22 / 2010-09-12
|
140
|
+
|
141
|
+
[full changelog](http://github.com/rspec/rspec-mocks/compare/v2.0.0.beta.20...v2.0.0.beta.22)
|
142
|
+
|
143
|
+
Bug fixes
|
144
|
+
|
145
|
+
* fixed regression that broke `obj.stub_chain(:a, :b => :c)`
|
146
|
+
* fixed regression that broke `obj.stub_chain(:a, :b) { :c }`
|
147
|
+
* `respond_to?` always returns true when using `as_null_object`
|
@@ -3,13 +3,13 @@ module RSpec
|
|
3
3
|
# @api private
|
4
4
|
class ArgumentExpectation
|
5
5
|
attr_reader :args
|
6
|
-
|
6
|
+
|
7
7
|
def initialize(*args, &block)
|
8
8
|
@args = args
|
9
9
|
@block = args.empty? ? block : nil
|
10
10
|
@match_any_args = false
|
11
11
|
@matchers = nil
|
12
|
-
|
12
|
+
|
13
13
|
case args.first
|
14
14
|
when ArgumentMatchers::AnyArgsMatcher
|
15
15
|
@match_any_args = true
|
@@ -19,34 +19,31 @@ module RSpec
|
|
19
19
|
@matchers = args.collect {|arg| matcher_for(arg)}
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def matcher_for(arg)
|
24
24
|
return ArgumentMatchers::MatcherMatcher.new(arg) if is_matcher?(arg)
|
25
25
|
return ArgumentMatchers::RegexpMatcher.new(arg) if arg.is_a?(Regexp)
|
26
26
|
return ArgumentMatchers::EqualityProxy.new(arg)
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def is_matcher?(obj)
|
30
|
-
!null_object?
|
30
|
+
!obj.null_object? & obj.respond_to?(:matches?) & [:failure_message_for_should, :failure_message].any? { |m| obj.respond_to?(m) }
|
31
31
|
end
|
32
32
|
|
33
33
|
def args_match?(*args)
|
34
34
|
match_any_args? || block_passes?(*args) || matchers_match?(*args)
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
private
|
38
|
-
|
39
|
-
obj.respond_to?(:__rspec_double_acting_as_null_object?) && obj.__rspec_double_acting_as_null_object?
|
40
|
-
end
|
41
|
-
|
38
|
+
|
42
39
|
def block_passes?(*args)
|
43
40
|
@block.call(*args) if @block
|
44
41
|
end
|
45
|
-
|
42
|
+
|
46
43
|
def matchers_match?(*args)
|
47
44
|
@matchers == args
|
48
45
|
end
|
49
|
-
|
46
|
+
|
50
47
|
def match_any_args?
|
51
48
|
@match_any_args
|
52
49
|
end
|
@@ -16,37 +16,37 @@ module RSpec
|
|
16
16
|
end
|
17
17
|
|
18
18
|
# @private
|
19
|
-
def raise_unexpected_message_error(
|
20
|
-
__raise "#{intro} received unexpected message :#{
|
19
|
+
def raise_unexpected_message_error(message, *args)
|
20
|
+
__raise "#{intro} received unexpected message :#{message}#{arg_message(*args)}"
|
21
21
|
end
|
22
22
|
|
23
23
|
# @private
|
24
24
|
def raise_unexpected_message_args_error(expectation, *args)
|
25
25
|
expected_args = format_args(*expectation.expected_args)
|
26
26
|
actual_args = format_args(*args)
|
27
|
-
__raise "#{intro} received #{expectation.
|
27
|
+
__raise "#{intro} received #{expectation.message.inspect} with unexpected arguments\n expected: #{expected_args}\n got: #{actual_args}"
|
28
28
|
end
|
29
29
|
|
30
30
|
# @private
|
31
31
|
def raise_similar_message_args_error(expectation, *args)
|
32
32
|
expected_args = format_args(*expectation.expected_args)
|
33
33
|
actual_args = args.collect {|a| format_args(*a)}.join(", ")
|
34
|
-
__raise "#{intro} received #{expectation.
|
34
|
+
__raise "#{intro} received #{expectation.message.inspect} with unexpected arguments\n expected: #{expected_args}\n got: #{actual_args}"
|
35
35
|
end
|
36
36
|
|
37
37
|
# @private
|
38
|
-
def raise_expectation_error(
|
39
|
-
__raise "(#{intro}).#{
|
38
|
+
def raise_expectation_error(message, expected_received_count, actual_received_count, *args)
|
39
|
+
__raise "(#{intro}).#{message}#{format_args(*args)}\n expected: #{count_message(expected_received_count)}\n received: #{count_message(actual_received_count)}"
|
40
40
|
end
|
41
41
|
|
42
42
|
# @private
|
43
|
-
def raise_out_of_order_error(
|
44
|
-
__raise "#{intro} received :#{
|
43
|
+
def raise_out_of_order_error(message)
|
44
|
+
__raise "#{intro} received :#{message} out of order"
|
45
45
|
end
|
46
46
|
|
47
47
|
# @private
|
48
|
-
def raise_block_failed_error(
|
49
|
-
__raise "#{intro} received :#{
|
48
|
+
def raise_block_failed_error(message, detail)
|
49
|
+
__raise "#{intro} received :#{message} but passed block failed with: #{detail}"
|
50
50
|
end
|
51
51
|
|
52
52
|
# @private
|
@@ -3,23 +3,23 @@ module RSpec
|
|
3
3
|
|
4
4
|
class MessageExpectation
|
5
5
|
# @private
|
6
|
-
attr_reader :
|
7
|
-
attr_writer :expected_received_count, :method_block, :expected_from
|
6
|
+
attr_reader :message
|
7
|
+
attr_writer :expected_received_count, :method_block, :expected_from, :argument_expectation
|
8
8
|
protected :expected_received_count=, :method_block=, :expected_from=
|
9
9
|
attr_accessor :error_generator
|
10
10
|
protected :error_generator, :error_generator=
|
11
11
|
|
12
12
|
# @private
|
13
|
-
def initialize(error_generator, expectation_ordering, expected_from,
|
13
|
+
def initialize(error_generator, expectation_ordering, expected_from, message, method_block, expected_received_count=1, opts={}, &implementation)
|
14
14
|
@error_generator = error_generator
|
15
15
|
@error_generator.opts = opts
|
16
16
|
@expected_from = expected_from
|
17
|
-
@
|
17
|
+
@message = message
|
18
18
|
@method_block = method_block
|
19
19
|
@return_block = nil
|
20
20
|
@actual_received_count = 0
|
21
21
|
@expected_received_count = expected_received_count
|
22
|
-
@
|
22
|
+
@argument_expectation = ArgumentExpectation.new(ArgumentMatchers::AnyArgsMatcher.new)
|
23
23
|
@consecutive = false
|
24
24
|
@exception_to_raise = nil
|
25
25
|
@args_to_throw = []
|
@@ -45,12 +45,13 @@ module RSpec
|
|
45
45
|
new_gen.opts = opts
|
46
46
|
child.error_generator = new_gen
|
47
47
|
child.clone_args_to_yield(*@args_to_yield)
|
48
|
+
child.argument_expectation = ArgumentExpectation.new(ArgumentMatchers::AnyArgsMatcher.new)
|
48
49
|
child
|
49
50
|
end
|
50
51
|
|
51
52
|
# @private
|
52
53
|
def expected_args
|
53
|
-
@
|
54
|
+
@argument_expectation.args
|
54
55
|
end
|
55
56
|
|
56
57
|
# @overload and_return(value)
|
@@ -163,8 +164,8 @@ module RSpec
|
|
163
164
|
end
|
164
165
|
|
165
166
|
# @private
|
166
|
-
def matches?(
|
167
|
-
@
|
167
|
+
def matches?(message, *args)
|
168
|
+
@message == message and @argument_expectation.args_match?(*args)
|
168
169
|
end
|
169
170
|
|
170
171
|
# @private
|
@@ -172,13 +173,20 @@ module RSpec
|
|
172
173
|
if @expected_received_count == 0
|
173
174
|
@failed_fast = true
|
174
175
|
@actual_received_count += 1
|
175
|
-
@error_generator.raise_expectation_error(@
|
176
|
+
@error_generator.raise_expectation_error(@message, @expected_received_count, @actual_received_count, *args)
|
176
177
|
end
|
177
178
|
|
178
179
|
@order_group.handle_order_constraint self
|
179
180
|
|
180
181
|
begin
|
181
|
-
|
182
|
+
begin
|
183
|
+
raise(@exception_to_raise) unless @exception_to_raise.nil?
|
184
|
+
rescue ArgumentError => e
|
185
|
+
raise e.exception(<<-MESSAGE)
|
186
|
+
'and_raise' can only accept an Exception class if an instance can be constructed with no arguments.
|
187
|
+
#{@exception_to_raise.to_s}'s initialize method requires #{@exception_to_raise.instance_method(:initialize).arity} arguments, so you have to supply an instance instead.
|
188
|
+
MESSAGE
|
189
|
+
end
|
182
190
|
Kernel::throw(*@args_to_throw) unless @args_to_throw.empty?
|
183
191
|
|
184
192
|
default_return_val = if !@method_block.nil?
|
@@ -208,8 +216,8 @@ module RSpec
|
|
208
216
|
end
|
209
217
|
|
210
218
|
# @private
|
211
|
-
def matches_name_but_not_args(
|
212
|
-
@
|
219
|
+
def matches_name_but_not_args(message, *args)
|
220
|
+
@message == message and not @argument_expectation.args_match?(*args)
|
213
221
|
end
|
214
222
|
|
215
223
|
# @private
|
@@ -258,12 +266,16 @@ module RSpec
|
|
258
266
|
# @private
|
259
267
|
def generate_error
|
260
268
|
if similar_messages.empty?
|
261
|
-
@error_generator.raise_expectation_error(@
|
269
|
+
@error_generator.raise_expectation_error(@message, @expected_received_count, @actual_received_count, *@argument_expectation.args)
|
262
270
|
else
|
263
271
|
@error_generator.raise_similar_message_args_error(self, *@similar_messages)
|
264
272
|
end
|
265
273
|
end
|
266
274
|
|
275
|
+
def raise_out_of_order_error
|
276
|
+
@error_generator.raise_out_of_order_error @message
|
277
|
+
end
|
278
|
+
|
267
279
|
# Constrains a stub or message expectation to invocations with specific
|
268
280
|
# arguments.
|
269
281
|
#
|
@@ -290,7 +302,7 @@ module RSpec
|
|
290
302
|
# # => passes
|
291
303
|
def with(*args, &block)
|
292
304
|
@return_block = block if block_given? unless args.empty?
|
293
|
-
@
|
305
|
+
@argument_expectation = ArgumentExpectation.new(*args, &block)
|
294
306
|
self
|
295
307
|
end
|
296
308
|
|
@@ -397,7 +409,7 @@ module RSpec
|
|
397
409
|
end
|
398
410
|
|
399
411
|
# @private
|
400
|
-
def negative_expectation_for?(
|
412
|
+
def negative_expectation_for?(message)
|
401
413
|
return false
|
402
414
|
end
|
403
415
|
|
@@ -417,7 +429,7 @@ module RSpec
|
|
417
429
|
begin
|
418
430
|
@method_block.call(*args, &block)
|
419
431
|
rescue => detail
|
420
|
-
@error_generator.raise_block_failed_error(@
|
432
|
+
@error_generator.raise_block_failed_error(@message, detail.message)
|
421
433
|
end
|
422
434
|
end
|
423
435
|
|
@@ -450,11 +462,7 @@ module RSpec
|
|
450
462
|
end
|
451
463
|
|
452
464
|
def invoke_return_block(*args, &block)
|
453
|
-
|
454
|
-
# Ruby 1.9 - when we set @return_block to return values
|
455
|
-
# regardless of arguments, any arguments will result in
|
456
|
-
# a "wrong number of arguments" error
|
457
|
-
@return_block.arity == 0 ? @return_block.call : @return_block.call(*args)
|
465
|
+
@return_block.arity == 0 ? @return_block.call(&block) : @return_block.call(*args, &block)
|
458
466
|
end
|
459
467
|
|
460
468
|
def clone_args_to_yield(*args)
|
@@ -468,15 +476,12 @@ module RSpec
|
|
468
476
|
|
469
477
|
def set_expected_received_count(relativity, n)
|
470
478
|
@at_least = (relativity == :at_least)
|
471
|
-
@at_most
|
472
|
-
@exactly
|
479
|
+
@at_most = (relativity == :at_most)
|
480
|
+
@exactly = (relativity == :exactly)
|
473
481
|
@expected_received_count = case n
|
474
|
-
when Numeric
|
475
|
-
|
476
|
-
when :
|
477
|
-
1
|
478
|
-
when :twice
|
479
|
-
2
|
482
|
+
when Numeric then n
|
483
|
+
when :once then 1
|
484
|
+
when :twice then 2
|
480
485
|
end
|
481
486
|
end
|
482
487
|
|
@@ -488,13 +493,13 @@ module RSpec
|
|
488
493
|
# @private
|
489
494
|
class NegativeMessageExpectation < MessageExpectation
|
490
495
|
# @private
|
491
|
-
def initialize(
|
492
|
-
super(
|
496
|
+
def initialize(error_generator, expectation_ordering, expected_from, message, method_block)
|
497
|
+
super(error_generator, expectation_ordering, expected_from, message, method_block, 0)
|
493
498
|
end
|
494
499
|
|
495
500
|
# @private
|
496
|
-
def negative_expectation_for?(
|
497
|
-
return @
|
501
|
+
def negative_expectation_for?(message)
|
502
|
+
return @message == message
|
498
503
|
end
|
499
504
|
end
|
500
505
|
end
|
data/lib/rspec/mocks/methods.rb
CHANGED
@@ -97,17 +97,18 @@ module RSpec
|
|
97
97
|
# are declared, they'll work as expected. If not, the receiver is
|
98
98
|
# returned.
|
99
99
|
def as_null_object
|
100
|
+
@_null_object = true
|
100
101
|
__mock_proxy.as_null_object
|
101
102
|
end
|
102
103
|
|
103
104
|
# Returns true if this object has received `as_null_object`
|
104
105
|
def null_object?
|
105
|
-
|
106
|
+
defined?(@_null_object)
|
106
107
|
end
|
107
108
|
|
108
109
|
# @private
|
109
|
-
def received_message?(
|
110
|
-
__mock_proxy.received_message?(
|
110
|
+
def received_message?(message, *args, &block)
|
111
|
+
__mock_proxy.received_message?(message, *args, &block)
|
111
112
|
end
|
112
113
|
|
113
114
|
# @private
|
data/lib/rspec/mocks/mock.rb
CHANGED
@@ -37,19 +37,19 @@ module RSpec
|
|
37
37
|
alias_method :to_str, :to_s
|
38
38
|
|
39
39
|
# @private
|
40
|
-
def respond_to?(
|
41
|
-
__mock_proxy.null_object? &&
|
40
|
+
def respond_to?(message, incl_private=false)
|
41
|
+
__mock_proxy.null_object? && message != :to_ary ? true : super
|
42
42
|
end
|
43
43
|
|
44
44
|
private
|
45
45
|
|
46
|
-
def method_missing(
|
47
|
-
raise NoMethodError if
|
48
|
-
__mock_proxy.record_message_received(
|
46
|
+
def method_missing(message, *args, &block)
|
47
|
+
raise NoMethodError if message == :to_ary
|
48
|
+
__mock_proxy.record_message_received(message, *args, &block)
|
49
49
|
begin
|
50
50
|
__mock_proxy.null_object? ? self : super
|
51
51
|
rescue NameError
|
52
|
-
__mock_proxy.raise_unexpected_message_error(
|
52
|
+
__mock_proxy.raise_unexpected_message_error(message, *args)
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
@@ -2,8 +2,7 @@ module RSpec
|
|
2
2
|
module Mocks
|
3
3
|
# @private
|
4
4
|
class OrderGroup
|
5
|
-
def initialize
|
6
|
-
@error_generator = error_generator
|
5
|
+
def initialize
|
7
6
|
@ordering = Array.new
|
8
7
|
end
|
9
8
|
|
@@ -14,7 +13,7 @@ module RSpec
|
|
14
13
|
|
15
14
|
# @private
|
16
15
|
def ready_for?(expectation)
|
17
|
-
|
16
|
+
@ordering.first == expectation
|
18
17
|
end
|
19
18
|
|
20
19
|
# @private
|
@@ -23,10 +22,18 @@ module RSpec
|
|
23
22
|
end
|
24
23
|
|
25
24
|
# @private
|
26
|
-
def handle_order_constraint
|
27
|
-
return unless @ordering.include?
|
25
|
+
def handle_order_constraint(expectation)
|
26
|
+
return unless @ordering.include?(expectation)
|
28
27
|
return consume if ready_for?(expectation)
|
29
|
-
|
28
|
+
expectation.raise_out_of_order_error
|
29
|
+
end
|
30
|
+
|
31
|
+
def clear
|
32
|
+
@ordering.clear
|
33
|
+
end
|
34
|
+
|
35
|
+
def empty?
|
36
|
+
@ordering.empty?
|
30
37
|
end
|
31
38
|
end
|
32
39
|
end
|
data/lib/rspec/mocks/proxy.rb
CHANGED
@@ -33,8 +33,8 @@ module RSpec
|
|
33
33
|
@object = object
|
34
34
|
@name = name
|
35
35
|
@error_generator = ErrorGenerator.new object, name, options
|
36
|
-
@expectation_ordering =
|
37
|
-
|
36
|
+
@expectation_ordering = RSpec::Mocks::space.expectation_ordering
|
37
|
+
@messages_received = []
|
38
38
|
@options = options
|
39
39
|
@already_proxied_respond_to = false
|
40
40
|
@null_object = false
|
@@ -101,38 +101,38 @@ module RSpec
|
|
101
101
|
end
|
102
102
|
|
103
103
|
# @private
|
104
|
-
def has_negative_expectation?(
|
105
|
-
method_double[
|
104
|
+
def has_negative_expectation?(message)
|
105
|
+
method_double[message].expectations.detect {|expectation| expectation.negative_expectation_for?(message)}
|
106
106
|
end
|
107
107
|
|
108
108
|
# @private
|
109
|
-
def record_message_received(
|
110
|
-
@messages_received << [
|
109
|
+
def record_message_received(message, *args, &block)
|
110
|
+
@messages_received << [message, args, block]
|
111
111
|
end
|
112
112
|
|
113
113
|
# @private
|
114
|
-
def message_received(
|
115
|
-
expectation = find_matching_expectation(
|
116
|
-
stub = find_matching_method_stub(
|
114
|
+
def message_received(message, *args, &block)
|
115
|
+
expectation = find_matching_expectation(message, *args)
|
116
|
+
stub = find_matching_method_stub(message, *args)
|
117
117
|
|
118
118
|
if (stub && expectation && expectation.called_max_times?) || (stub && !expectation)
|
119
119
|
expectation.increase_actual_received_count! if expectation && expectation.actual_received_count_matters?
|
120
|
-
if expectation = find_almost_matching_expectation(
|
120
|
+
if expectation = find_almost_matching_expectation(message, *args)
|
121
121
|
expectation.advise(*args) unless expectation.expected_messages_received?
|
122
122
|
end
|
123
123
|
stub.invoke(*args, &block)
|
124
124
|
elsif expectation
|
125
125
|
expectation.invoke(*args, &block)
|
126
|
-
elsif expectation = find_almost_matching_expectation(
|
126
|
+
elsif expectation = find_almost_matching_expectation(message, *args)
|
127
127
|
expectation.advise(*args) if null_object? unless expectation.expected_messages_received?
|
128
|
-
raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(
|
129
|
-
elsif stub = find_almost_matching_stub(
|
128
|
+
raise_unexpected_message_args_error(expectation, *args) unless (has_negative_expectation?(message) or null_object?)
|
129
|
+
elsif stub = find_almost_matching_stub(message, *args)
|
130
130
|
stub.advise(*args)
|
131
131
|
raise_unexpected_message_args_error(stub, *args)
|
132
132
|
elsif @object.is_a?(Class)
|
133
|
-
@object.superclass.__send__(
|
133
|
+
@object.superclass.__send__(message, *args, &block)
|
134
134
|
else
|
135
|
-
@object.__send__(:method_missing,
|
135
|
+
@object.__send__(:method_missing, message, *args, &block)
|
136
136
|
end
|
137
137
|
end
|
138
138
|
|
data/lib/rspec/mocks/space.rb
CHANGED
@@ -3,26 +3,31 @@ module RSpec
|
|
3
3
|
# @api private
|
4
4
|
class Space
|
5
5
|
def add(obj)
|
6
|
-
|
6
|
+
receivers << obj unless receivers.detect {|m| m.equal? obj}
|
7
7
|
end
|
8
8
|
|
9
9
|
def verify_all
|
10
|
-
|
10
|
+
receivers.each do |mock|
|
11
11
|
mock.rspec_verify
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
15
|
def reset_all
|
16
|
-
|
16
|
+
receivers.each do |mock|
|
17
17
|
mock.rspec_reset
|
18
18
|
end
|
19
|
-
|
19
|
+
receivers.clear
|
20
|
+
expectation_ordering.clear
|
20
21
|
end
|
21
|
-
|
22
|
+
|
23
|
+
def expectation_ordering
|
24
|
+
@expectation_ordering ||= OrderGroup.new
|
25
|
+
end
|
26
|
+
|
22
27
|
private
|
23
28
|
|
24
|
-
def
|
25
|
-
@
|
29
|
+
def receivers
|
30
|
+
@receivers ||= []
|
26
31
|
end
|
27
32
|
end
|
28
33
|
end
|
data/lib/rspec/mocks/version.rb
CHANGED
@@ -769,14 +769,14 @@ module RSpec
|
|
769
769
|
|
770
770
|
it "adds an class to the current space when #any_instance is invoked" do
|
771
771
|
klass.any_instance
|
772
|
-
RSpec::Mocks::space.send(:
|
772
|
+
RSpec::Mocks::space.send(:receivers).should include(klass)
|
773
773
|
end
|
774
774
|
|
775
775
|
it "adds an instance to the current space when stubbed method is invoked" do
|
776
776
|
klass.any_instance.stub(:foo)
|
777
777
|
instance = klass.new
|
778
778
|
instance.foo
|
779
|
-
RSpec::Mocks::space.send(:
|
779
|
+
RSpec::Mocks::space.send(:receivers).should include(instance)
|
780
780
|
end
|
781
781
|
end
|
782
782
|
|
@@ -3,20 +3,18 @@ require 'spec_helper'
|
|
3
3
|
module RSpec
|
4
4
|
module Mocks
|
5
5
|
describe ArgumentExpectation do
|
6
|
-
|
6
|
+
|
7
7
|
it "considers an object that responds to #matches? and #failure_message_for_should to be a matcher" do
|
8
8
|
argument_expecatation = RSpec::Mocks::ArgumentExpectation.new
|
9
9
|
obj = double("matcher")
|
10
|
-
obj.stub(:respond_to?).with(:__rspec_double_acting_as_null_object?).and_return(false)
|
11
10
|
obj.stub(:respond_to?).with(:matches?).and_return(true)
|
12
11
|
obj.stub(:respond_to?).with(:failure_message_for_should).and_return(true)
|
13
12
|
argument_expecatation.is_matcher?(obj).should be_true
|
14
13
|
end
|
15
|
-
|
14
|
+
|
16
15
|
it "considers an object that responds to #matches? and #failure_message to be a matcher for backward compatibility" do
|
17
16
|
argument_expecatation = RSpec::Mocks::ArgumentExpectation.new
|
18
17
|
obj = double("matcher")
|
19
|
-
obj.stub(:respond_to?).with(:__rspec_double_acting_as_null_object?).and_return(false)
|
20
18
|
obj.stub(:respond_to?).with(:matches?).and_return(true)
|
21
19
|
obj.stub(:respond_to?).with(:failure_message_for_should).and_return(false)
|
22
20
|
obj.stub(:respond_to?).with(:failure_message).and_return(true)
|
@@ -26,7 +24,6 @@ module RSpec
|
|
26
24
|
it "does NOT consider an object that only responds to #matches? to be a matcher" do
|
27
25
|
argument_expecatation = RSpec::Mocks::ArgumentExpectation.new
|
28
26
|
obj = double("matcher")
|
29
|
-
obj.stub(:respond_to?).with(:__rspec_double_acting_as_null_object?).and_return(false)
|
30
27
|
obj.stub(:respond_to?).with(:matches?).and_return(true)
|
31
28
|
obj.stub(:respond_to?).with(:failure_message_for_should).and_return(false)
|
32
29
|
obj.stub(:respond_to?).with(:failure_message).and_return(false)
|
@@ -1,11 +1,11 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
class LiarLiarPantsOnFire
|
4
|
-
def respond_to?(
|
4
|
+
def respond_to?(message, incl_private=false)
|
5
5
|
true
|
6
6
|
end
|
7
7
|
|
8
|
-
def self.respond_to?(
|
8
|
+
def self.respond_to?(message, incl_private=false)
|
9
9
|
true
|
10
10
|
end
|
11
11
|
end
|
@@ -1,16 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe "An object where respond_to? is true and does not have method" do
|
4
|
-
# When should_receive(
|
5
|
-
# respond_to?(
|
4
|
+
# When should_receive(message) is sent to any object, the Proxy sends
|
5
|
+
# respond_to?(message) to that object to see if the method should be proxied.
|
6
6
|
#
|
7
7
|
# If respond_to? itself is proxied, then when the Proxy sends respond_to?
|
8
8
|
# to the object, the proxy is invoked and responds yes (if so set in the spec).
|
9
|
-
# When the object does NOT actually respond to
|
9
|
+
# When the object does NOT actually respond to `message`, an exception is thrown
|
10
10
|
# when trying to proxy it.
|
11
11
|
#
|
12
|
-
# The fix was to keep track of whether
|
13
|
-
# so, call the munged copy of
|
12
|
+
# The fix was to keep track of whether `respond_to?` had been proxied and, if
|
13
|
+
# so, call the munged copy of `respond_to?` on the object.
|
14
14
|
|
15
15
|
it "does not raise an exception for Object" do
|
16
16
|
obj = Object.new
|
@@ -4,34 +4,30 @@ module RSpec
|
|
4
4
|
module Mocks
|
5
5
|
|
6
6
|
describe "ordering" do
|
7
|
+
before { @double = double("test double") }
|
8
|
+
after { @double.rspec_reset }
|
7
9
|
|
8
|
-
|
9
|
-
@double = double("test double")
|
10
|
-
end
|
11
|
-
|
12
|
-
after do
|
13
|
-
@double.rspec_reset
|
14
|
-
end
|
15
|
-
|
16
|
-
it "passes two calls in order" do
|
17
|
-
@double.should_receive(:one).ordered
|
18
|
-
@double.should_receive(:two).ordered
|
19
|
-
@double.one
|
20
|
-
@double.two
|
21
|
-
@double.rspec_verify
|
22
|
-
end
|
23
|
-
|
24
|
-
it "passes three calls in order" do
|
10
|
+
it "passes when messages are received in order" do
|
25
11
|
@double.should_receive(:one).ordered
|
26
12
|
@double.should_receive(:two).ordered
|
27
13
|
@double.should_receive(:three).ordered
|
28
14
|
@double.one
|
29
15
|
@double.two
|
30
16
|
@double.three
|
31
|
-
@double.rspec_verify
|
32
17
|
end
|
33
18
|
|
34
|
-
it "
|
19
|
+
it "passes when messages are received in order across objects" do
|
20
|
+
a = double("a")
|
21
|
+
b = double("b")
|
22
|
+
a.should_receive(:one).ordered
|
23
|
+
b.should_receive(:two).ordered
|
24
|
+
a.should_receive(:three).ordered
|
25
|
+
a.one
|
26
|
+
b.two
|
27
|
+
a.three
|
28
|
+
end
|
29
|
+
|
30
|
+
it "fails when messages are received out of order (2nd message 1st)" do
|
35
31
|
@double.should_receive(:one).ordered
|
36
32
|
@double.should_receive(:two).ordered
|
37
33
|
lambda do
|
@@ -39,7 +35,7 @@ module RSpec
|
|
39
35
|
end.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :two out of order")
|
40
36
|
end
|
41
37
|
|
42
|
-
it "fails
|
38
|
+
it "fails when messages are received out of order (3rd message 1st)" do
|
43
39
|
@double.should_receive(:one).ordered
|
44
40
|
@double.should_receive(:two).ordered
|
45
41
|
@double.should_receive(:three).ordered
|
@@ -48,8 +44,8 @@ module RSpec
|
|
48
44
|
@double.three
|
49
45
|
end.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
|
50
46
|
end
|
51
|
-
|
52
|
-
it "fails
|
47
|
+
|
48
|
+
it "fails when messages are received out of order (3rd message 2nd)" do
|
53
49
|
@double.should_receive(:one).ordered
|
54
50
|
@double.should_receive(:two).ordered
|
55
51
|
@double.should_receive(:three).ordered
|
@@ -59,7 +55,21 @@ module RSpec
|
|
59
55
|
end.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
|
60
56
|
end
|
61
57
|
|
62
|
-
it "
|
58
|
+
it "fails when messages are out of order across objects" do
|
59
|
+
a = double("test double")
|
60
|
+
b = double("another test double")
|
61
|
+
a.should_receive(:one).ordered
|
62
|
+
b.should_receive(:two).ordered
|
63
|
+
a.should_receive(:three).ordered
|
64
|
+
a.one
|
65
|
+
lambda do
|
66
|
+
a.three
|
67
|
+
end.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :three out of order")
|
68
|
+
a.rspec_reset
|
69
|
+
b.rspec_reset
|
70
|
+
end
|
71
|
+
|
72
|
+
it "ignores order of non ordered messages" do
|
63
73
|
@double.should_receive(:ignored_0)
|
64
74
|
@double.should_receive(:ordered_1).ordered
|
65
75
|
@double.should_receive(:ignored_1)
|
@@ -78,17 +88,16 @@ module RSpec
|
|
78
88
|
@double.ignored_1
|
79
89
|
@double.rspec_verify
|
80
90
|
end
|
81
|
-
|
82
|
-
it "
|
91
|
+
|
92
|
+
it "supports duplicate messages" do
|
83
93
|
@double.should_receive(:a).ordered
|
84
94
|
@double.should_receive(:b).ordered
|
85
95
|
@double.should_receive(:a).ordered
|
86
|
-
|
96
|
+
|
87
97
|
@double.a
|
88
98
|
@double.b
|
89
99
|
@double.a
|
90
100
|
end
|
91
|
-
|
92
101
|
end
|
93
102
|
end
|
94
103
|
end
|
@@ -40,7 +40,11 @@ module RSpec
|
|
40
40
|
it "clears internal mocks on reset_all" do
|
41
41
|
@space.add(double("mock"))
|
42
42
|
@space.reset_all
|
43
|
-
@space.instance_eval {
|
43
|
+
@space.instance_eval { receivers.empty? }.should be_true
|
44
|
+
end
|
45
|
+
it "resets the ordering" do
|
46
|
+
@space.reset_all
|
47
|
+
@space.expectation_ordering.should be_empty
|
44
48
|
end
|
45
49
|
it "only adds an instance once" do
|
46
50
|
@space.add(m1 = double("mock1"))
|
@@ -8,7 +8,7 @@ module RSpec
|
|
8
8
|
end
|
9
9
|
|
10
10
|
treats_method_missing_as_private :subject => RSpec::Mocks::Mock.new, :noop => false
|
11
|
-
|
11
|
+
|
12
12
|
after(:each) do
|
13
13
|
@mock.rspec_reset
|
14
14
|
end
|
@@ -54,7 +54,7 @@ module RSpec
|
|
54
54
|
@mock.not_expected
|
55
55
|
violated
|
56
56
|
}.to raise_error(
|
57
|
-
RSpec::Mocks::MockExpectationError,
|
57
|
+
RSpec::Mocks::MockExpectationError,
|
58
58
|
%Q|(Double "test double").not_expected(no args)\n expected: 0 times\n received: 1 time|
|
59
59
|
)
|
60
60
|
end
|
@@ -65,7 +65,7 @@ module RSpec
|
|
65
65
|
@mock.not_expected("unexpected text")
|
66
66
|
violated
|
67
67
|
}.to raise_error(
|
68
|
-
RSpec::Mocks::MockExpectationError,
|
68
|
+
RSpec::Mocks::MockExpectationError,
|
69
69
|
%Q|(Double "test double").not_expected("unexpected text")\n expected: 0 times\n received: 1 time|
|
70
70
|
)
|
71
71
|
end
|
@@ -137,19 +137,19 @@ module RSpec
|
|
137
137
|
@mock.rspec_verify
|
138
138
|
}.should raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :something with unexpected arguments\n expected: (\"a\", \"b\", \"c\")\n got: (\"a\", \"d\", \"c\")")
|
139
139
|
end
|
140
|
-
|
140
|
+
|
141
141
|
describe 'with a method that has a default argument' do
|
142
142
|
it "raises an exception if the arguments don't match when the method is called, correctly reporting the offending arguments" do
|
143
143
|
def @mock.method_with_default_argument(arg={}); end
|
144
144
|
@mock.should_receive(:method_with_default_argument).with({})
|
145
|
-
|
145
|
+
|
146
146
|
expect {
|
147
147
|
@mock.method_with_default_argument(nil)
|
148
148
|
@mock.rspec_verify
|
149
149
|
}.to raise_error(RSpec::Mocks::MockExpectationError, "Double \"test double\" received :method_with_default_argument with unexpected arguments\n expected: ({})\n got: (nil)")
|
150
150
|
end
|
151
151
|
end
|
152
|
-
|
152
|
+
|
153
153
|
it "fails if unexpected method called" do
|
154
154
|
lambda {
|
155
155
|
@mock.something("a","b","c")
|
@@ -174,41 +174,42 @@ module RSpec
|
|
174
174
|
}.to raise_error(RSpec::Mocks::MockExpectationError, /Double \"test double\" received :something but passed block failed with: expected false to be true/)
|
175
175
|
end
|
176
176
|
|
177
|
-
it "passes
|
178
|
-
a = nil
|
177
|
+
it "passes proc to expectation block without an argument", :ruby => '> 1.8.6' do
|
179
178
|
# We eval this because Ruby 1.8.6's syntax parser barfs on { |&block| ... }
|
180
179
|
# and prevents the entire spec suite from running.
|
181
|
-
eval("@mock.should_receive(:
|
182
|
-
|
183
|
-
@mock.something(&b)
|
184
|
-
a.should eq b
|
185
|
-
@mock.rspec_verify
|
180
|
+
eval("@mock.should_receive(:foo) {|&block| block.call.should eq(:bar)}")
|
181
|
+
@mock.foo { :bar }
|
186
182
|
end
|
187
183
|
|
188
|
-
it "
|
189
|
-
@mock.should_receive(:
|
190
|
-
|
191
|
-
RSpec::Mocks::MockExpectationError,
|
192
|
-
%Q|(Double "test double").not_expected(no args)\n expected: 0 times\n received: 1 time|
|
193
|
-
)
|
184
|
+
it "passes proc to expectation block with an argument", :ruby => '> 1.8.6' do
|
185
|
+
eval("@mock.should_receive(:foo) {|arg, &block| block.call.should eq(:bar)}")
|
186
|
+
@mock.foo(:arg) { :bar }
|
194
187
|
end
|
195
188
|
|
196
|
-
it "
|
189
|
+
it "passes proc to stub block without an argurment", :ruby => '>1.8.6' do
|
190
|
+
eval("@mock.stub(:foo) {|&block| block.call.should eq(:bar)}")
|
191
|
+
@mock.foo { :bar }
|
192
|
+
end
|
193
|
+
|
194
|
+
it "passes proc to stub block with an argument", :ruby => '> 1.8.6' do
|
195
|
+
eval("@mock.stub(:foo) {|arg, &block| block.call.should eq(:bar)}")
|
196
|
+
@mock.foo(:arg) { :bar }
|
197
|
+
end
|
198
|
+
|
199
|
+
it "fails right away when method defined as never is received" do
|
197
200
|
@mock.should_receive(:not_expected).never
|
198
|
-
expect { @mock.not_expected }.
|
199
|
-
RSpec::Mocks::MockExpectationError,
|
200
|
-
|
201
|
+
expect { @mock.not_expected }.
|
202
|
+
to raise_error(RSpec::Mocks::MockExpectationError,
|
203
|
+
%Q|(Double "test double").not_expected(no args)\n expected: 0 times\n received: 1 time|
|
201
204
|
)
|
202
205
|
end
|
203
206
|
|
204
207
|
it "raises when told to" do
|
205
208
|
@mock.should_receive(:something).and_raise(RuntimeError)
|
206
|
-
|
207
|
-
@mock.something
|
208
|
-
end.should raise_error(RuntimeError)
|
209
|
+
expect { @mock.something }.to raise_error(RuntimeError)
|
209
210
|
end
|
210
211
|
|
211
|
-
it "raises
|
212
|
+
it "raises instance of submitted Exception" do
|
212
213
|
error = RuntimeError.new("error message")
|
213
214
|
@mock.should_receive(:something).and_raise(error)
|
214
215
|
lambda {
|
@@ -216,7 +217,19 @@ module RSpec
|
|
216
217
|
}.should raise_error(RuntimeError, "error message")
|
217
218
|
end
|
218
219
|
|
219
|
-
it "
|
220
|
+
it "fails with helpful message if submitted Exception requires constructor arguments" do
|
221
|
+
class ErrorWithNonZeroArgConstructor < RuntimeError
|
222
|
+
def initialize(i_take_an_argument)
|
223
|
+
end
|
224
|
+
end
|
225
|
+
|
226
|
+
@mock.stub(:something).and_raise(ErrorWithNonZeroArgConstructor)
|
227
|
+
lambda {
|
228
|
+
@mock.something
|
229
|
+
}.should raise_error(ArgumentError, /^'and_raise' can only accept an Exception class if an instance/)
|
230
|
+
end
|
231
|
+
|
232
|
+
it "raises RuntimeError with submitted message" do
|
220
233
|
@mock.should_receive(:something).and_raise("error message")
|
221
234
|
lambda {
|
222
235
|
@mock.something
|
@@ -615,7 +628,7 @@ module RSpec
|
|
615
628
|
mock = double()
|
616
629
|
expect {mock.foo}.to raise_error(/Double received/)
|
617
630
|
end
|
618
|
-
|
631
|
+
|
619
632
|
it "does respond to initially stubbed methods" do
|
620
633
|
double = double(:foo => "woo", :bar => "car")
|
621
634
|
double.foo.should eq "woo"
|
@@ -1,26 +1,47 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
3
|
+
describe "expection set on previously stubbed method" do
|
4
|
+
it "fails if message is not received after expectation is set" do
|
5
|
+
double = double(:msg => nil)
|
6
|
+
double.msg
|
7
|
+
double.should_receive(:msg)
|
8
|
+
lambda { double.rspec_verify }.should raise_error(RSpec::Mocks::MockExpectationError)
|
9
|
+
end
|
10
|
+
|
11
|
+
it "outputs arguments of similar calls" do
|
12
|
+
double = double('double', :foo => true)
|
13
|
+
double.should_receive(:foo).with('first')
|
14
|
+
double.foo('second')
|
15
|
+
double.foo('third')
|
16
|
+
lambda do
|
17
|
+
double.rspec_verify
|
18
|
+
end.should raise_error(%Q|Double "double" received :foo with unexpected arguments\n expected: ("first")\n got: ("second"), ("third")|)
|
19
|
+
double.rspec_reset
|
20
|
+
end
|
21
|
+
|
22
|
+
context "with argument constraint on stub" do
|
23
|
+
it "matches any args if no arg constraint set on expectation" do
|
24
|
+
double = double("mock")
|
25
|
+
double.stub(:foo).with(3).and_return("stub")
|
26
|
+
double.should_receive(:foo).at_least(:once).and_return("expectation")
|
27
|
+
double.foo
|
28
|
+
double.rspec_verify
|
29
|
+
end
|
30
|
+
|
31
|
+
it "matches specific args set on expectation" do
|
32
|
+
double = double("mock")
|
33
|
+
double.stub(:foo).with(3).and_return("stub")
|
34
|
+
double.should_receive(:foo).at_least(:once).with(4).and_return("expectation")
|
35
|
+
double.foo(4)
|
36
|
+
double.rspec_verify
|
37
|
+
end
|
12
38
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
double.rspec_verify
|
20
|
-
end.should raise_error(%Q|Double "double" received :foo with unexpected arguments\n expected: ("first")\n got: ("second"), ("third")|)
|
21
|
-
double.rspec_reset
|
22
|
-
end
|
39
|
+
it "fails if expectation's arg constraint is not met" do
|
40
|
+
double = double("mock")
|
41
|
+
double.stub(:foo).with(3).and_return("stub")
|
42
|
+
double.should_receive(:foo).at_least(:once).with(4).and_return("expectation")
|
43
|
+
double.foo(3)
|
44
|
+
expect { double.rspec_verify }.to raise_error(/expected: \(4\)\s+got: \(3\)/)
|
23
45
|
end
|
24
|
-
|
25
46
|
end
|
26
47
|
end
|
metadata
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-mocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 85566451
|
5
|
+
prerelease: 6
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
8
|
+
- 9
|
9
9
|
- 0
|
10
|
-
|
10
|
+
- rc
|
11
|
+
- 2
|
12
|
+
version: 2.9.0.rc2
|
11
13
|
platform: ruby
|
12
14
|
authors:
|
13
15
|
- Steven Baker
|
@@ -16,18 +18,64 @@ autorequire:
|
|
16
18
|
bindir: bin
|
17
19
|
cert_chain: []
|
18
20
|
|
19
|
-
date: 2012-
|
20
|
-
dependencies:
|
21
|
-
|
21
|
+
date: 2012-03-12 00:00:00 Z
|
22
|
+
dependencies:
|
23
|
+
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 63
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
- 9
|
33
|
+
- 2
|
34
|
+
version: 0.9.2
|
35
|
+
prerelease: false
|
36
|
+
requirement: *id001
|
37
|
+
name: rake
|
38
|
+
type: :development
|
39
|
+
- !ruby/object:Gem::Dependency
|
40
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 1
|
46
|
+
segments:
|
47
|
+
- 1
|
48
|
+
- 1
|
49
|
+
- 9
|
50
|
+
version: 1.1.9
|
51
|
+
prerelease: false
|
52
|
+
requirement: *id002
|
53
|
+
name: cucumber
|
54
|
+
type: :development
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
hash: 25
|
62
|
+
segments:
|
63
|
+
- 0
|
64
|
+
- 4
|
65
|
+
- 11
|
66
|
+
version: 0.4.11
|
67
|
+
prerelease: false
|
68
|
+
requirement: *id003
|
69
|
+
name: aruba
|
70
|
+
type: :development
|
22
71
|
description: RSpec's 'test double' framework, with support for stubbing and mocking
|
23
72
|
email: rspec-users@rubyforge.org
|
24
73
|
executables: []
|
25
74
|
|
26
75
|
extensions: []
|
27
76
|
|
28
|
-
extra_rdoc_files:
|
29
|
-
|
30
|
-
- License.txt
|
77
|
+
extra_rdoc_files: []
|
78
|
+
|
31
79
|
files:
|
32
80
|
- lib/rspec/mocks.rb
|
33
81
|
- lib/rspec/mocks/any_instance.rb
|
@@ -54,8 +102,11 @@ files:
|
|
54
102
|
- lib/rspec/mocks/standalone.rb
|
55
103
|
- lib/rspec/mocks/version.rb
|
56
104
|
- lib/spec/mocks.rb
|
57
|
-
- License.txt
|
58
105
|
- README.md
|
106
|
+
- License.txt
|
107
|
+
- Changelog.md
|
108
|
+
- .yardopts
|
109
|
+
- .document
|
59
110
|
- features/README.markdown
|
60
111
|
- features/Scope.md
|
61
112
|
- features/Upgrade.md
|
@@ -144,19 +195,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
195
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
196
|
none: false
|
146
197
|
requirements:
|
147
|
-
- - "
|
198
|
+
- - ">"
|
148
199
|
- !ruby/object:Gem::Version
|
149
|
-
hash:
|
200
|
+
hash: 25
|
150
201
|
segments:
|
151
|
-
-
|
152
|
-
|
202
|
+
- 1
|
203
|
+
- 3
|
204
|
+
- 1
|
205
|
+
version: 1.3.1
|
153
206
|
requirements: []
|
154
207
|
|
155
208
|
rubyforge_project: rspec
|
156
|
-
rubygems_version: 1.8.
|
209
|
+
rubygems_version: 1.8.15
|
157
210
|
signing_key:
|
158
211
|
specification_version: 3
|
159
|
-
summary: rspec-mocks-2.
|
212
|
+
summary: rspec-mocks-2.9.0.rc2
|
160
213
|
test_files:
|
161
214
|
- features/README.markdown
|
162
215
|
- features/Scope.md
|