rspec-mocks 3.2.0 → 3.2.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
  SHA1:
3
- metadata.gz: 23676d8c392cc0e21a6fc7fdec5248f084775150
4
- data.tar.gz: fbaf8723ad0840c4da3dc8c6cc21093d2bd2f1c7
3
+ metadata.gz: e4228dd818e7161f972b35380ad510d2c9f42846
4
+ data.tar.gz: 6b51cb642d8ab3a56c2bbacb6670bdbe0f5a8a80
5
5
  SHA512:
6
- metadata.gz: 2563565823fee6d8c5f0a3358af1fb0ed0a12d77f1128c82bcae6d3583cfdd7206d59dfbf2d0213d10ce10c5a480b31317b92194586c0ce7e1fb800e4e8b95c5
7
- data.tar.gz: 00664f4764abbf01ab4c93986454c1d7582abba0fefc378f5abf1a4908fc2e66028242565843377b53e4f58310937d8c7c4747a2b961c9009e36774be83a4e62
6
+ metadata.gz: 33be4cf0a047a9e96eb84a057d59554ec8a0299cd67e8c8a26017f8d4b76f453edbe54754ea8c2362ef117cd1997ad32f0b6c36afb17e04434398f9d7609d601
7
+ data.tar.gz: 15736e89331dd0b9bce1c3a7c96261cd692e4135bfbdc6a3f93adfd972f3453c3283311db099c8404495941dd86df668273ae62eee4e1f7ffcce5cc31aa1c29e
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,16 @@
1
+ ### 3.2.1 / 2015-02-23
2
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.2.0...v3.2.1)
3
+
4
+ Bug Fixes:
5
+
6
+ * Add missing `rspec/support/differ` require so that rspec-mocks can be
7
+ used w/o rspec-expectations (which also loads the differ and hided the
8
+ fact we forgot to require it). (Myron Marston, #893)
9
+ * Revert tracking of received arg mutation (added in 3.2.0 to provide an
10
+ error in a situation we can't support) as our implementation has side
11
+ effects on non-standard objects and there's no solution we could come
12
+ up with that always works. (Myron Marston, #900)
13
+
1
14
  ### 3.2.0 / 2015-02-03
2
15
  [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.1.3...v3.2.0)
3
16
 
data/README.md CHANGED
@@ -136,8 +136,7 @@ class_spy("Invitation") # => same as `class_double("Invitation").as_null_object`
136
136
  object_spy("Invitation") # => same as `object_double("Invitation").as_null_object`
137
137
  ```
138
138
 
139
- Stubbing and verifying messages received in this way implements the Test Spy
140
- pattern.
139
+ Verifying messages received in this way implements the Test Spy pattern.
141
140
 
142
141
  ```ruby
143
142
  invitation = spy('invitation')
@@ -157,6 +156,20 @@ expect(invitation).to have_received(:accept).with(mailer)
157
156
  expect(invitation.accept).to eq(true)
158
157
  ```
159
158
 
159
+ Note that `have_received(...).with(...)` is unable to work properly when
160
+ passed arguments are mutated after the spy records the received message.
161
+ For example, this does not work properly:
162
+
163
+ ```ruby
164
+ greeter = spy("greeter")
165
+
166
+ message = "Hello"
167
+ greeter.greet_with(message)
168
+ message << ", World"
169
+
170
+ expect(greeter).to have_received(:greet_with).with("Hello")
171
+ ```
172
+
160
173
  ## Nomenclature
161
174
 
162
175
  ### Mock Objects and Test Stubs
@@ -17,7 +17,6 @@ module RSpec
17
17
  # Acts like an arg splat, matching any number of args at any point in an arg list.
18
18
  #
19
19
  # @example
20
- #
21
20
  # expect(object).to receive(:message).with(1, 2, any_args)
22
21
  #
23
22
  # # matches any of these:
@@ -31,7 +30,6 @@ module RSpec
31
30
  # Matches any argument at all.
32
31
  #
33
32
  # @example
34
- #
35
33
  # expect(object).to receive(:message).with(anything)
36
34
  def anything
37
35
  AnyArgMatcher::INSTANCE
@@ -40,7 +38,6 @@ module RSpec
40
38
  # Matches no arguments.
41
39
  #
42
40
  # @example
43
- #
44
41
  # expect(object).to receive(:message).with(no_args)
45
42
  def no_args
46
43
  NoArgsMatcher::INSTANCE
@@ -49,7 +46,6 @@ module RSpec
49
46
  # Matches if the actual argument responds to the specified messages.
50
47
  #
51
48
  # @example
52
- #
53
49
  # expect(object).to receive(:message).with(duck_type(:hello))
54
50
  # expect(object).to receive(:message).with(duck_type(:hello, :goodbye))
55
51
  def duck_type(*args)
@@ -59,7 +55,6 @@ module RSpec
59
55
  # Matches a boolean value.
60
56
  #
61
57
  # @example
62
- #
63
58
  # expect(object).to receive(:message).with(boolean())
64
59
  def boolean
65
60
  BooleanMatcher::INSTANCE
@@ -69,7 +64,6 @@ module RSpec
69
64
  # Ignores any additional keys.
70
65
  #
71
66
  # @example
72
- #
73
67
  # expect(object).to receive(:message).with(hash_including(:key => val))
74
68
  # expect(object).to receive(:message).with(hash_including(:key))
75
69
  # expect(object).to receive(:message).with(hash_including(:key, :key2 => val2))
@@ -81,7 +75,6 @@ module RSpec
81
75
  # Ignores duplicates and additional values
82
76
  #
83
77
  # @example
84
- #
85
78
  # expect(object).to receive(:message).with(array_including(1,2,3))
86
79
  # expect(object).to receive(:message).with(array_including([1,2,3]))
87
80
  def array_including(*args)
@@ -92,7 +85,6 @@ module RSpec
92
85
  # Matches a hash that doesn't include the specified key(s) or key/value.
93
86
  #
94
87
  # @example
95
- #
96
88
  # expect(object).to receive(:message).with(hash_excluding(:key => val))
97
89
  # expect(object).to receive(:message).with(hash_excluding(:key))
98
90
  # expect(object).to receive(:message).with(hash_excluding(:key, :key2 => :val2))
@@ -105,7 +97,6 @@ module RSpec
105
97
  # Matches if `arg.instance_of?(klass)`
106
98
  #
107
99
  # @example
108
- #
109
100
  # expect(object).to receive(:message).with(instance_of(Thing))
110
101
  def instance_of(klass)
111
102
  InstanceOf.new(klass)
@@ -114,8 +105,8 @@ module RSpec
114
105
  alias_method :an_instance_of, :instance_of
115
106
 
116
107
  # Matches if `arg.kind_of?(klass)`
117
- # @example
118
108
  #
109
+ # @example
119
110
  # expect(object).to receive(:message).with(kind_of(Thing))
120
111
  def kind_of(klass)
121
112
  KindOf.new(klass)
@@ -19,7 +19,6 @@ module RSpec
19
19
  # Defaults to `true`.
20
20
  #
21
21
  # @example
22
- #
23
22
  # RSpec.configure do |rspec|
24
23
  # rspec.mock_with :rspec do |mocks|
25
24
  # mocks.yield_receiver_to_any_instance_implementation_blocks = false
@@ -35,7 +34,6 @@ module RSpec
35
34
  # the process.
36
35
  #
37
36
  # @example
38
- #
39
37
  # RSpec.configure do |rspec|
40
38
  # rspec.mock_with :rspec do |mocks|
41
39
  # mocks.add_stub_and_should_receive_to Delegator
@@ -55,7 +53,6 @@ module RSpec
55
53
  # disable `expect` syntax.
56
54
  #
57
55
  # @example
58
- #
59
56
  # RSpec.configure do |rspec|
60
57
  # rspec.mock_with :rspec do |mocks|
61
58
  # mocks.syntax = [:expect, :should]
@@ -81,7 +78,6 @@ module RSpec
81
78
  # that are enabled.
82
79
  #
83
80
  # @example
84
- #
85
81
  # unless RSpec::Mocks.configuration.syntax.include?(:expect)
86
82
  # raise "this RSpec extension gem requires the rspec-mocks `:expect` syntax"
87
83
  # end
@@ -107,7 +103,6 @@ module RSpec
107
103
  # Provides a way to perform customisations when verifying doubles.
108
104
  #
109
105
  # @example
110
- #
111
106
  # RSpec::Mocks.configuration.when_declaring_verifying_double do |ref|
112
107
  # ref.some_method!
113
108
  # end
@@ -1,3 +1,5 @@
1
+ RSpec::Support.require_rspec_support 'differ'
2
+
1
3
  module RSpec
2
4
  module Mocks
3
5
  # Raised when a message expectation is not satisfied.
@@ -18,6 +20,9 @@ module RSpec
18
20
  # Raised for situations that RSpec cannot support due to mutations made
19
21
  # externally on arguments that RSpec is holding onto to use for later
20
22
  # comparisons.
23
+ #
24
+ # @deprecated We no longer raise this error but the constant remains until
25
+ # RSpec 4 for SemVer reasons.
21
26
  CannotSupportArgMutationsError = Class.new(StandardError)
22
27
 
23
28
  # @private
@@ -24,7 +24,6 @@ module RSpec
24
24
  # hash of message/return-value pairs.
25
25
  #
26
26
  # @example
27
- #
28
27
  # book = double("book", :title => "The RSpec Book")
29
28
  # book.title #=> "The RSpec Book"
30
29
  #
@@ -219,7 +218,6 @@ module RSpec
219
218
  # @return [Object] the stubbed value of the constant
220
219
  #
221
220
  # @example
222
- #
223
221
  # stub_const("MyClass", Class.new) # => Replaces (or defines) MyClass with a new class object.
224
222
  # stub_const("SomeModel::PER_PAGE", 5) # => Sets SomeModel::PER_PAGE to 5.
225
223
  #
@@ -253,7 +251,6 @@ module RSpec
253
251
  # The current constant scoping at the point of call is not considered.
254
252
  #
255
253
  # @example
256
- #
257
254
  # hide_const("MyClass") # => MyClass is now an undefined constant
258
255
  def hide_const(constant_name)
259
256
  ConstantMutator.hide(constant_name)
@@ -271,13 +268,15 @@ module RSpec
271
268
  # called.
272
269
  #
273
270
  # @example
274
- #
275
271
  # invitation = double('invitation', accept: true)
276
272
  # user.accept_invitation(invitation)
277
273
  # expect(invitation).to have_received(:accept)
278
274
  #
279
275
  # # You can also use most message expectations:
280
276
  # expect(invitation).to have_received(:accept).with(mailer).once
277
+ #
278
+ # @note `have_received(...).with(...)` is unable to work properly when
279
+ # passed arguments are mutated after the spy records the received message.
281
280
  def have_received(method_name, &block)
282
281
  Matchers::HaveReceived.new(method_name, &block)
283
282
  end
@@ -287,7 +286,6 @@ module RSpec
287
286
  # on it.
288
287
  #
289
288
  # @example
290
- #
291
289
  # expect(obj).to receive(:foo).with(5).and_return(:return_value)
292
290
  #
293
291
  # @note This method is usually provided by rspec-expectations. However,
@@ -300,7 +298,6 @@ module RSpec
300
298
  # on it.
301
299
  #
302
300
  # @example
303
- #
304
301
  # allow(dbl).to receive(:foo).with(5).and_return(:return_value)
305
302
  #
306
303
  # @note If you disable the `:expect` syntax this method will be undefined.
@@ -310,7 +307,6 @@ module RSpec
310
307
  # on instances of it.
311
308
  #
312
309
  # @example
313
- #
314
310
  # expect_any_instance_of(MyClass).to receive(:foo)
315
311
  #
316
312
  # @note If you disable the `:expect` syntax this method will be undefined.
@@ -320,7 +316,6 @@ module RSpec
320
316
  # on instances of it.
321
317
  #
322
318
  # @example
323
- #
324
319
  # allow_any_instance_of(MyClass).to receive(:foo)
325
320
  #
326
321
  # @note This is only available when you have enabled the `expect` syntax.
@@ -333,7 +328,6 @@ module RSpec
333
328
  # times, and configure how the object should respond to the message.
334
329
  #
335
330
  # @example
336
- #
337
331
  # expect(obj).to receive(:hello).with("world").exactly(3).times
338
332
  #
339
333
  # @note If you disable the `:expect` syntax this method will be undefined.
@@ -346,7 +340,6 @@ module RSpec
346
340
  # interface.
347
341
  #
348
342
  # @example
349
- #
350
343
  # allow(obj).to receive_messages(:speak => "Hello World")
351
344
  # allow(obj).to receive_messages(:speak => "Hello", :meow => "Meow")
352
345
  #
@@ -370,16 +363,15 @@ module RSpec
370
363
  # implementation calls `foo.baz.bar`, the stub will not work.
371
364
  #
372
365
  # @example
366
+ # allow(double).to receive_message_chain("foo.bar") { :baz }
367
+ # allow(double).to receive_message_chain(:foo, :bar => :baz)
368
+ # allow(double).to receive_message_chain(:foo, :bar) { :baz }
373
369
  #
374
- # allow(double).to receive_message_chain("foo.bar") { :baz }
375
- # allow(double).to receive_message_chain(:foo, :bar => :baz)
376
- # allow(double).to receive_message_chain(:foo, :bar) { :baz }
377
- #
378
- # # Given any of ^^ these three forms ^^:
379
- # double.foo.bar # => :baz
370
+ # # Given any of ^^ these three forms ^^:
371
+ # double.foo.bar # => :baz
380
372
  #
381
- # # Common use in Rails/ActiveRecord:
382
- # allow(Article).to receive_message_chain("recent.published") { [Article.new] }
373
+ # # Common use in Rails/ActiveRecord:
374
+ # allow(Article).to receive_message_chain("recent.published") { [Article.new] }
383
375
  #
384
376
  # @note If you disable the `:expect` syntax this method will be undefined.
385
377
 
@@ -510,17 +510,6 @@ module RSpec
510
510
  @actual_received_count += 1
511
511
  end
512
512
 
513
- def fail_if_problematic_received_arg_mutations(received_arg_list)
514
- return if @argument_list_matcher == ArgumentListMatcher::MATCH_ALL
515
- return unless received_arg_list.has_mutations?
516
-
517
- raise CannotSupportArgMutationsError,
518
- "`have_received(...).with(...)` cannot be used when received " \
519
- "message args have later been mutated. You can use a normal " \
520
- "message expectation (`expect(...).to receive(...).with(...)`) " \
521
- "instead."
522
- end
523
-
524
513
  private
525
514
 
526
515
  def invoke_incrementing_actual_calls_by(increment, allowed_to_fail, parent_stub, *args, &block)
@@ -88,12 +88,7 @@ module RSpec
88
88
  @error_generator.raise_expectation_on_unstubbed_method(expected_method_name)
89
89
  end
90
90
 
91
- @messages_received.each do |(actual_method_name, received_arg_list, _)|
92
- if expectation.message == actual_method_name
93
- expectation.fail_if_problematic_received_arg_mutations(received_arg_list)
94
- end
95
-
96
- args = received_arg_list.args
91
+ @messages_received.each do |(actual_method_name, args, _)|
97
92
  next unless expectation.matches?(actual_method_name, *args)
98
93
 
99
94
  expectation.safe_invoke(nil)
@@ -103,8 +98,7 @@ module RSpec
103
98
 
104
99
  # @private
105
100
  def check_for_unexpected_arguments(expectation)
106
- @messages_received.each do |(method_name, received_arg_list, _)|
107
- args = received_arg_list.args
101
+ @messages_received.each do |(method_name, args, _)|
108
102
  next unless expectation.matches_name_but_not_args(method_name, *args)
109
103
 
110
104
  raise_unexpected_message_args_error(expectation, *args)
@@ -144,11 +138,7 @@ module RSpec
144
138
 
145
139
  # @private
146
140
  def received_message?(method_name, *args, &block)
147
- @messages_received.any? do |(received_method_name, received_arg_list, received_block)|
148
- method_name == received_method_name &&
149
- args == received_arg_list.args &&
150
- block == received_block
151
- end
141
+ @messages_received.any? { |array| array == [method_name, args, block] }
152
142
  end
153
143
 
154
144
  # @private
@@ -159,35 +149,7 @@ module RSpec
159
149
  # @private
160
150
  def record_message_received(message, *args, &block)
161
151
  @order_group.invoked SpecificMessage.new(object, message, args)
162
- @messages_received << [message, ReceivedArgList.new(args), block]
163
- end
164
-
165
- class ReceivedArgList
166
- attr_reader :args
167
-
168
- def initialize(args)
169
- @args = args
170
- @original_hash = hash_of(args)
171
- end
172
-
173
- def has_mutations?
174
- @original_hash != hash_of(args)
175
- end
176
-
177
- private
178
-
179
- def hash_of(arg)
180
- arg.hash
181
- rescue Exception
182
- # While `Object#hash` is a built-in ruby method that we expect args to
183
- # support, there's no guarantee that all args will. For example, a
184
- # `BasicObject` instance will raise a `NoMethodError`. Given that
185
- # we use the hash only to advise the user of a rare case we don't
186
- # support involving mutations, it seems better to ignore this error
187
- # and use a static value in its place (which will make us assume no
188
- # mutation has occurred).
189
- :failed_to_get_hash
190
- end
152
+ @messages_received << [message, args, block]
191
153
  end
192
154
 
193
155
  # @private
@@ -214,11 +214,10 @@ if defined?(BasicObject)
214
214
  # the end of the example.
215
215
  #
216
216
  # @example
217
- #
218
- # logger = double('logger')
219
- # thing_that_logs = ThingThatLogs.new(logger)
220
- # logger.should_receive(:log)
221
- # thing_that_logs.do_something_that_logs_a_message
217
+ # logger = double('logger')
218
+ # thing_that_logs = ThingThatLogs.new(logger)
219
+ # logger.should_receive(:log)
220
+ # thing_that_logs.do_something_that_logs_a_message
222
221
  #
223
222
  # @note This is only available when you have enabled the `should` syntax.
224
223
  # @see RSpec::Mocks::ExampleMethods#expect
@@ -232,10 +231,9 @@ if defined?(BasicObject)
232
231
  # Tells the object to respond to the message with the specified value.
233
232
  #
234
233
  # @example
235
- #
236
- # counter.stub(:count).and_return(37)
237
- # counter.stub(:count => 37)
238
- # counter.stub(:count) { 37 }
234
+ # counter.stub(:count).and_return(37)
235
+ # counter.stub(:count => 37)
236
+ # counter.stub(:count) { 37 }
239
237
  #
240
238
  # @note This is only available when you have enabled the `should` syntax.
241
239
  # @see RSpec::Mocks::ExampleMethods#allow
@@ -269,10 +267,9 @@ if defined?(BasicObject)
269
267
  # implementation calls `foo.baz.bar`, the stub will not work.
270
268
  #
271
269
  # @example
272
- #
273
- # double.stub_chain("foo.bar") { :baz }
274
- # double.stub_chain(:foo, :bar => :baz)
275
- # double.stub_chain(:foo, :bar) { :baz }
270
+ # double.stub_chain("foo.bar") { :baz }
271
+ # double.stub_chain(:foo, :bar => :baz)
272
+ # double.stub_chain(:foo, :bar) { :baz }
276
273
  #
277
274
  # # Given any of ^^ these three forms ^^:
278
275
  # double.foo.bar # => :baz
@@ -311,15 +308,14 @@ class Class
311
308
  # class.
312
309
  #
313
310
  # @example
311
+ # Car.any_instance.should_receive(:go)
312
+ # race = Race.new
313
+ # race.cars << Car.new
314
+ # race.go # assuming this delegates to all of its cars
315
+ # # this example would pass
314
316
  #
315
- # Car.any_instance.should_receive(:go)
316
- # race = Race.new
317
- # race.cars << Car.new
318
- # race.go # assuming this delegates to all of its cars
319
- # # this example would pass
320
- #
321
- # Account.any_instance.stub(:balance) { Money.new(:USD, 25) }
322
- # Account.new.balance # => Money.new(:USD, 25))
317
+ # Account.any_instance.stub(:balance) { Money.new(:USD, 25) }
318
+ # Account.new.balance # => Money.new(:USD, 25))
323
319
  #
324
320
  # @return [Recorder]
325
321
  #
@@ -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.2.0'
6
+ STRING = '3.2.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
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.2.0
4
+ version: 3.2.1
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-02-03 00:00:00.000000000 Z
48
+ date: 2015-02-24 00:00:00.000000000 Z
49
49
  dependencies:
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: rspec-support
@@ -208,9 +208,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
208
  version: '0'
209
209
  requirements: []
210
210
  rubyforge_project: rspec
211
- rubygems_version: 2.2.2
211
+ rubygems_version: 2.4.5
212
212
  signing_key:
213
213
  specification_version: 4
214
- summary: rspec-mocks-3.2.0
214
+ summary: rspec-mocks-3.2.1
215
215
  test_files: []
216
216
  has_rdoc:
metadata.gz.sig CHANGED
Binary file