rspec-mocks 3.2.1 → 3.3.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 +47 -0
- data/README.md +2 -2
- data/lib/rspec/mocks/any_instance.rb +1 -0
- data/lib/rspec/mocks/any_instance/chain.rb +1 -1
- data/lib/rspec/mocks/any_instance/error_generator.rb +31 -0
- data/lib/rspec/mocks/any_instance/message_chains.rb +1 -3
- data/lib/rspec/mocks/any_instance/recorder.rb +7 -10
- data/lib/rspec/mocks/argument_list_matcher.rb +3 -3
- data/lib/rspec/mocks/configuration.rb +6 -5
- data/lib/rspec/mocks/error_generator.rb +163 -111
- data/lib/rspec/mocks/example_methods.rb +2 -5
- data/lib/rspec/mocks/matchers/have_received.rb +6 -9
- data/lib/rspec/mocks/message_chain.rb +0 -4
- data/lib/rspec/mocks/message_expectation.rb +56 -53
- data/lib/rspec/mocks/method_double.rb +13 -9
- data/lib/rspec/mocks/method_reference.rb +37 -0
- data/lib/rspec/mocks/proxy.rb +26 -18
- data/lib/rspec/mocks/test_double.rb +40 -5
- data/lib/rspec/mocks/verifying_double.rb +11 -16
- data/lib/rspec/mocks/verifying_proxy.rb +31 -7
- data/lib/rspec/mocks/version.rb +1 -1
- metadata +8 -7
- metadata.gz.sig +0 -0
@@ -39,7 +39,7 @@ module RSpec
|
|
39
39
|
|
40
40
|
# @private
|
41
41
|
def inspect
|
42
|
-
|
42
|
+
TestDoubleFormatter.format(self)
|
43
43
|
end
|
44
44
|
|
45
45
|
# @private
|
@@ -91,14 +91,14 @@ module RSpec
|
|
91
91
|
# https://github.com/jruby/jruby/issues/1398
|
92
92
|
visibility = proxy.visibility_for(message)
|
93
93
|
if visibility == :private || visibility == :protected
|
94
|
-
ErrorGenerator.new(self
|
94
|
+
ErrorGenerator.new(self).raise_non_public_error(
|
95
95
|
message, visibility
|
96
96
|
)
|
97
97
|
end
|
98
98
|
|
99
99
|
# Required wrapping doubles in an Array on Ruby 1.9.2
|
100
100
|
raise NoMethodError if [:to_a, :to_ary].include? message
|
101
|
-
proxy.raise_unexpected_message_error(message,
|
101
|
+
proxy.raise_unexpected_message_error(message, args)
|
102
102
|
end
|
103
103
|
|
104
104
|
def assign_stubs(stubs)
|
@@ -112,12 +112,12 @@ module RSpec
|
|
112
112
|
end
|
113
113
|
|
114
114
|
def __build_mock_proxy(order_group)
|
115
|
-
TestDoubleProxy.new(self, order_group
|
115
|
+
TestDoubleProxy.new(self, order_group)
|
116
116
|
end
|
117
117
|
|
118
118
|
def __raise_expired_error
|
119
119
|
return false unless @__expired
|
120
|
-
ErrorGenerator.new(self
|
120
|
+
ErrorGenerator.new(self).raise_expired_test_double_error
|
121
121
|
end
|
122
122
|
|
123
123
|
def initialize_copy(other)
|
@@ -131,5 +131,40 @@ module RSpec
|
|
131
131
|
class Double
|
132
132
|
include TestDouble
|
133
133
|
end
|
134
|
+
|
135
|
+
# @private
|
136
|
+
module TestDoubleFormatter
|
137
|
+
def self.format(dbl, unwrap=false)
|
138
|
+
format = "#{type_desc(dbl)}#{verified_module_desc(dbl)} #{name_desc(dbl)}"
|
139
|
+
return format if unwrap
|
140
|
+
"#<#{format}>"
|
141
|
+
end
|
142
|
+
|
143
|
+
class << self
|
144
|
+
private
|
145
|
+
|
146
|
+
def type_desc(dbl)
|
147
|
+
case dbl
|
148
|
+
when InstanceVerifyingDouble then "InstanceDouble"
|
149
|
+
when ClassVerifyingDouble then "ClassDouble"
|
150
|
+
when ObjectVerifyingDouble then "ObjectDouble"
|
151
|
+
else "Double"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
# @private
|
156
|
+
IVAR_GET = Object.instance_method(:instance_variable_get)
|
157
|
+
|
158
|
+
def verified_module_desc(dbl)
|
159
|
+
return nil unless VerifyingDouble === dbl
|
160
|
+
"(#{IVAR_GET.bind(dbl).call(:@doubled_module).description})"
|
161
|
+
end
|
162
|
+
|
163
|
+
def name_desc(dbl)
|
164
|
+
return "(anonymous)" unless (name = IVAR_GET.bind(dbl).call(:@name))
|
165
|
+
name.inspect
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
134
169
|
end
|
135
170
|
end
|
@@ -1,5 +1,4 @@
|
|
1
1
|
RSpec::Support.require_rspec_mocks 'verifying_proxy'
|
2
|
-
require 'stringio'
|
3
2
|
|
4
3
|
module RSpec
|
5
4
|
module Mocks
|
@@ -35,8 +34,16 @@ module RSpec
|
|
35
34
|
super
|
36
35
|
end
|
37
36
|
|
37
|
+
# @private
|
38
|
+
module SilentIO
|
39
|
+
def self.method_missing(*); end
|
40
|
+
def self.respond_to?(*)
|
41
|
+
true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
38
45
|
# Redefining `__send__` causes ruby to issue a warning.
|
39
|
-
old, $stderr = $stderr,
|
46
|
+
old, $stderr = $stderr, SilentIO
|
40
47
|
def __send__(name, *args, &block)
|
41
48
|
@__sending_message = name
|
42
49
|
super
|
@@ -55,8 +62,6 @@ module RSpec
|
|
55
62
|
possible_name = args.first
|
56
63
|
name = if String === possible_name || Symbol === possible_name
|
57
64
|
args.shift
|
58
|
-
else
|
59
|
-
@description
|
60
65
|
end
|
61
66
|
|
62
67
|
super(name, *args)
|
@@ -73,13 +78,8 @@ module RSpec
|
|
73
78
|
include TestDouble
|
74
79
|
include VerifyingDouble
|
75
80
|
|
76
|
-
def initialize(doubled_module, *args)
|
77
|
-
@description = "#{doubled_module.description} (instance)"
|
78
|
-
super
|
79
|
-
end
|
80
|
-
|
81
81
|
def __build_mock_proxy(order_group)
|
82
|
-
VerifyingProxy.new(self, order_group,
|
82
|
+
VerifyingProxy.new(self, order_group,
|
83
83
|
@doubled_module,
|
84
84
|
InstanceMethodReference
|
85
85
|
)
|
@@ -101,13 +101,8 @@ module RSpec
|
|
101
101
|
|
102
102
|
private
|
103
103
|
|
104
|
-
def initialize(doubled_module, *args)
|
105
|
-
@description = doubled_module.description
|
106
|
-
super
|
107
|
-
end
|
108
|
-
|
109
104
|
def __build_mock_proxy(order_group)
|
110
|
-
VerifyingProxy.new(self, order_group,
|
105
|
+
VerifyingProxy.new(self, order_group,
|
111
106
|
@doubled_module,
|
112
107
|
ObjectMethodReference
|
113
108
|
)
|
@@ -25,7 +25,8 @@ module RSpec
|
|
25
25
|
|
26
26
|
@error_generator.raise_unimplemented_error(
|
27
27
|
@doubled_module,
|
28
|
-
method_name
|
28
|
+
method_name,
|
29
|
+
@object
|
29
30
|
)
|
30
31
|
end
|
31
32
|
|
@@ -55,8 +56,8 @@ module RSpec
|
|
55
56
|
class VerifyingProxy < TestDoubleProxy
|
56
57
|
include VerifyingProxyMethods
|
57
58
|
|
58
|
-
def initialize(object, order_group,
|
59
|
-
super(object, order_group
|
59
|
+
def initialize(object, order_group, doubled_module, method_reference_class)
|
60
|
+
super(object, order_group)
|
60
61
|
@object = object
|
61
62
|
@doubled_module = doubled_module
|
62
63
|
@method_reference_class = method_reference_class
|
@@ -71,7 +72,7 @@ module RSpec
|
|
71
72
|
|
72
73
|
def method_reference
|
73
74
|
@method_reference ||= Hash.new do |h, k|
|
74
|
-
h[k] = @method_reference_class.
|
75
|
+
h[k] = @method_reference_class.for(@doubled_module, k)
|
75
76
|
end
|
76
77
|
end
|
77
78
|
|
@@ -95,7 +96,11 @@ module RSpec
|
|
95
96
|
# A custom method double is required to pass through a way to lookup
|
96
97
|
# methods to determine their parameters.
|
97
98
|
@method_doubles = Hash.new do |h, k|
|
98
|
-
h[k] = VerifyingExistingMethodDouble.
|
99
|
+
h[k] = VerifyingExistingMethodDouble.for(object, k, self)
|
100
|
+
end
|
101
|
+
|
102
|
+
RSpec::Mocks.configuration.verifying_double_callbacks.each do |block|
|
103
|
+
block.call @doubled_module
|
99
104
|
end
|
100
105
|
end
|
101
106
|
|
@@ -158,16 +163,35 @@ module RSpec
|
|
158
163
|
|
159
164
|
# Trigger an eager find of the original method since if we find it any
|
160
165
|
# later we end up getting a stubbed method with incorrect arity.
|
161
|
-
|
166
|
+
save_original_implementation_callable!
|
162
167
|
end
|
163
168
|
|
164
169
|
def with_signature
|
165
|
-
yield Support::MethodSignature.new(
|
170
|
+
yield Support::MethodSignature.new(original_implementation_callable)
|
166
171
|
end
|
167
172
|
|
168
173
|
def unimplemented?
|
169
174
|
!@valid_method
|
170
175
|
end
|
176
|
+
|
177
|
+
def self.for(object, method_name, proxy)
|
178
|
+
if ClassNewMethodReference.applies_to?(method_name) { object }
|
179
|
+
VerifyingExistingClassNewMethodDouble
|
180
|
+
else
|
181
|
+
self
|
182
|
+
end.new(object, method_name, proxy)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
# Used in place of a `VerifyingExistingMethodDouble` for the specific case
|
187
|
+
# of mocking or stubbing a `new` method on a class. In this case, we substitute
|
188
|
+
# the method signature from `#initialize` since new's signature is just `*args`.
|
189
|
+
#
|
190
|
+
# @private
|
191
|
+
class VerifyingExistingClassNewMethodDouble < VerifyingExistingMethodDouble
|
192
|
+
def with_signature
|
193
|
+
yield Support::MethodSignature.new(object.instance_method(:initialize))
|
194
|
+
end
|
171
195
|
end
|
172
196
|
end
|
173
197
|
end
|
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.
|
4
|
+
version: 3.3.0
|
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-
|
48
|
+
date: 2015-06-12 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.
|
56
|
+
version: 3.3.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.
|
63
|
+
version: 3.3.0
|
64
64
|
- !ruby/object:Gem::Dependency
|
65
65
|
name: diff-lcs
|
66
66
|
requirement: !ruby/object:Gem::Requirement
|
@@ -151,6 +151,7 @@ files:
|
|
151
151
|
- lib/rspec/mocks.rb
|
152
152
|
- lib/rspec/mocks/any_instance.rb
|
153
153
|
- lib/rspec/mocks/any_instance/chain.rb
|
154
|
+
- lib/rspec/mocks/any_instance/error_generator.rb
|
154
155
|
- lib/rspec/mocks/any_instance/expect_chain_chain.rb
|
155
156
|
- lib/rspec/mocks/any_instance/expectation_chain.rb
|
156
157
|
- lib/rspec/mocks/any_instance/message_chains.rb
|
@@ -207,10 +208,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
208
|
- !ruby/object:Gem::Version
|
208
209
|
version: '0'
|
209
210
|
requirements: []
|
210
|
-
rubyforge_project:
|
211
|
-
rubygems_version: 2.
|
211
|
+
rubyforge_project:
|
212
|
+
rubygems_version: 2.2.2
|
212
213
|
signing_key:
|
213
214
|
specification_version: 4
|
214
|
-
summary: rspec-mocks-3.
|
215
|
+
summary: rspec-mocks-3.3.0
|
215
216
|
test_files: []
|
216
217
|
has_rdoc:
|
metadata.gz.sig
CHANGED
Binary file
|