rspec-mocks 3.11.1 → 3.12.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 93e990c0ca803cda14a587b44a4a6148fd60df472f56e58c54be5a2c8ef4a655
4
- data.tar.gz: db0535d24fb98fa0da5c5de3356b687e1b95773624dd38132444f74a57c5d0b7
3
+ metadata.gz: 8c8abef40b0c7af1e3c4e31c39dd5ea6b00b0a38585852d6c7f1c0eaafaf4b01
4
+ data.tar.gz: c96bca0c8abb7db7344dd431f34a3eac93813e476ab20cb7d34709862ef26b64
5
5
  SHA512:
6
- metadata.gz: 7e74e72aec89ffce718f693bfda425f142bfd7139d90c57ff02e62ac461d99f9458df2ffba237bd9163e1665fd9b03a0221f723552d84bffb539a567c3b98f71
7
- data.tar.gz: 6b2b9c447b777b74fcf50eb62a9674b0a4e321cf71165d340017f1ec9050a676c818a608d4d99bb5bb9c1178f44e57505e52c750b22520cb868b05b02812bfc2
6
+ metadata.gz: 5174ad99df46d9c45b1e2fddb7564163a46c9bd5c2def07853abc5113a590b50cd752690fa4e89cd103eb57d79a311df144cd6abfb3f60b7dbae9ce170aa73d0
7
+ data.tar.gz: 924bf170ff82d03b801006aaae1d5457351e8d95c2590cacca34db87d23097b158bc688fb0c0494a2435b1f4dc9540cc63db5ddf63737c514592f54f8b71a29a
checksums.yaml.gz.sig CHANGED
Binary file
data/Changelog.md CHANGED
@@ -1,5 +1,57 @@
1
1
  ### Development
2
- [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.11.1...3-11-maintenance)
2
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.12.3...3-12-maintenance)
3
+
4
+ ### 3.12.3 / 2023-01-17
5
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.12.2...v3.12.3)
6
+
7
+ Bug Fixes:
8
+
9
+ * Fix keyword delegation in `send` for verifying doubles on Ruby 3.
10
+ (Charlie Honig, #1485)
11
+
12
+ ### 3.12.2 / 2023-01-07
13
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.12.1...v3.12.2)
14
+
15
+ Bug Fixes:
16
+
17
+ * Fix implementation blocks for mocks using keyword arguments on Ruby 3.2.0.
18
+ (Adam Steel, #1508)
19
+ * Fix keyword argument assertions when mocking using `with` on Ruby 3.2.0.
20
+ (Slava Kardakov, Benoit Tigeot, Phil Pirozhkov, Benoit Daloze, #1514)
21
+
22
+ ### 3.12.1 / 2022-12-10
23
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.12.0...v3.12.1)
24
+
25
+ Bug Fixes:
26
+
27
+ * Remove empty diff marker when a diff only contains console codes. (Jon Rowe, #1506)
28
+ * Show keyword vs hash diff marker when arguments are not `==` (Jon Rowe, #1506)
29
+ * Change check to detect frozen objects to rescue errors rather than
30
+ pre-empting by checking `frozen?` due to some objects mis-behaving.
31
+ (Keegan Roth, #1401)
32
+ * Prevent unfulfilled expectations using `expect_any_instance_of` across a class
33
+ inheritance boundary from raising rather than failing. (Jon Rowe, #1496)
34
+ * Prevent a misleading error message when using `allow(...).not_to` with
35
+ unsupported matchers. (Phil Pirozhkov, #1503)
36
+
37
+ ### 3.12.0 / 2022-10-26
38
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.11.2...v3.12.0)
39
+
40
+ Enhancements:
41
+
42
+ * Improve diff output when diffing keyword arguments against hashes.
43
+ (Jean Boussier, #1461)
44
+
45
+ ### 3.11.2 / 2022-10-25
46
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.11.1...v3.11.2)
47
+
48
+ Bug Fixes:
49
+
50
+ * Use the original implementation of `Class.new` to detect overridden definitions
51
+ of `new` rather than the owner, fixing detection of "double aliased" methods
52
+ in Ruby 3 and above. (Benoit Daloze, #1470, #1476)
53
+ * Support keyword argument semantics when constraining argument expectations using
54
+ `with` on Ruby 3.0+ with `instance_double` (Andrii Malyshko, #1473)
3
55
 
4
56
  ### 3.11.1 / 2022-03-31
5
57
  [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.11.0...v3.11.1)
@@ -49,7 +49,7 @@ module RSpec
49
49
  # @private
50
50
  def unfulfilled_expectations
51
51
  @chains_by_method_name.map do |method_name, chains|
52
- method_name.to_s if ExpectationChain === chains.last unless chains.last.expectation_fulfilled?
52
+ method_name.to_s if ExpectationChain === chains.last && !chains.last.expectation_fulfilled?
53
53
  end.compact
54
54
  end
55
55
 
@@ -10,7 +10,7 @@ module RSpec
10
10
  #
11
11
  # This proxy sits in front of the recorder and delegates both to it
12
12
  # and to the `RSpec::Mocks::Proxy` for each already mocked or stubbed
13
- # instance of the class, in order to propogates changes to the instances.
13
+ # instance of the class, in order to propagates changes to the instances.
14
14
  #
15
15
  # Note that unlike `RSpec::Mocks::Proxy`, this proxy class is stateless
16
16
  # and is not persisted in `RSpec::Mocks.space`.
@@ -61,7 +61,9 @@ module RSpec
61
61
  return false if expected_args.size != actual_args.size
62
62
 
63
63
  if RUBY_VERSION >= "3"
64
- # if both arguments end with Hashes, and if one is a keyword hash and the other is not, they don't match
64
+ # If the expectation was set with keywords, while the actual method was called with a positional hash argument, they don't match.
65
+ # If the expectation was set without keywords, e.g., with({a: 1}), then it fine to call it with either foo(a: 1) or foo({a: 1}).
66
+ # This corresponds to Ruby semantics, as if the method was def foo(options).
65
67
  if Hash === expected_args.last && Hash === actual_args.last
66
68
  if !Hash.ruby2_keywords_hash?(actual_args.last) && Hash.ruby2_keywords_hash?(expected_args.last)
67
69
  return false
@@ -268,11 +268,32 @@ module RSpec
268
268
  def error_message(expectation, args_for_multiple_calls)
269
269
  expected_args = format_args(expectation.expected_args)
270
270
  actual_args = format_received_args(args_for_multiple_calls)
271
+
272
+ if RSpec::Support::RubyFeatures.distincts_kw_args_from_positional_hash?
273
+ expected_hash = expectation.expected_args.last
274
+ actual_hash = args_for_multiple_calls.last.last
275
+ if Hash === expected_hash && Hash === actual_hash &&
276
+ (Hash.ruby2_keywords_hash?(expected_hash) != Hash.ruby2_keywords_hash?(actual_hash))
277
+
278
+ actual_description = Hash.ruby2_keywords_hash?(actual_hash) ? " (keyword arguments)" : " (options hash)"
279
+ expected_description = Hash.ruby2_keywords_hash?(expected_hash) ? " (keyword arguments)" : " (options hash)"
280
+
281
+ if actual_description != expected_description
282
+ actual_args += actual_description
283
+ expected_args += expected_description
284
+ end
285
+ end
286
+ end
287
+
271
288
  message = default_error_message(expectation, expected_args, actual_args)
272
289
 
273
290
  if args_for_multiple_calls.one?
274
291
  diff = diff_message(expectation.expected_args, args_for_multiple_calls.first)
275
- message << "\nDiff:#{diff}" unless diff.strip.empty?
292
+ if RSpec::Mocks.configuration.color?
293
+ message << "\nDiff:#{diff}" unless diff.gsub(/\e\[\d+m/, '').strip.empty?
294
+ else
295
+ message << "\nDiff:#{diff}" unless diff.strip.empty?
296
+ end
276
297
  end
277
298
 
278
299
  message
@@ -16,7 +16,7 @@ module RSpec
16
16
  @subject = nil
17
17
  end
18
18
 
19
- def name
19
+ def matcher_name
20
20
  "have_received"
21
21
  end
22
22
 
@@ -13,7 +13,7 @@ module RSpec
13
13
  @recorded_customizations = []
14
14
  end
15
15
 
16
- def name
16
+ def matcher_name
17
17
  "receive"
18
18
  end
19
19
 
@@ -20,7 +20,7 @@ module RSpec
20
20
  end
21
21
  end
22
22
 
23
- def name
23
+ def matcher_name
24
24
  "receive_message_chain"
25
25
  end
26
26
 
@@ -10,7 +10,7 @@ module RSpec
10
10
  @backtrace_line = CallerFilter.first_non_rspec_line
11
11
  end
12
12
 
13
- def name
13
+ def matcher_name
14
14
  "receive_messages"
15
15
  end
16
16
 
@@ -406,7 +406,6 @@ module RSpec
406
406
  # some collaborators it delegates to for this stuff but for now this was
407
407
  # the simplest way to split the public from private stuff to make it
408
408
  # easier to publish the docs for the APIs we want published.
409
- # rubocop:disable Metrics/ModuleLength
410
409
  module ImplementationDetails
411
410
  attr_accessor :error_generator, :implementation
412
411
  attr_reader :message
@@ -686,7 +685,6 @@ module RSpec
686
685
  nil
687
686
  end
688
687
  end
689
- # rubocop:enable Metrics/ModuleLength
690
688
 
691
689
  include ImplementationDetails
692
690
  end
@@ -2,6 +2,9 @@ module RSpec
2
2
  module Mocks
3
3
  # @private
4
4
  class MethodDouble
5
+ # @private TODO: drop in favor of FrozenError in ruby 2.5+
6
+ FROZEN_ERROR_MSG = /can't modify frozen/
7
+
5
8
  # @private
6
9
  attr_reader :method_name, :object, :expectations, :stubs, :method_stasher
7
10
 
@@ -70,6 +73,14 @@ module RSpec
70
73
  end
71
74
 
72
75
  @method_is_proxied = true
76
+ rescue RuntimeError, TypeError => e
77
+ # TODO: drop in favor of FrozenError in ruby 2.5+
78
+ # RuntimeError (and FrozenError) for ruby 2.x
79
+ # TypeError for ruby 1.x
80
+ if (defined?(FrozenError) && e.is_a?(FrozenError)) || FROZEN_ERROR_MSG === e.message
81
+ raise ArgumentError, "Cannot proxy frozen objects, rspec-mocks relies on proxies for method stubbing and expectations."
82
+ end
83
+ raise
73
84
  end
74
85
 
75
86
  # The implementation of the proxied method. Subclasses may override this
@@ -83,7 +94,6 @@ module RSpec
83
94
 
84
95
  # @private
85
96
  def restore_original_method
86
- return show_frozen_warning if object_singleton_class.frozen?
87
97
  return unless @method_is_proxied
88
98
 
89
99
  remove_method_from_definition_target
@@ -91,6 +101,14 @@ module RSpec
91
101
  restore_original_visibility
92
102
 
93
103
  @method_is_proxied = false
104
+ rescue RuntimeError, TypeError => e
105
+ # TODO: drop in favor of FrozenError in ruby 2.5+
106
+ # RuntimeError (and FrozenError) for ruby 2.x
107
+ # TypeError for ruby 1.x
108
+ if (defined?(FrozenError) && e.is_a?(FrozenError)) || FROZEN_ERROR_MSG === e.message
109
+ return show_frozen_warning
110
+ end
111
+ raise
94
112
  end
95
113
 
96
114
  # @private
@@ -185,11 +185,23 @@ module RSpec
185
185
  def self.applies_to?(method_name)
186
186
  return false unless method_name == :new
187
187
  klass = yield
188
- return false unless klass.respond_to?(:new, true)
188
+ return false unless ::Class === klass && klass.respond_to?(:new, true)
189
189
 
190
190
  # We only want to apply our special logic to normal `new` methods.
191
191
  # Methods that the user has monkeyed with should be left as-is.
192
- ::RSpec::Support.method_handle_for(klass, :new).owner == ::Class
192
+ uses_class_new?(klass)
193
+ end
194
+
195
+ if RUBY_VERSION.to_i >= 3
196
+ CLASS_NEW = ::Class.instance_method(:new)
197
+
198
+ def self.uses_class_new?(klass)
199
+ ::RSpec::Support.method_handle_for(klass, :new) == CLASS_NEW.bind(klass)
200
+ end
201
+ else # Ruby 2's Method#== is too strict
202
+ def self.uses_class_new?(klass)
203
+ ::RSpec::Support.method_handle_for(klass, :new).owner == ::Class
204
+ end
193
205
  end
194
206
 
195
207
  def with_signature
@@ -37,7 +37,7 @@ if defined?(::Minitest::Expectation)
37
37
  # not want to here (or else we would interfere with rspec-expectations' definition).
38
38
  else
39
39
  # ...otherwise, define those methods now. If `rspec/expectations/minitest_integration`
40
- # is loaded after this file, it'll overide the defintion here.
40
+ # is loaded after this file, it'll override the definition here.
41
41
  Minitest::Expectation.class_eval do
42
42
  include RSpec::Mocks::ExpectationTargetMethods
43
43
 
@@ -81,7 +81,7 @@ module RSpec
81
81
  # Queries rspec-mocks to find out information about the named constant.
82
82
  #
83
83
  # @param [String] name the name of the constant
84
- # @return [Constant] an object contaning information about the named
84
+ # @return [Constant] an object containing information about the named
85
85
  # constant.
86
86
  def self.original(name)
87
87
  mutator = ::RSpec::Mocks.space.constant_mutator_for(name)
@@ -35,15 +35,9 @@ module RSpec
35
35
 
36
36
  # @private
37
37
  def ensure_can_be_proxied!(object)
38
- return unless object.is_a?(Symbol) || object.frozen?
39
- return if object.nil?
38
+ return unless object.is_a?(Symbol)
40
39
 
41
- msg = "Cannot proxy frozen objects"
42
- if Symbol === object
43
- msg << ". Symbols such as #{object} cannot be mocked or stubbed."
44
- else
45
- msg << ", rspec-mocks relies on proxies for method stubbing and expectations."
46
- end
40
+ msg = "Cannot proxy frozen objects. Symbols such as #{object} cannot be mocked or stubbed."
47
41
  raise ArgumentError, msg
48
42
  end
49
43
 
@@ -198,6 +192,7 @@ module RSpec
198
192
  @messages_received << [message, args, block]
199
193
  end
200
194
  end
195
+ ruby2_keywords :record_message_received if respond_to?(:ruby2_keywords, true)
201
196
 
202
197
  # @private
203
198
  def message_received(message, *args, &block)
@@ -54,7 +54,7 @@ module RSpec
54
54
 
55
55
  def raise_negation_unsupported(method_name, matcher)
56
56
  raise NegationUnsupportedError,
57
- "`#{expression}(...).#{method_name} #{matcher.name}` is not supported since it " \
57
+ "`#{expression}(...).#{method_name} #{matcher.matcher_name}` is not supported since it " \
58
58
  "doesn't really make sense. What would it even mean?"
59
59
  end
60
60
  end
@@ -42,11 +42,13 @@ module RSpec
42
42
  ensure
43
43
  @__sending_message = nil
44
44
  end
45
+ ruby2_keywords :__send__ if respond_to?(:ruby2_keywords, true)
45
46
  $VERBOSE = old
46
47
 
47
48
  def send(name, *args, &block)
48
49
  __send__(name, *args, &block)
49
50
  end
51
+ ruby2_keywords :send if respond_to?(:ruby2_keywords, true)
50
52
 
51
53
  def initialize(doubled_module, *args)
52
54
  @doubled_module = doubled_module
@@ -31,6 +31,7 @@ module RSpec
31
31
  end
32
32
  end
33
33
  end
34
+ ruby2_keywords(:with) if respond_to?(:ruby2_keywords, true)
34
35
 
35
36
  private
36
37
 
@@ -57,7 +57,7 @@ module RSpec
57
57
  # A verifying proxy mostly acts like a normal proxy, except that it
58
58
  # contains extra logic to try and determine the validity of any expectation
59
59
  # set on it. This includes whether or not methods have been defined and the
60
- # validatiy of arguments on method calls.
60
+ # validity of arguments on method calls.
61
61
  #
62
62
  # In all other ways this behaves like a normal proxy. It only adds the
63
63
  # verification behaviour to specific methods then delegates to the parent
@@ -147,12 +147,12 @@ module RSpec
147
147
  end
148
148
 
149
149
  def add_expectation(*args, &block)
150
- # explict params necessary for 1.8.7 see #626
150
+ # explicit params necessary for 1.8.7 see #626
151
151
  super(*args, &block).tap { |x| x.method_reference = @method_reference }
152
152
  end
153
153
 
154
154
  def add_stub(*args, &block)
155
- # explict params necessary for 1.8.7 see #626
155
+ # explicit params necessary for 1.8.7 see #626
156
156
  super(*args, &block).tap { |x| x.method_reference = @method_reference }
157
157
  end
158
158
 
@@ -160,6 +160,7 @@ module RSpec
160
160
  validate_arguments!(args)
161
161
  super
162
162
  end
163
+ ruby2_keywords :proxy_method_invoked if respond_to?(:ruby2_keywords, true)
163
164
 
164
165
  def validate_arguments!(actual_args)
165
166
  @method_reference.with_signature do |signature|
@@ -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.11.1'
6
+ STRING = '3.12.3'
7
7
  end
8
8
  end
9
9
  end
data.tar.gz.sig CHANGED
Binary file
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.11.1
4
+ version: 3.12.3
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: 2022-03-31 00:00:00.000000000 Z
48
+ date: 2023-01-17 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.11.0
56
+ version: 3.12.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.11.0
63
+ version: 3.12.0
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: diff-lcs
66
66
  requirement: !ruby/object:Gem::Requirement
@@ -194,7 +194,7 @@ licenses:
194
194
  - MIT
195
195
  metadata:
196
196
  bug_tracker_uri: https://github.com/rspec/rspec-mocks/issues
197
- changelog_uri: https://github.com/rspec/rspec-mocks/blob/v3.11.1/Changelog.md
197
+ changelog_uri: https://github.com/rspec/rspec-mocks/blob/v3.12.3/Changelog.md
198
198
  documentation_uri: https://rspec.info/documentation/
199
199
  mailing_list_uri: https://groups.google.com/forum/#!forum/rspec
200
200
  source_code_uri: https://github.com/rspec/rspec-mocks
@@ -214,8 +214,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
214
214
  - !ruby/object:Gem::Version
215
215
  version: '0'
216
216
  requirements: []
217
- rubygems_version: 3.3.3
217
+ rubygems_version: 3.3.26
218
218
  signing_key:
219
219
  specification_version: 4
220
- summary: rspec-mocks-3.11.1
220
+ summary: rspec-mocks-3.12.3
221
221
  test_files: []
metadata.gz.sig CHANGED
Binary file