rspec-mocks 3.6.0.beta1 → 3.6.0

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
  SHA1:
3
- metadata.gz: 8dc8b700a6acee68e71a9a6d76459b12a975c818
4
- data.tar.gz: b6a18ff9aed7115428b4011af1a7d060a856fef9
3
+ metadata.gz: 0194543e201f9d8cb6c477dcdeaf678b3f5ce442
4
+ data.tar.gz: bd1e7cae196ec0d61c4dd714c4371b27e3d8c9f1
5
5
  SHA512:
6
- metadata.gz: c78d4ae88eb1df7fc1b6d5f91da6f14723a9033cbefe482673bed82a4dd9f74042ced61b9c06301f8d159b42401adaaf85a071884f56661b7a35c2f8308976b5
7
- data.tar.gz: 49a87bccd1d7d8bbe7b60225dd353bee56d41d2603e1060f887d9f70379fe15056ea8f7f417593a88a62dfe210b954d057d4b255bbf7600bda1894e8472551f2
6
+ metadata.gz: 13bfadb0ccb5f89efaa761ab93de080a4d9da94568965e55b03c53e104fb57ec283311e4395ecdb497fcff11f648b6649daaf117b1e486eced3040b1b8b04268
7
+ data.tar.gz: 627998b4615c8de8e236ac46788da589e9f16acbcfe75d310af7119dff3ee69a0e1eb2981b9947e2b102d546a0c5b2fd06780fc191fb3b2362b102dbb16dc400
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,3 +1,24 @@
1
+ ### 3.6.0 / 2017-05-04
2
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.6.0.beta2...v3.6.0)
3
+
4
+ Bug Fixes:
5
+
6
+ * Fix "instance variable @color not initialized" warning when using
7
+ rspec-mocks without rspec-core. (Myron Marston, #1142)
8
+ * Restore aliased module methods properly when stubbing on 1.8.7.
9
+ (Samuel Giddins, #1144)
10
+ * Allow a message chain expectation to be constrained by argument(s).
11
+ (Jon Rowe, #1156)
12
+
13
+ ### 3.6.0.beta2 / 2016-12-12
14
+ [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.6.0.beta1...v3.6.0.beta2)
15
+
16
+ Enhancements:
17
+
18
+ * Add new `without_partial_double_verification { }` API that lets you
19
+ temporarily turn off partial double verification for an example.
20
+ (Jon Rowe, #1104)
21
+
1
22
  ### 3.6.0.beta1 / 2016-10-09
2
23
  [Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.5.0...v3.6.0.beta1)
3
24
 
data/README.md CHANGED
@@ -101,6 +101,21 @@ that iterates through them:
101
101
  order.calculate_total_price(double(:price => 1.99), double(:price => 2.99))
102
102
  ```
103
103
 
104
+ ### Stubbing a chain of methods
105
+
106
+ You can use `receive_message_chain` in place of `receive` to stub a chain of messages:
107
+
108
+ ```ruby
109
+ allow(double).to receive_message_chain("foo.bar") { :baz }
110
+ allow(double).to receive_message_chain(:foo, :bar => :baz)
111
+ allow(double).to receive_message_chain(:foo, :bar) { :baz }
112
+
113
+ # Given any of the above forms:
114
+ double.foo.bar # => :baz
115
+ ```
116
+
117
+ Chains can be arbitrarily long, which makes it quite painless to violate the Law of Demeter in violent ways, so you should consider any use of `receive_message_chain` a code smell. Even though not all code smells indicate real problems (think fluent interfaces), `receive_message_chain` still results in brittle examples. For example, if you write `allow(foo).to receive_message_chain(:bar, :baz => 37)` in a spec and then the implementation calls `foo.baz.bar`, the stub will not work.
118
+
104
119
  ## Consecutive return values
105
120
 
106
121
  When a stub might be invoked more than once, you can provide additional
@@ -23,11 +23,7 @@ module RSpec
23
23
  end
24
24
 
25
25
  def invocation_order
26
- @invocation_order ||= {
27
- :and_return => [nil],
28
- :and_raise => [nil],
29
- :and_yield => [nil]
30
- }
26
+ EmptyInvocationOrder
31
27
  end
32
28
  end
33
29
  end
@@ -35,12 +35,14 @@ module RSpec
35
35
  me
36
36
  end
37
37
 
38
- def invocation_order
39
- @invocation_order ||= {
40
- :with => [nil],
38
+ ExpectationInvocationOrder =
39
+ {
41
40
  :and_return => [:with, nil],
42
- :and_raise => [:with, nil]
43
- }
41
+ :and_raise => [:with, nil],
42
+ }.freeze
43
+
44
+ def invocation_order
45
+ ExpectationInvocationOrder
44
46
  end
45
47
  end
46
48
  end
@@ -25,20 +25,24 @@ module RSpec
25
25
  stub
26
26
  end
27
27
 
28
- def invocation_order
29
- @invocation_order ||= {
30
- :with => [nil],
28
+ InovcationOrder =
29
+ {
31
30
  :and_return => [:with, nil],
32
31
  :and_raise => [:with, nil],
33
32
  :and_yield => [:with, :and_yield, nil],
34
33
  :and_throw => [:with, nil],
35
34
  :and_call_original => [:with, nil],
36
35
  :and_wrap_original => [:with, nil]
37
- }
36
+ }.freeze
37
+
38
+ EmptyInvocationOrder = {}.freeze
39
+
40
+ def invocation_order
41
+ InovcationOrder
38
42
  end
39
43
 
40
44
  def verify_invocation_order(rspec_method_name, *_args, &_block)
41
- return if invocation_order[rspec_method_name].include?(last_message)
45
+ return if invocation_order.fetch(rspec_method_name, [nil]).include?(last_message)
42
46
  raise NoMethodError, "Undefined method #{rspec_method_name}"
43
47
  end
44
48
  end
@@ -15,12 +15,7 @@ module RSpec
15
15
  end
16
16
 
17
17
  def invocation_order
18
- @invocation_order ||= {
19
- :with => [nil],
20
- :and_return => [nil],
21
- :and_raise => [nil],
22
- :and_yield => [nil]
23
- }
18
+ EmptyInvocationOrder
24
19
  end
25
20
  end
26
21
  end
@@ -8,6 +8,8 @@ module RSpec
8
8
  @verify_doubled_constant_names = false
9
9
  @transfer_nested_constants = false
10
10
  @verify_partial_doubles = false
11
+ @temporarily_suppress_partial_double_verification = false
12
+ @color = false
11
13
  end
12
14
 
13
15
  # Sets whether RSpec will warn, ignore, or fail a test when
@@ -153,6 +155,11 @@ module RSpec
153
155
  @verify_partial_doubles
154
156
  end
155
157
 
158
+ # @private
159
+ # Used to track wether we are temporarily suppressing verifying partial
160
+ # doubles with `without_partial_double_verification { ... }`
161
+ attr_accessor :temporarily_suppress_partial_double_verification
162
+
156
163
  if ::RSpec.respond_to?(:configuration)
157
164
  def color?
158
165
  ::RSpec.configuration.color_enabled?
@@ -214,8 +214,8 @@ module RSpec
214
214
 
215
215
  def expectation_on_nil_message(method_name)
216
216
  "An expectation of `:#{method_name}` was set on `nil`. " \
217
- "To allow expectations on `nil` and suppress this message, set `config.allow_message_expectations_on_nil` to `true`. " \
218
- "To disallow expectations on `nil`, set `config.allow_message_expectations_on_nil` to `false`"
217
+ "To allow expectations on `nil` and suppress this message, set `RSpec::Mocks.configuration.allow_message_expectations_on_nil` to `true`. " \
218
+ "To disallow expectations on `nil`, set `RSpec::Mocks.configuration.allow_message_expectations_on_nil` to `false`"
219
219
  end
220
220
 
221
221
  # @private
@@ -282,6 +282,18 @@ module RSpec
282
282
  Matchers::HaveReceived.new(method_name, &block)
283
283
  end
284
284
 
285
+ # Turns off the verifying of partial doubles for the duration of the
286
+ # block, this is useful in situations where methods are defined at run
287
+ # time and you wish to define stubs for them but not turn off partial
288
+ # doubles for the entire run suite. (e.g. view specs in rspec-rails).
289
+ def without_partial_double_verification
290
+ original_state = Mocks.configuration.temporarily_suppress_partial_double_verification
291
+ Mocks.configuration.temporarily_suppress_partial_double_verification = true
292
+ yield
293
+ ensure
294
+ Mocks.configuration.temporarily_suppress_partial_double_verification = original_state
295
+ end
296
+
285
297
  # @method expect
286
298
  # Used to wrap an object in preparation for setting a mock expectation
287
299
  # on it.
@@ -380,7 +392,7 @@ module RSpec
380
392
  def self.included(klass)
381
393
  klass.class_exec do
382
394
  # This gets mixed in so that if `RSpec::Matchers` is included in
383
- # `klass` later, it's definition of `expect` will take precedence.
395
+ # `klass` later, its definition of `expect` will take precedence.
384
396
  include ExpectHost unless method_defined?(:expect)
385
397
  end
386
398
  end
@@ -388,7 +400,7 @@ module RSpec
388
400
  # @private
389
401
  def self.extended(object)
390
402
  # This gets extended in so that if `RSpec::Matchers` is included in
391
- # `klass` later, it's definition of `expect` will take precedence.
403
+ # `klass` later, its definition of `expect` will take precedence.
392
404
  object.extend ExpectHost unless object.respond_to?(:expect)
393
405
  end
394
406
 
@@ -128,6 +128,17 @@ module RSpec
128
128
  # Hence, we verify that the owner actually has the method defined.
129
129
  # If the given owner does not have the method defined, we assume
130
130
  # that the method is actually owned by @klass.
131
+ #
132
+ # On 1.8, aliased methods can also report the wrong owner. Example:
133
+ # module M
134
+ # def a; end
135
+ # module_function :a
136
+ # alias b a
137
+ # module_function :b
138
+ # end
139
+ # The owner of M.b is the raw Module object, instead of the expected
140
+ # singleton class of the module
141
+ return true if RUBY_VERSION < '1.9' && owner == @object
131
142
  owner == @klass || !(method_defined_on_klass?(owner))
132
143
  end
133
144
  end
@@ -330,7 +330,7 @@ module RSpec
330
330
  def ordered(&block)
331
331
  if type == :stub
332
332
  RSpec.warning(
333
- "`allow(...).to receive(..).ordered` is not supported and will" \
333
+ "`allow(...).to receive(..).ordered` is not supported and will " \
334
334
  "have no effect, use `and_return(*ordered_values)` instead."
335
335
  )
336
336
  end
@@ -207,8 +207,8 @@ module RSpec
207
207
 
208
208
  # In Ruby 2.0.0 and above prepend will alter the method lookup chain.
209
209
  # We use an object's singleton class to define method doubles upon,
210
- # however if the object has had it's singleton class (as opposed to
211
- # it's actual class) prepended too then the the method lookup chain
210
+ # however if the object has had its singleton class (as opposed to
211
+ # its actual class) prepended too then the the method lookup chain
212
212
  # will look in the prepended module first, **before** the singleton
213
213
  # class.
214
214
  #
@@ -105,6 +105,10 @@ module RSpec
105
105
  # so you can stub constants in other contexts (e.g. helper
106
106
  # classes).
107
107
  def self.stub(constant_name, value, options={})
108
+ unless String === constant_name
109
+ raise ArgumentError, "`stub_const` requires a String, but you provided a #{constant_name.class.name}"
110
+ end
111
+
108
112
  mutator = if recursive_const_defined?(constant_name, &raise_on_invalid_const)
109
113
  DefinedConstantReplacer
110
114
  else
@@ -120,6 +120,11 @@ module RSpec
120
120
  optional_callback_invocation_strategy.call(@doubled_module)
121
121
  end
122
122
 
123
+ def ensure_implemented(_method_name)
124
+ return if Mocks.configuration.temporarily_suppress_partial_double_verification
125
+ super
126
+ end
127
+
123
128
  def method_reference
124
129
  @method_doubles
125
130
  end
@@ -193,6 +198,8 @@ module RSpec
193
198
  def self.for(object, method_name, proxy)
194
199
  if ClassNewMethodReference.applies_to?(method_name) { object }
195
200
  VerifyingExistingClassNewMethodDouble
201
+ elsif Mocks.configuration.temporarily_suppress_partial_double_verification
202
+ MethodDouble
196
203
  else
197
204
  self
198
205
  end.new(object, method_name, proxy)
@@ -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.6.0.beta1'
6
+ STRING = '3.6.0'
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.6.0.beta1
4
+ version: 3.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Baker
@@ -45,22 +45,22 @@ cert_chain:
45
45
  ZsVDj6a7lH3cNqtWXZxrb2wO38qV5AkYj8SQK7Hj3/Yui9myUX3crr+PdetazSqQ
46
46
  F3MdtaDehhjC
47
47
  -----END CERTIFICATE-----
48
- date: 2016-10-10 00:00:00.000000000 Z
48
+ date: 2017-05-04 00:00:00.000000000 Z
49
49
  dependencies:
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: rspec-support
52
52
  requirement: !ruby/object:Gem::Requirement
53
53
  requirements:
54
- - - '='
54
+ - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: 3.6.0.beta1
56
+ version: 3.6.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.6.0.beta1
63
+ version: 3.6.0
64
64
  - !ruby/object:Gem::Dependency
65
65
  name: diff-lcs
66
66
  requirement: !ruby/object:Gem::Requirement
@@ -205,14 +205,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
205
205
  version: 1.8.7
206
206
  required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  requirements:
208
- - - ">"
208
+ - - ">="
209
209
  - !ruby/object:Gem::Version
210
- version: 1.3.1
210
+ version: '0'
211
211
  requirements: []
212
212
  rubyforge_project:
213
- rubygems_version: 2.2.2
213
+ rubygems_version: 2.4.5.2
214
214
  signing_key:
215
215
  specification_version: 4
216
- summary: rspec-mocks-3.6.0.beta1
216
+ summary: rspec-mocks-3.6.0
217
217
  test_files: []
218
218
  has_rdoc:
metadata.gz.sig CHANGED
Binary file