rspec-mocks-diag 3.8.1.2 → 3.9.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cabd49758a2f5b8020f328ab1105cc85886cda2739117cd2015961e2be8d439c
4
- data.tar.gz: c2f58dbff88f7bbebbf1a950f6b3bb47ba42378bbafa45f722f65d523a04b599
3
+ metadata.gz: 8be35928033a695ee980bc47fffc4e52e3bfaae18bece60c4fdb928ae49d28b0
4
+ data.tar.gz: 8a477839418aab6661b7eb23bd150f08ece8015a98b641b2387e2e4582f6b52d
5
5
  SHA512:
6
- metadata.gz: ad6f5c38c0a79a3fa75dbaaf721d7ceeb85d7a23be1e52198f76343fd4e48cc7ab32682bc9964cd290a23754e70ac847325758f26ef73b0350a0c18fe1dded91
7
- data.tar.gz: 72a03fa13751b377146bc4186c604f3e32657292f787d20b14f4ef5270249ff5510302f14cf221b127b0f2ce4313dfe4ec1bad98054a1e18667c199b927e521e
6
+ metadata.gz: 222f5305d179ae0c5326badad390c06121c47cf143984501b7cbd3d8e7e1c15a7d255d92c0cb26716709e32d92896e0dda9c5eb6cb006c0a7f24f0fe2e2829f3
7
+ data.tar.gz: 3c790d7f0b638fff260179b35f931bf6c28951a0a0faef3797dfc2a78b66fffe086af30cd6d379ea758ad2fcc7ed10728ff7bffea06136bc5614973f78384e95
@@ -1,3 +1,28 @@
1
+ ### 3.9.1 / 2019-12-31
2
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.9.0...v3.9.1)
3
+
4
+ Bug Fixes:
5
+
6
+ * Trigger `RSpec::Mocks.configuration.verifying_double_callbacks` when using
7
+ `allow_any_instance_of` or `expect_any_instance_of` (Daniel Orner, #1309)
8
+
9
+ ### 3.9.0 / 2019-10-07
10
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.8.2...v3.9.0)
11
+
12
+ Enhancements:
13
+
14
+ * Improve thread safety of message expectations by using Mutex to prevent
15
+ deadlocking errors. (Ry Biesemeyer, #1236)
16
+ * Add the ability to use `time` as an alias for `times`. For example:
17
+ `expect(Class).to receive(:method).exactly(1).time`.
18
+ (Pistos, Benoit Tigeot, #1271)
19
+
20
+ ### 3.8.2 / 2019-10-02
21
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.8.1...v3.8.2)
22
+
23
+ * Allow `array_including` argument matchers to be nested.
24
+ (Emmanuel Delmas, #1291)
25
+
1
26
  ### 3.8.1 / 2019-06-13
2
27
  [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.8.0...v3.8.1)
3
28
 
data/README.md CHANGED
@@ -285,12 +285,15 @@ expect(double).to receive(:msg).with(hash_excluding(:a => 5)) # first arg is a h
285
285
  ```ruby
286
286
  expect(double).to receive(:msg).once
287
287
  expect(double).to receive(:msg).twice
288
+ expect(double).to receive(:msg).exactly(n).time
288
289
  expect(double).to receive(:msg).exactly(n).times
289
290
  expect(double).to receive(:msg).at_least(:once)
290
291
  expect(double).to receive(:msg).at_least(:twice)
292
+ expect(double).to receive(:msg).at_least(n).time
291
293
  expect(double).to receive(:msg).at_least(n).times
292
294
  expect(double).to receive(:msg).at_most(:once)
293
295
  expect(double).to receive(:msg).at_most(:twice)
296
+ expect(double).to receive(:msg).at_most(n).time
294
297
  expect(double).to receive(:msg).at_most(n).times
295
298
  ```
296
299
 
@@ -327,7 +330,7 @@ expect(double).to receive(:msg).and_return(value)
327
330
  expect(double).to receive(:msg).exactly(3).times.and_return(value1, value2, value3)
328
331
  # returns value1 the first time, value2 the second, etc
329
332
  expect(double).to receive(:msg).and_raise(error)
330
- # error can be an instantiated object or a class
333
+ # `error` can be an instantiated object (e.g. `StandardError.new(some_arg)`) or a class (e.g. `StandardError`)
331
334
  # if it is a class, it must be instantiable with no args
332
335
  expect(double).to receive(:msg).and_throw(:msg)
333
336
  expect(double).to receive(:msg).and_yield(values, to, yield)
@@ -41,6 +41,7 @@ module RSpec
41
41
  record :thrice
42
42
  record :exactly
43
43
  record :times
44
+ record :time
44
45
  record :never
45
46
  record :at_least
46
47
  record :at_most
@@ -12,17 +12,9 @@ module RSpec
12
12
  __raise "#{klass} does not implement ##{method_name}"
13
13
  end
14
14
 
15
- def raise_message_already_received_by_other_instance_error(method_name, object_inspect, invoked_instance, invoked_backtrace)
16
- begin
17
- raise RuntimeError
18
- rescue => e
19
- backtrace = e.backtrace
20
- end
15
+ def raise_message_already_received_by_other_instance_error(method_name, object_inspect, invoked_instance)
21
16
  __raise "The message '#{method_name}' was received by #{object_inspect} " \
22
- "but has already been received by #{invoked_instance}.\nCurrent backtrace:\n" +
23
- backtrace.map { |line| ' ' + line }.join("\n") +
24
- "\nPrevious backtrace: \n" +
25
- invoked_backtrace.map { |line| ' ' + line }.join("\n")
17
+ "but has already been received by #{invoked_instance}"
26
18
  end
27
19
 
28
20
  def raise_not_supported_with_prepend_error(method_name, problem_mod)
@@ -21,6 +21,11 @@ module RSpec
21
21
  @backed_up_method_owner = {}
22
22
  @klass = klass
23
23
  @expectation_set = false
24
+
25
+ return unless RSpec::Mocks.configuration.verify_partial_doubles?
26
+ RSpec::Mocks.configuration.verifying_double_callbacks.each do |block|
27
+ block.call(ObjectReference.for(klass))
28
+ end
24
29
  end
25
30
 
26
31
  # Initializes the recording a stub to be played back against any
@@ -261,16 +266,11 @@ module RSpec
261
266
  def mark_invoked!(method_name)
262
267
  backup_method!(method_name)
263
268
  recorder = self
264
- begin
265
- raise RuntimeError
266
- rescue => e
267
- invoked_backtrace = e.backtrace
268
- end
269
269
  @klass.__send__(:define_method, method_name) do |*_args, &_blk|
270
270
  invoked_instance = recorder.instance_that_received(method_name)
271
271
  inspect = "#<#{self.class}:#{object_id} #{instance_variables.map { |name| "#{name}=#{instance_variable_get name}" }.join(', ')}>"
272
272
  AnyInstance.error_generator.raise_message_already_received_by_other_instance_error(
273
- method_name, inspect, invoked_instance, invoked_backtrace
273
+ method_name, inspect, invoked_instance
274
274
  )
275
275
  end
276
276
  end
@@ -241,6 +241,8 @@ module RSpec
241
241
  RSpec::Support::FuzzyMatcher.values_match?(expected_element, actual_element)
242
242
  end
243
243
  end
244
+ rescue NoMethodError
245
+ false
244
246
  end
245
247
 
246
248
  def description
@@ -47,7 +47,7 @@ module RSpec
47
47
 
48
48
  # @private
49
49
  def raise_unexpected_message_error(message, args)
50
- __raise "#{intro} received unexpected message :#{message} with #{format_args(args)}\nDouble instantiated from:\n#{@target._rspec_backtrace.map { |line| ' ' + line }.join("\n")}"
50
+ __raise "#{intro} received unexpected message :#{message} with #{format_args(args)}"
51
51
  end
52
52
 
53
53
  # @private
@@ -5,7 +5,7 @@ module RSpec
5
5
  class HaveReceived
6
6
  include Matcher
7
7
 
8
- COUNT_CONSTRAINTS = %w[exactly at_least at_most times once twice thrice]
8
+ COUNT_CONSTRAINTS = %w[exactly at_least at_most times time once twice thrice]
9
9
  ARGS_CONSTRAINTS = %w[with]
10
10
  CONSTRAINTS = COUNT_CONSTRAINTS + ARGS_CONSTRAINTS + %w[ordered]
11
11
 
@@ -1,3 +1,5 @@
1
+ RSpec::Support.require_rspec_support 'mutex'
2
+
1
3
  module RSpec
2
4
  module Mocks
3
5
  # A message expectation that only allows concrete return values to be set
@@ -236,6 +238,7 @@ module RSpec
236
238
  self.inner_implementation_action = block
237
239
  self
238
240
  end
241
+ alias time times
239
242
 
240
243
  # Expect a message not to be received at all.
241
244
  #
@@ -357,6 +360,7 @@ module RSpec
357
360
  # some collaborators it delegates to for this stuff but for now this was
358
361
  # the simplest way to split the public from private stuff to make it
359
362
  # easier to publish the docs for the APIs we want published.
363
+ # rubocop:disable Metrics/ModuleLength
360
364
  module ImplementationDetails
361
365
  attr_accessor :error_generator, :implementation
362
366
  attr_reader :message
@@ -378,6 +382,7 @@ module RSpec
378
382
  @orig_object = @method_double.object
379
383
  @message = @method_double.method_name
380
384
  @actual_received_count = 0
385
+ @actual_received_count_write_mutex = Support::Mutex.new
381
386
  @expected_received_count = type == :expectation ? 1 : :any
382
387
  @argument_list_matcher = ArgumentListMatcher::MATCH_ALL
383
388
  @order_group = expectation_ordering
@@ -543,7 +548,9 @@ module RSpec
543
548
  end
544
549
 
545
550
  def increase_actual_received_count!
546
- @actual_received_count += 1
551
+ @actual_received_count_write_mutex.synchronize do
552
+ @actual_received_count += 1
553
+ end
547
554
  end
548
555
 
549
556
  private
@@ -574,7 +581,9 @@ module RSpec
574
581
  parent_stub.invoke(nil, *args, &block)
575
582
  end
576
583
  ensure
577
- @actual_received_count += increment
584
+ @actual_received_count_write_mutex.synchronize do
585
+ @actual_received_count += increment
586
+ end
578
587
  end
579
588
 
580
589
  def has_been_invoked?
@@ -633,6 +642,7 @@ module RSpec
633
642
  nil
634
643
  end
635
644
  end
645
+ # rubocop:enable Metrics/ModuleLength
636
646
 
637
647
  include ImplementationDetails
638
648
  end
@@ -9,6 +9,11 @@ module RSpec
9
9
  end
10
10
  end
11
11
 
12
+ unless defined?(Mutex)
13
+ Support.require_rspec_support 'mutex'
14
+ Mutex = Support::Mutex
15
+ end
16
+
12
17
  # @private
13
18
  def ensure_implemented(*_args)
14
19
  # noop for basic proxies, see VerifyingProxy for behaviour.
@@ -20,6 +25,7 @@ module RSpec
20
25
  @order_group = order_group
21
26
  @error_generator = ErrorGenerator.new(object)
22
27
  @messages_received = []
28
+ @messages_received_mutex = Mutex.new
23
29
  @options = options
24
30
  @null_object = false
25
31
  @method_doubles = Hash.new { |h, k| h[k] = MethodDouble.new(@object, k, self) }
@@ -90,27 +96,31 @@ module RSpec
90
96
  @error_generator.raise_expectation_on_unstubbed_method(expected_method_name)
91
97
  end
92
98
 
93
- @messages_received.each do |(actual_method_name, args, received_block)|
94
- next unless expectation.matches?(actual_method_name, *args)
99
+ @messages_received_mutex.synchronize do
100
+ @messages_received.each do |(actual_method_name, args, received_block)|
101
+ next unless expectation.matches?(actual_method_name, *args)
95
102
 
96
- expectation.safe_invoke(nil)
97
- block.call(*args, &received_block) if block
103
+ expectation.safe_invoke(nil)
104
+ block.call(*args, &received_block) if block
105
+ end
98
106
  end
99
107
  end
100
108
 
101
109
  # @private
102
110
  def check_for_unexpected_arguments(expectation)
103
- return if @messages_received.empty?
111
+ @messages_received_mutex.synchronize do
112
+ return if @messages_received.empty?
104
113
 
105
- return if @messages_received.any? { |method_name, args, _| expectation.matches?(method_name, *args) }
114
+ return if @messages_received.any? { |method_name, args, _| expectation.matches?(method_name, *args) }
106
115
 
107
- name_but_not_args, others = @messages_received.partition do |(method_name, args, _)|
108
- expectation.matches_name_but_not_args(method_name, *args)
109
- end
116
+ name_but_not_args, others = @messages_received.partition do |(method_name, args, _)|
117
+ expectation.matches_name_but_not_args(method_name, *args)
118
+ end
110
119
 
111
- return if name_but_not_args.empty? && !others.empty?
120
+ return if name_but_not_args.empty? && !others.empty?
112
121
 
113
- expectation.raise_unexpected_message_args_error(name_but_not_args.map { |args| args[1] })
122
+ expectation.raise_unexpected_message_args_error(name_but_not_args.map { |args| args[1] })
123
+ end
114
124
  end
115
125
 
116
126
  # @private
@@ -141,17 +151,23 @@ module RSpec
141
151
 
142
152
  # @private
143
153
  def reset
144
- @messages_received.clear
154
+ @messages_received_mutex.synchronize do
155
+ @messages_received.clear
156
+ end
145
157
  end
146
158
 
147
159
  # @private
148
160
  def received_message?(method_name, *args, &block)
149
- @messages_received.any? { |array| array == [method_name, args, block] }
161
+ @messages_received_mutex.synchronize do
162
+ @messages_received.any? { |array| array == [method_name, args, block] }
163
+ end
150
164
  end
151
165
 
152
166
  # @private
153
167
  def messages_arg_list
154
- @messages_received.map { |_, args, _| args }
168
+ @messages_received_mutex.synchronize do
169
+ @messages_received.map { |_, args, _| args }
170
+ end
155
171
  end
156
172
 
157
173
  # @private
@@ -162,7 +178,9 @@ module RSpec
162
178
  # @private
163
179
  def record_message_received(message, *args, &block)
164
180
  @order_group.invoked SpecificMessage.new(object, message, args)
165
- @messages_received << [message, args, block]
181
+ @messages_received_mutex.synchronize do
182
+ @messages_received << [message, args, block]
183
+ end
166
184
  end
167
185
 
168
186
  # @private
@@ -15,18 +15,8 @@ module RSpec
15
15
  @name = name
16
16
  end
17
17
  assign_stubs(stubs)
18
-
19
- begin
20
- raise RuntimeError
21
- rescue => e
22
- @_rspec_backtrace = e.backtrace.dup.tap do |bt|
23
- bt.shift
24
- end
25
- end
26
18
  end
27
19
 
28
- attr_reader :_rspec_backtrace
29
-
30
20
  # Tells the object to respond to all messages. If specific stub values
31
21
  # are declared, they'll work as expected. If not, the receiver is
32
22
  # returned.
@@ -3,7 +3,7 @@ module RSpec
3
3
  # Version information for RSpec mocks.
4
4
  module Version
5
5
  # Version of RSpec mocks currently in use in SemVer format.
6
- STRING = '3.8.1.2'
6
+ STRING = '3.9.1.1'
7
7
  end
8
8
  end
9
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec-mocks-diag
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.1.2
4
+ version: 3.9.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Baker
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2019-08-16 00:00:00.000000000 Z
13
+ date: 2020-01-22 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec-support
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: 3.8.0
21
+ version: 3.9.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: 3.8.0
28
+ version: 3.9.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: diff-lcs
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -80,14 +80,14 @@ dependencies:
80
80
  requirements:
81
81
  - - "~>"
82
82
  - !ruby/object:Gem::Version
83
- version: 0.6.2
83
+ version: 0.14.10
84
84
  type: :development
85
85
  prerelease: false
86
86
  version_requirements: !ruby/object:Gem::Requirement
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: 0.6.2
90
+ version: 0.14.10
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: minitest
93
93
  requirement: !ruby/object:Gem::Requirement
@@ -159,7 +159,7 @@ licenses:
159
159
  - MIT
160
160
  metadata:
161
161
  bug_tracker_uri: https://github.com/p-mongo/rspec-mocks/issues
162
- changelog_uri: https://github.com/p-mongo/rspec-mocks/blob/v3.8.1.2/Changelog.md
162
+ changelog_uri: https://github.com/p-mongo/rspec-mocks/blob/v3.9.1.1/Changelog.md
163
163
  documentation_uri: https://rspec.info/documentation/
164
164
  mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
165
165
  source_code_uri: https://github.com/p-mongo/rspec-mocks
@@ -179,8 +179,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  - !ruby/object:Gem::Version
180
180
  version: '0'
181
181
  requirements: []
182
- rubygems_version: 3.0.3
182
+ rubygems_version: 3.1.2
183
183
  signing_key:
184
184
  specification_version: 4
185
- summary: rspec-mocks-3.8.1.2
185
+ summary: rspec-mocks-3.9.1.1
186
186
  test_files: []