rspec-mocks 3.6.0.beta2 → 3.6.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/Changelog.md +12 -0
- data/README.md +15 -0
- data/lib/rspec/mocks/any_instance/expect_chain_chain.rb +1 -5
- data/lib/rspec/mocks/any_instance/expectation_chain.rb +7 -5
- data/lib/rspec/mocks/any_instance/stub_chain.rb +9 -5
- data/lib/rspec/mocks/any_instance/stub_chain_chain.rb +1 -6
- data/lib/rspec/mocks/configuration.rb +1 -0
- data/lib/rspec/mocks/error_generator.rb +2 -2
- data/lib/rspec/mocks/example_methods.rb +2 -2
- data/lib/rspec/mocks/instance_method_stasher.rb +11 -0
- data/lib/rspec/mocks/method_double.rb +2 -2
- data/lib/rspec/mocks/mutate_const.rb +4 -0
- data/lib/rspec/mocks/version.rb +1 -1
- metadata +10 -10
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0194543e201f9d8cb6c477dcdeaf678b3f5ce442
|
4
|
+
data.tar.gz: bd1e7cae196ec0d61c4dd714c4371b27e3d8c9f1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 13bfadb0ccb5f89efaa761ab93de080a4d9da94568965e55b03c53e104fb57ec283311e4395ecdb497fcff11f648b6649daaf117b1e486eced3040b1b8b04268
|
7
|
+
data.tar.gz: 627998b4615c8de8e236ac46788da589e9f16acbcfe75d310af7119dff3ee69a0e1eb2981b9947e2b102d546a0c5b2fd06780fc191fb3b2362b102dbb16dc400
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Changelog.md
CHANGED
@@ -1,3 +1,15 @@
|
|
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
|
+
|
1
13
|
### 3.6.0.beta2 / 2016-12-12
|
2
14
|
[Full Changelog](http://github.com/rspec/rspec-mocks/compare/v3.6.0.beta1...v3.6.0.beta2)
|
3
15
|
|
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
|
@@ -35,12 +35,14 @@ module RSpec
|
|
35
35
|
me
|
36
36
|
end
|
37
37
|
|
38
|
-
|
39
|
-
|
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
|
-
|
29
|
-
|
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[
|
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
|
@@ -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 `
|
218
|
-
"To disallow expectations on `nil`, set `
|
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
|
@@ -392,7 +392,7 @@ module RSpec
|
|
392
392
|
def self.included(klass)
|
393
393
|
klass.class_exec do
|
394
394
|
# This gets mixed in so that if `RSpec::Matchers` is included in
|
395
|
-
# `klass` later,
|
395
|
+
# `klass` later, its definition of `expect` will take precedence.
|
396
396
|
include ExpectHost unless method_defined?(:expect)
|
397
397
|
end
|
398
398
|
end
|
@@ -400,7 +400,7 @@ module RSpec
|
|
400
400
|
# @private
|
401
401
|
def self.extended(object)
|
402
402
|
# This gets extended in so that if `RSpec::Matchers` is included in
|
403
|
-
# `klass` later,
|
403
|
+
# `klass` later, its definition of `expect` will take precedence.
|
404
404
|
object.extend ExpectHost unless object.respond_to?(:expect)
|
405
405
|
end
|
406
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
|
@@ -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
|
211
|
-
#
|
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
|
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.6.0
|
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:
|
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
|
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
|
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:
|
210
|
+
version: '0'
|
211
211
|
requirements: []
|
212
212
|
rubyforge_project:
|
213
|
-
rubygems_version: 2.5.
|
213
|
+
rubygems_version: 2.4.5.2
|
214
214
|
signing_key:
|
215
215
|
specification_version: 4
|
216
|
-
summary: rspec-mocks-3.6.0
|
216
|
+
summary: rspec-mocks-3.6.0
|
217
217
|
test_files: []
|
218
218
|
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|