rspec-mocks 3.3.2 → 3.4.0
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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.document +1 -1
- data/.yardopts +1 -1
- data/Changelog.md +19 -0
- data/{License.txt → LICENSE.md} +5 -4
- data/README.md +19 -4
- data/lib/rspec/mocks/configuration.rb +17 -0
- data/lib/rspec/mocks/error_generator.rb +11 -6
- data/lib/rspec/mocks/example_methods.rb +1 -0
- data/lib/rspec/mocks/instance_method_stasher.rb +0 -1
- data/lib/rspec/mocks/matchers/have_received.rb +17 -5
- data/lib/rspec/mocks/message_expectation.rb +13 -13
- data/lib/rspec/mocks/method_double.rb +1 -1
- data/lib/rspec/mocks/proxy.rb +58 -13
- data/lib/rspec/mocks/space.rb +2 -2
- data/lib/rspec/mocks/syntax.rb +1 -1
- data/lib/rspec/mocks/targets.rb +2 -2
- data/lib/rspec/mocks/{verifying_message_expecation.rb → verifying_message_expectation.rb} +1 -1
- data/lib/rspec/mocks/verifying_proxy.rb +1 -1
- data/lib/rspec/mocks/version.rb +1 -1
- metadata +9 -25
- metadata.gz.sig +0 -0
- data/lib/rspec/mocks/mutex.rb +0 -73
- data/lib/rspec/mocks/reentrant_mutex.rb +0 -53
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e618d7a28b9f934cf906f40a9d1c70d59833ac36
|
4
|
+
data.tar.gz: 6e4a6af3c8ad439a596350088869b5cd2dd69885
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e14baa4517cc30d218b50b8bc4b3bfaa2a878504e4de3bb90c1a6f36db05d742f5d7f5c561c732031c932d4c27fbc2cc67fd471992e6ca50c3c13219d26c6c60
|
7
|
+
data.tar.gz: bfe1b8654f29fc1f891e23ec4efadd1f10c1411b166fe66e0889d6336cee57d4f2ddbb7bf5becc9d0b5f6a47915d9d1fe1fc86abae394e70b9308aa8cabbe3f2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/.document
CHANGED
data/.yardopts
CHANGED
data/Changelog.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
### 3.4.0 / 2015-11-11
|
2
|
+
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.3.2...v3.4.0)
|
3
|
+
|
4
|
+
Enhancements:
|
5
|
+
|
6
|
+
* Make `expect(...).to have_received` work without relying upon
|
7
|
+
rspec-expectations. (Myron Marston, #978)
|
8
|
+
* Add option for failing tests when expectations are set on `nil`.
|
9
|
+
(Liz Rush, #983)
|
10
|
+
|
11
|
+
Bug Fixes:
|
12
|
+
|
13
|
+
* Fix `have_received { ... }` so that any block passed when the message
|
14
|
+
was received is forwarded to the `have_received` block. (Myron Marston, #1006)
|
15
|
+
* Fix infinite loop in error generator when stubbing `respond_to?`.
|
16
|
+
(Alex Dowad, #1022)
|
17
|
+
* Fix issue with using `receive` on subclasses (at a class level) with 1.8.7.
|
18
|
+
(Alex Dowad, #1026)
|
19
|
+
|
1
20
|
### 3.3.2 / 2015-07-15
|
2
21
|
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.3.1...v3.3.2)
|
3
22
|
|
data/{License.txt → LICENSE.md}
RENAMED
@@ -1,8 +1,9 @@
|
|
1
|
-
|
1
|
+
The MIT License (MIT)
|
2
|
+
=====================
|
2
3
|
|
3
|
-
Copyright
|
4
|
-
Copyright
|
5
|
-
Copyright
|
4
|
+
* Copyright © 2012 David Chelimsky, Myron Marston
|
5
|
+
* Copyright © 2006 David Chelimsky, The RSpec Development Team
|
6
|
+
* Copyright © 2005 Steven Baker
|
6
7
|
|
7
8
|
Permission is hereby granted, free of charge, to any person obtaining
|
8
9
|
a copy of this software and associated documentation files (the
|
data/README.md
CHANGED
@@ -16,6 +16,20 @@ RSpec repos as well. Add the following to your `Gemfile`:
|
|
16
16
|
gem lib, :git => "git://github.com/rspec/#{lib}.git", :branch => 'master'
|
17
17
|
end
|
18
18
|
```
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
Once you've set up the environment, you'll need to cd into the working
|
22
|
+
directory of whichever repo you want to work in. From there you can run the
|
23
|
+
specs and cucumber features, and make patches.
|
24
|
+
|
25
|
+
NOTE: You do not need to use rspec-dev to work on a specific RSpec repo. You
|
26
|
+
can treat each RSpec repo as an independent project.
|
27
|
+
|
28
|
+
For information about contributing to RSpec, please refer to the following markdown files:
|
29
|
+
* [Build details](BUILD_DETAIL.md)
|
30
|
+
* [Code of Conduct](CODE_OF_CONDUCT.md)
|
31
|
+
* [Detailed contributing guide](CONTRIBUTING.md)
|
32
|
+
* [Development setup guide](DEVELOPMENT.md)
|
19
33
|
|
20
34
|
## Test Doubles
|
21
35
|
|
@@ -346,7 +360,7 @@ end
|
|
346
360
|
## Delegating to the Original Implementation
|
347
361
|
|
348
362
|
When working with a partial mock object, you may occasionally
|
349
|
-
want to set a message
|
363
|
+
want to set a message expectation without interfering with how
|
350
364
|
the object responds to the message. You can use `and_call_original`
|
351
365
|
to achieve this:
|
352
366
|
|
@@ -425,6 +439,7 @@ you are interested in learning more, here is some recommended reading:
|
|
425
439
|
|
426
440
|
## Also see
|
427
441
|
|
428
|
-
* [
|
429
|
-
* [
|
430
|
-
* [
|
442
|
+
* [https://github.com/rspec/rspec](https://github.com/rspec/rspec)
|
443
|
+
* [https://github.com/rspec/rspec-core](https://github.com/rspec/rspec-core)
|
444
|
+
* [https://github.com/rspec/rspec-expectations](https://github.com/rspec/rspec-expectations)
|
445
|
+
* [https://github.com/rspec/rspec-rails](https://github.com/rspec/rspec-rails)
|
@@ -3,12 +3,29 @@ module RSpec
|
|
3
3
|
# Provides configuration options for rspec-mocks.
|
4
4
|
class Configuration
|
5
5
|
def initialize
|
6
|
+
@allow_message_expectations_on_nil = nil
|
6
7
|
@yield_receiver_to_any_instance_implementation_blocks = true
|
7
8
|
@verify_doubled_constant_names = false
|
8
9
|
@transfer_nested_constants = false
|
9
10
|
@verify_partial_doubles = false
|
10
11
|
end
|
11
12
|
|
13
|
+
# Sets whether RSpec will warn, ignore, or fail a test when
|
14
|
+
# expectations are set on nil.
|
15
|
+
# By default, when this flag is not set, warning messages are issued when
|
16
|
+
# expectations are set on nil. This is to prevent false-positives and to
|
17
|
+
# catch potential bugs early on.
|
18
|
+
# When set to `true`, warning messages are suppressed.
|
19
|
+
# When set to `false`, it will raise an error.
|
20
|
+
#
|
21
|
+
# @example
|
22
|
+
# RSpec.configure do |config|
|
23
|
+
# config.mock_with :rspec do |mocks|
|
24
|
+
# mocks.allow_message_expectations_on_nil = false
|
25
|
+
# end
|
26
|
+
# end
|
27
|
+
attr_accessor :allow_message_expectations_on_nil
|
28
|
+
|
12
29
|
def yield_receiver_to_any_instance_implementation_blocks?
|
13
30
|
@yield_receiver_to_any_instance_implementation_blocks
|
14
31
|
end
|
@@ -69,12 +69,7 @@ module RSpec
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def default_error_message(expectation, expected_args, actual_args)
|
72
|
-
|
73
|
-
intro,
|
74
|
-
"received",
|
75
|
-
expectation.message.inspect,
|
76
|
-
unexpected_arguments_message(expected_args, actual_args),
|
77
|
-
].join(" ")
|
72
|
+
"#{intro} received #{expectation.message.inspect} #{unexpected_arguments_message(expected_args, actual_args)}"
|
78
73
|
end
|
79
74
|
|
80
75
|
# rubocop:disable Style/ParameterLists
|
@@ -213,6 +208,16 @@ module RSpec
|
|
213
208
|
notify MockExpectationAlreadyInvokedError.new(error_message)
|
214
209
|
end
|
215
210
|
|
211
|
+
def raise_expectation_on_nil_error(method_name)
|
212
|
+
__raise expectation_on_nil_message(method_name)
|
213
|
+
end
|
214
|
+
|
215
|
+
def expectation_on_nil_message(method_name)
|
216
|
+
"An expectation of `:#{method_name}` was set on `nil`. " \
|
217
|
+
"To allow expectations on `nil` and suppress this message, set `config.allow_expectations_on_nil` to `true`. " \
|
218
|
+
"To disallow expectations on `nil`, set `config.allow_expectations_on_nil` to `false`"
|
219
|
+
end
|
220
|
+
|
216
221
|
private
|
217
222
|
|
218
223
|
def received_part_of_expectation_error(actual_received_count, args)
|
@@ -197,6 +197,7 @@ module RSpec
|
|
197
197
|
# By default warning messages are issued when expectations are set on
|
198
198
|
# nil. This is to prevent false-positives and to catch potential bugs
|
199
199
|
# early on.
|
200
|
+
# @deprecated Use {RSpec::Mocks::Configuration#allow_message_expectations_on_nil} instead.
|
200
201
|
def allow_message_expectations_on_nil
|
201
202
|
RSpec::Mocks.space.proxy_for(nil).warn_about_expectations = false
|
202
203
|
end
|
@@ -36,11 +36,11 @@ module RSpec
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def failure_message
|
39
|
-
|
39
|
+
capture_failure_message
|
40
40
|
end
|
41
41
|
|
42
42
|
def failure_message_when_negated
|
43
|
-
|
43
|
+
capture_failure_message
|
44
44
|
end
|
45
45
|
|
46
46
|
def description
|
@@ -54,6 +54,14 @@ module RSpec
|
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
|
+
def setup_expectation(subject, &block)
|
58
|
+
notify_failure_message unless matches?(subject, &block)
|
59
|
+
end
|
60
|
+
|
61
|
+
def setup_negative_expectation(subject, &block)
|
62
|
+
notify_failure_message unless does_not_match?(subject, &block)
|
63
|
+
end
|
64
|
+
|
57
65
|
def setup_allowance(_subject, &_block)
|
58
66
|
disallow("allow", " as it would have no effect")
|
59
67
|
end
|
@@ -95,13 +103,17 @@ module RSpec
|
|
95
103
|
end
|
96
104
|
end
|
97
105
|
|
98
|
-
def
|
106
|
+
def capture_failure_message
|
99
107
|
RSpec::Support.with_failure_notifier(Proc.new { |err, _opt| return err.message }) do
|
100
|
-
|
101
|
-
@expectation.generate_error
|
108
|
+
notify_failure_message
|
102
109
|
end
|
103
110
|
end
|
104
111
|
|
112
|
+
def notify_failure_message
|
113
|
+
mock_proxy.check_for_unexpected_arguments(@expectation)
|
114
|
+
@expectation.generate_error
|
115
|
+
end
|
116
|
+
|
105
117
|
def expected_messages_received_in_order?
|
106
118
|
mock_proxy.replay_received_message_on @expectation, &@block
|
107
119
|
@expectation.expected_messages_received? && @expectation.ensure_expected_ordering_received!
|
@@ -2,7 +2,7 @@ module RSpec
|
|
2
2
|
module Mocks
|
3
3
|
# A message expectation that only allows concrete return values to be set
|
4
4
|
# for a message. While this same effect can be achieved using a standard
|
5
|
-
#
|
5
|
+
# MessageExpectation, this version is much faster and so can be used as an
|
6
6
|
# optimization.
|
7
7
|
#
|
8
8
|
# @private
|
@@ -169,7 +169,7 @@ module RSpec
|
|
169
169
|
# Tells the object to yield one or more args to a block when the message
|
170
170
|
# is received.
|
171
171
|
#
|
172
|
-
# @return [
|
172
|
+
# @return [MessageExpectation] self, to support further chaining.
|
173
173
|
# @example
|
174
174
|
# stream.stub(:open).and_yield(StringIO.new)
|
175
175
|
def and_yield(*args, &block)
|
@@ -191,7 +191,7 @@ module RSpec
|
|
191
191
|
# Constrain a message expectation to be received a specific number of
|
192
192
|
# times.
|
193
193
|
#
|
194
|
-
# @return [
|
194
|
+
# @return [MessageExpectation] self, to support further chaining.
|
195
195
|
# @example
|
196
196
|
# expect(dealer).to receive(:deal_card).exactly(10).times
|
197
197
|
def exactly(n, &block)
|
@@ -204,7 +204,7 @@ module RSpec
|
|
204
204
|
# Constrain a message expectation to be received at least a specific
|
205
205
|
# number of times.
|
206
206
|
#
|
207
|
-
# @return [
|
207
|
+
# @return [MessageExpectation] self, to support further chaining.
|
208
208
|
# @example
|
209
209
|
# expect(dealer).to receive(:deal_card).at_least(9).times
|
210
210
|
def at_least(n, &block)
|
@@ -223,7 +223,7 @@ module RSpec
|
|
223
223
|
# Constrain a message expectation to be received at most a specific
|
224
224
|
# number of times.
|
225
225
|
#
|
226
|
-
# @return [
|
226
|
+
# @return [MessageExpectation] self, to support further chaining.
|
227
227
|
# @example
|
228
228
|
# expect(dealer).to receive(:deal_card).at_most(10).times
|
229
229
|
def at_most(n, &block)
|
@@ -235,7 +235,7 @@ module RSpec
|
|
235
235
|
|
236
236
|
# Syntactic sugar for `exactly`, `at_least` and `at_most`
|
237
237
|
#
|
238
|
-
# @return [
|
238
|
+
# @return [MessageExpectation] self, to support further chaining.
|
239
239
|
# @example
|
240
240
|
# expect(dealer).to receive(:deal_card).exactly(10).times
|
241
241
|
# expect(dealer).to receive(:deal_card).at_least(10).times
|
@@ -247,7 +247,7 @@ module RSpec
|
|
247
247
|
|
248
248
|
# Expect a message not to be received at all.
|
249
249
|
#
|
250
|
-
# @return [
|
250
|
+
# @return [MessageExpectation] self, to support further chaining.
|
251
251
|
# @example
|
252
252
|
# expect(car).to receive(:stop).never
|
253
253
|
def never
|
@@ -258,7 +258,7 @@ module RSpec
|
|
258
258
|
|
259
259
|
# Expect a message to be received exactly one time.
|
260
260
|
#
|
261
|
-
# @return [
|
261
|
+
# @return [MessageExpectation] self, to support further chaining.
|
262
262
|
# @example
|
263
263
|
# expect(car).to receive(:go).once
|
264
264
|
def once(&block)
|
@@ -269,7 +269,7 @@ module RSpec
|
|
269
269
|
|
270
270
|
# Expect a message to be received exactly two times.
|
271
271
|
#
|
272
|
-
# @return [
|
272
|
+
# @return [MessageExpectation] self, to support further chaining.
|
273
273
|
# @example
|
274
274
|
# expect(car).to receive(:go).twice
|
275
275
|
def twice(&block)
|
@@ -280,7 +280,7 @@ module RSpec
|
|
280
280
|
|
281
281
|
# Expect a message to be received exactly three times.
|
282
282
|
#
|
283
|
-
# @return [
|
283
|
+
# @return [MessageExpectation] self, to support further chaining.
|
284
284
|
# @example
|
285
285
|
# expect(car).to receive(:go).thrice
|
286
286
|
def thrice(&block)
|
@@ -302,7 +302,7 @@ module RSpec
|
|
302
302
|
# A message expectation will fail if the message is received with different
|
303
303
|
# arguments.
|
304
304
|
#
|
305
|
-
# @return [
|
305
|
+
# @return [MessageExpectation] self, to support further chaining.
|
306
306
|
# @example
|
307
307
|
# allow(cart).to receive(:add) { :failure }
|
308
308
|
# allow(cart).to receive(:add).with(Book.new(:isbn => 1934356379)) { :success }
|
@@ -330,7 +330,7 @@ module RSpec
|
|
330
330
|
|
331
331
|
# Expect messages to be received in a specific order.
|
332
332
|
#
|
333
|
-
# @return [
|
333
|
+
# @return [MessageExpectation] self, to support further chaining.
|
334
334
|
# @example
|
335
335
|
# expect(api).to receive(:prepare).ordered
|
336
336
|
# expect(api).to receive(:run).ordered
|
@@ -345,7 +345,7 @@ module RSpec
|
|
345
345
|
end
|
346
346
|
|
347
347
|
# @private
|
348
|
-
# Contains the parts of `
|
348
|
+
# Contains the parts of `MessageExpectation` that aren't part of
|
349
349
|
# rspec-mocks' public API. The class is very big and could really use
|
350
350
|
# some collaborators it delegates to for this stuff but for now this was
|
351
351
|
# the simplest way to split the public from private stuff to make it
|
data/lib/rspec/mocks/proxy.rb
CHANGED
@@ -89,11 +89,11 @@ module RSpec
|
|
89
89
|
@error_generator.raise_expectation_on_unstubbed_method(expected_method_name)
|
90
90
|
end
|
91
91
|
|
92
|
-
@messages_received.each do |(actual_method_name, args,
|
92
|
+
@messages_received.each do |(actual_method_name, args, received_block)|
|
93
93
|
next unless expectation.matches?(actual_method_name, *args)
|
94
94
|
|
95
95
|
expectation.safe_invoke(nil)
|
96
|
-
block.call(*args) if block
|
96
|
+
block.call(*args, &received_block) if block
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
@@ -371,20 +371,36 @@ module RSpec
|
|
371
371
|
|
372
372
|
return super unless unbound_method
|
373
373
|
unbound_method.bind(object)
|
374
|
+
# :nocov:
|
375
|
+
rescue TypeError
|
376
|
+
if RUBY_VERSION == '1.8.7'
|
377
|
+
# In MRI 1.8.7, a singleton method on a class cannot be rebound to its subclass
|
378
|
+
if unbound_method && unbound_method.owner.ancestors.first != unbound_method.owner
|
379
|
+
# This is a singleton method; we can't do anything with it
|
380
|
+
# But we can work around this using a different implementation
|
381
|
+
double = method_double_from_ancestor_for(message)
|
382
|
+
return object.method(double.method_stasher.stashed_method_name)
|
383
|
+
end
|
384
|
+
end
|
385
|
+
raise
|
386
|
+
# :nocov:
|
374
387
|
end
|
375
388
|
|
376
389
|
protected
|
377
390
|
|
378
391
|
def original_unbound_method_handle_from_ancestor_for(message)
|
379
|
-
|
392
|
+
double = method_double_from_ancestor_for(message)
|
393
|
+
double && double.original_method.unbind
|
394
|
+
end
|
395
|
+
|
396
|
+
def method_double_from_ancestor_for(message)
|
397
|
+
@method_doubles.fetch(message) do
|
380
398
|
# The fact that there is no method double for this message indicates
|
381
399
|
# that it has not been redefined by rspec-mocks. We need to continue
|
382
400
|
# looking up the ancestor chain.
|
383
401
|
return superclass_proxy &&
|
384
|
-
superclass_proxy.
|
402
|
+
superclass_proxy.method_double_from_ancestor_for(message)
|
385
403
|
end
|
386
|
-
|
387
|
-
method_double.original_method.unbind
|
388
404
|
end
|
389
405
|
|
390
406
|
def superclass_proxy
|
@@ -406,33 +422,62 @@ module RSpec
|
|
406
422
|
# @private
|
407
423
|
class ProxyForNil < PartialDoubleProxy
|
408
424
|
def initialize(order_group)
|
409
|
-
|
425
|
+
set_expectation_behavior
|
410
426
|
super(nil, order_group)
|
411
427
|
end
|
412
428
|
|
429
|
+
attr_accessor :disallow_expectations
|
413
430
|
attr_accessor :warn_about_expectations
|
414
|
-
alias warn_about_expectations? warn_about_expectations
|
415
431
|
|
416
432
|
def add_message_expectation(method_name, opts={}, &block)
|
417
|
-
|
433
|
+
warn_or_raise!(method_name)
|
418
434
|
super
|
419
435
|
end
|
420
436
|
|
421
437
|
def add_negative_message_expectation(location, method_name, &implementation)
|
422
|
-
|
438
|
+
warn_or_raise!(method_name)
|
423
439
|
super
|
424
440
|
end
|
425
441
|
|
426
442
|
def add_stub(method_name, opts={}, &implementation)
|
427
|
-
|
443
|
+
warn_or_raise!(method_name)
|
428
444
|
super
|
429
445
|
end
|
430
446
|
|
431
447
|
private
|
432
448
|
|
449
|
+
def set_expectation_behavior
|
450
|
+
case RSpec::Mocks.configuration.allow_message_expectations_on_nil
|
451
|
+
when false
|
452
|
+
@warn_about_expectations = false
|
453
|
+
@disallow_expectations = true
|
454
|
+
when true
|
455
|
+
@warn_about_expectations = false
|
456
|
+
@disallow_expectations = false
|
457
|
+
else
|
458
|
+
@warn_about_expectations = true
|
459
|
+
@disallow_expectations = false
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
def warn_or_raise!(method_name)
|
464
|
+
# This method intentionally swallows the message when
|
465
|
+
# neither disallow_expectations nor warn_about_expectations
|
466
|
+
# are set to true.
|
467
|
+
if disallow_expectations
|
468
|
+
raise_error(method_name)
|
469
|
+
elsif warn_about_expectations
|
470
|
+
warn(method_name)
|
471
|
+
end
|
472
|
+
end
|
473
|
+
|
433
474
|
def warn(method_name)
|
434
|
-
|
435
|
-
|
475
|
+
warning_msg = @error_generator.expectation_on_nil_message(method_name)
|
476
|
+
RSpec.warning(warning_msg)
|
477
|
+
end
|
478
|
+
|
479
|
+
def raise_error(method_name)
|
480
|
+
@error_generator.raise_expectation_on_nil_error(method_name)
|
436
481
|
end
|
437
482
|
end
|
438
483
|
end
|
data/lib/rspec/mocks/space.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
RSpec::Support.
|
1
|
+
RSpec::Support.require_rspec_support 'reentrant_mutex'
|
2
2
|
|
3
3
|
module RSpec
|
4
4
|
module Mocks
|
@@ -145,7 +145,7 @@ module RSpec
|
|
145
145
|
private
|
146
146
|
|
147
147
|
def new_mutex
|
148
|
-
|
148
|
+
Support::ReentrantMutex.new
|
149
149
|
end
|
150
150
|
|
151
151
|
def proxy_not_found_for(id, object)
|
data/lib/rspec/mocks/syntax.rb
CHANGED
@@ -48,7 +48,7 @@ module RSpec
|
|
48
48
|
end
|
49
49
|
|
50
50
|
def unstub(message)
|
51
|
-
::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__, "`allow(...).
|
51
|
+
::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__, "`allow(...).to receive(...).and_call_original` or explicitly enable `:should`")
|
52
52
|
::RSpec::Mocks.space.proxy_for(self).remove_stub(message)
|
53
53
|
end
|
54
54
|
|
data/lib/rspec/mocks/targets.rb
CHANGED
@@ -19,7 +19,7 @@ module RSpec
|
|
19
19
|
method_name = options.fetch(:from)
|
20
20
|
define_method(method_name) do |matcher, &block|
|
21
21
|
case matcher
|
22
|
-
when Matchers::Receive
|
22
|
+
when Matchers::Receive, Matchers::HaveReceived
|
23
23
|
define_matcher(matcher, matcher_method, &block)
|
24
24
|
when Matchers::ReceiveMessages, Matchers::ReceiveMessageChain
|
25
25
|
raise_negation_unsupported(method_name, matcher)
|
@@ -47,7 +47,7 @@ module RSpec
|
|
47
47
|
|
48
48
|
def raise_unsupported_matcher(method_name, matcher)
|
49
49
|
raise UnsupportedMatcherError,
|
50
|
-
"only the `receive`
|
50
|
+
"only the `receive`, `have_received` and `receive_messages` matchers are supported " \
|
51
51
|
"with `#{expression}(...).#{method_name}`, but you have provided: #{matcher}"
|
52
52
|
end
|
53
53
|
|
@@ -42,7 +42,7 @@ module RSpec
|
|
42
42
|
verifier = Support::LooseSignatureVerifier.new(signature, args)
|
43
43
|
|
44
44
|
unless verifier.valid?
|
45
|
-
# Fail fast is required, otherwise the message
|
45
|
+
# Fail fast is required, otherwise the message expectation will fail
|
46
46
|
# as well ("expected method not called") and clobber this one.
|
47
47
|
@failed_fast = true
|
48
48
|
@error_generator.raise_invalid_arguments_error(verifier)
|
data/lib/rspec/mocks/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rspec-mocks
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steven Baker
|
@@ -45,7 +45,7 @@ cert_chain:
|
|
45
45
|
ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
|
46
46
|
F3MdtaDehhjC
|
47
47
|
-----END CERTIFICATE-----
|
48
|
-
date: 2015-
|
48
|
+
date: 2015-11-12 00:00:00.000000000 Z
|
49
49
|
dependencies:
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: rspec-support
|
@@ -53,14 +53,14 @@ dependencies:
|
|
53
53
|
requirements:
|
54
54
|
- - "~>"
|
55
55
|
- !ruby/object:Gem::Version
|
56
|
-
version: 3.
|
56
|
+
version: 3.4.0
|
57
57
|
type: :runtime
|
58
58
|
prerelease: false
|
59
59
|
version_requirements: !ruby/object:Gem::Requirement
|
60
60
|
requirements:
|
61
61
|
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version: 3.
|
63
|
+
version: 3.4.0
|
64
64
|
- !ruby/object:Gem::Dependency
|
65
65
|
name: diff-lcs
|
66
66
|
requirement: !ruby/object:Gem::Requirement
|
@@ -115,14 +115,14 @@ dependencies:
|
|
115
115
|
requirements:
|
116
116
|
- - "~>"
|
117
117
|
- !ruby/object:Gem::Version
|
118
|
-
version:
|
118
|
+
version: 0.6.2
|
119
119
|
type: :development
|
120
120
|
prerelease: false
|
121
121
|
version_requirements: !ruby/object:Gem::Requirement
|
122
122
|
requirements:
|
123
123
|
- - "~>"
|
124
124
|
- !ruby/object:Gem::Version
|
125
|
-
version:
|
125
|
+
version: 0.6.2
|
126
126
|
- !ruby/object:Gem::Dependency
|
127
127
|
name: minitest
|
128
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -137,20 +137,6 @@ dependencies:
|
|
137
137
|
- - "~>"
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '5.2'
|
140
|
-
- !ruby/object:Gem::Dependency
|
141
|
-
name: thread_order
|
142
|
-
requirement: !ruby/object:Gem::Requirement
|
143
|
-
requirements:
|
144
|
-
- - "~>"
|
145
|
-
- !ruby/object:Gem::Version
|
146
|
-
version: 1.1.0
|
147
|
-
type: :development
|
148
|
-
prerelease: false
|
149
|
-
version_requirements: !ruby/object:Gem::Requirement
|
150
|
-
requirements:
|
151
|
-
- - "~>"
|
152
|
-
- !ruby/object:Gem::Version
|
153
|
-
version: 1.1.0
|
154
140
|
description: RSpec's 'test double' framework, with support for stubbing and mocking
|
155
141
|
email: rspec@googlegroups.com
|
156
142
|
executables: []
|
@@ -160,7 +146,7 @@ files:
|
|
160
146
|
- ".document"
|
161
147
|
- ".yardopts"
|
162
148
|
- Changelog.md
|
163
|
-
-
|
149
|
+
- LICENSE.md
|
164
150
|
- README.md
|
165
151
|
- lib/rspec/mocks.rb
|
166
152
|
- lib/rspec/mocks/any_instance.rb
|
@@ -190,18 +176,16 @@ files:
|
|
190
176
|
- lib/rspec/mocks/method_double.rb
|
191
177
|
- lib/rspec/mocks/method_reference.rb
|
192
178
|
- lib/rspec/mocks/mutate_const.rb
|
193
|
-
- lib/rspec/mocks/mutex.rb
|
194
179
|
- lib/rspec/mocks/object_reference.rb
|
195
180
|
- lib/rspec/mocks/order_group.rb
|
196
181
|
- lib/rspec/mocks/proxy.rb
|
197
|
-
- lib/rspec/mocks/reentrant_mutex.rb
|
198
182
|
- lib/rspec/mocks/space.rb
|
199
183
|
- lib/rspec/mocks/standalone.rb
|
200
184
|
- lib/rspec/mocks/syntax.rb
|
201
185
|
- lib/rspec/mocks/targets.rb
|
202
186
|
- lib/rspec/mocks/test_double.rb
|
203
187
|
- lib/rspec/mocks/verifying_double.rb
|
204
|
-
- lib/rspec/mocks/
|
188
|
+
- lib/rspec/mocks/verifying_message_expectation.rb
|
205
189
|
- lib/rspec/mocks/verifying_proxy.rb
|
206
190
|
- lib/rspec/mocks/version.rb
|
207
191
|
homepage: http://github.com/rspec/rspec-mocks
|
@@ -228,6 +212,6 @@ rubyforge_project:
|
|
228
212
|
rubygems_version: 2.2.2
|
229
213
|
signing_key:
|
230
214
|
specification_version: 4
|
231
|
-
summary: rspec-mocks-3.
|
215
|
+
summary: rspec-mocks-3.4.0
|
232
216
|
test_files: []
|
233
217
|
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|
data/lib/rspec/mocks/mutex.rb
DELETED
@@ -1,73 +0,0 @@
|
|
1
|
-
module RSpec
|
2
|
-
module Mocks
|
3
|
-
# On 1.8.7, it's in the stdlib.
|
4
|
-
# We don't want to load the stdlib, b/c this is a test tool, and can affect
|
5
|
-
# the test environment, causing tests to pass where they should fail.
|
6
|
-
#
|
7
|
-
# So we're transcribing/modifying it from
|
8
|
-
# https://github.com/ruby/ruby/blob/v1_8_7_374/lib/thread.rb#L56
|
9
|
-
# Some methods we don't need are deleted. Anything I don't
|
10
|
-
# understand (there's quite a bit, actually) is left in.
|
11
|
-
#
|
12
|
-
# Some formating changes are made to appease the robot overlord:
|
13
|
-
# https://travis-ci.org/rspec/rspec-core/jobs/54410874
|
14
|
-
# @private
|
15
|
-
class Mutex
|
16
|
-
def initialize
|
17
|
-
@waiting = []
|
18
|
-
@locked = false
|
19
|
-
@waiting.taint
|
20
|
-
taint
|
21
|
-
end
|
22
|
-
|
23
|
-
# @private
|
24
|
-
def lock
|
25
|
-
while Thread.critical = true && @locked
|
26
|
-
@waiting.push Thread.current
|
27
|
-
Thread.stop
|
28
|
-
end
|
29
|
-
@locked = true
|
30
|
-
Thread.critical = false
|
31
|
-
self
|
32
|
-
end
|
33
|
-
|
34
|
-
# @private
|
35
|
-
def unlock
|
36
|
-
return unless @locked
|
37
|
-
Thread.critical = true
|
38
|
-
@locked = false
|
39
|
-
wakeup_and_run_waiting_thread
|
40
|
-
self
|
41
|
-
end
|
42
|
-
|
43
|
-
# @private
|
44
|
-
def synchronize
|
45
|
-
lock
|
46
|
-
begin
|
47
|
-
yield
|
48
|
-
ensure
|
49
|
-
unlock
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
private
|
54
|
-
|
55
|
-
def wakeup_and_run_waiting_thread
|
56
|
-
begin
|
57
|
-
t = @waiting.shift
|
58
|
-
t.wakeup if t
|
59
|
-
rescue ThreadError
|
60
|
-
retry
|
61
|
-
end
|
62
|
-
Thread.critical = false
|
63
|
-
begin
|
64
|
-
t.run if t
|
65
|
-
rescue ThreadError
|
66
|
-
:noop
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
# Avoid warnings for library wide checks spec
|
71
|
-
end unless defined?(::RSpec::Mocks::Mutex) || defined?(::Mutex)
|
72
|
-
end
|
73
|
-
end
|
@@ -1,53 +0,0 @@
|
|
1
|
-
module RSpec
|
2
|
-
module Mocks
|
3
|
-
# Allows a thread to lock out other threads from a critical section of code,
|
4
|
-
# while allowing the thread with the lock to reenter that section.
|
5
|
-
#
|
6
|
-
# Based on Monitor as of 2.2 -
|
7
|
-
# https://github.com/ruby/ruby/blob/eb7ddaa3a47bf48045d26c72eb0f263a53524ebc/lib/monitor.rb#L9
|
8
|
-
#
|
9
|
-
# Depends on Mutex, but Mutex is only available as part of core since 1.9.1:
|
10
|
-
# exists - http://ruby-doc.org/core-1.9.1/Mutex.html
|
11
|
-
# dne - http://ruby-doc.org/core-1.9.0/Mutex.html
|
12
|
-
#
|
13
|
-
# @private
|
14
|
-
class ReentrantMutex
|
15
|
-
def initialize
|
16
|
-
@owner = nil
|
17
|
-
@count = 0
|
18
|
-
@mutex = Mutex.new
|
19
|
-
end
|
20
|
-
|
21
|
-
def synchronize
|
22
|
-
enter
|
23
|
-
yield
|
24
|
-
ensure
|
25
|
-
exit
|
26
|
-
end
|
27
|
-
|
28
|
-
private
|
29
|
-
|
30
|
-
def enter
|
31
|
-
@mutex.lock if @owner != Thread.current
|
32
|
-
@owner = Thread.current
|
33
|
-
@count += 1
|
34
|
-
end
|
35
|
-
|
36
|
-
def exit
|
37
|
-
@count -= 1
|
38
|
-
return unless @count == 0
|
39
|
-
@owner = nil
|
40
|
-
@mutex.unlock
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
if defined? ::Mutex
|
45
|
-
# On 1.9 and up, this is in core, so we just use the real one
|
46
|
-
Mutex = ::Mutex
|
47
|
-
else # For 1.8.7
|
48
|
-
# :nocov:
|
49
|
-
RSpec::Support.require_rspec_mocks "mutex"
|
50
|
-
# :nocov:
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|