rspec-mocks 3.0.4 → 3.1.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.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Changelog.md +26 -0
  5. data/README.md +29 -15
  6. data/lib/rspec/mocks/any_instance/chain.rb +2 -2
  7. data/lib/rspec/mocks/any_instance/expectation_chain.rb +2 -3
  8. data/lib/rspec/mocks/any_instance/message_chains.rb +8 -7
  9. data/lib/rspec/mocks/any_instance/proxy.rb +2 -2
  10. data/lib/rspec/mocks/any_instance/recorder.rb +27 -25
  11. data/lib/rspec/mocks/any_instance/stub_chain.rb +3 -5
  12. data/lib/rspec/mocks/argument_list_matcher.rb +4 -4
  13. data/lib/rspec/mocks/argument_matchers.rb +23 -5
  14. data/lib/rspec/mocks/configuration.rb +3 -10
  15. data/lib/rspec/mocks/error_generator.rb +33 -27
  16. data/lib/rspec/mocks/example_methods.rb +74 -6
  17. data/lib/rspec/mocks/instance_method_stasher.rb +5 -5
  18. data/lib/rspec/mocks/matchers/have_received.rb +7 -8
  19. data/lib/rspec/mocks/matchers/receive.rb +8 -8
  20. data/lib/rspec/mocks/matchers/receive_message_chain.rb +4 -5
  21. data/lib/rspec/mocks/matchers/receive_messages.rb +6 -7
  22. data/lib/rspec/mocks/message_chain.rb +5 -5
  23. data/lib/rspec/mocks/message_expectation.rb +56 -28
  24. data/lib/rspec/mocks/method_double.rb +15 -12
  25. data/lib/rspec/mocks/method_reference.rb +8 -7
  26. data/lib/rspec/mocks/mutate_const.rb +26 -100
  27. data/lib/rspec/mocks/object_reference.rb +12 -13
  28. data/lib/rspec/mocks/order_group.rb +4 -5
  29. data/lib/rspec/mocks/proxy.rb +31 -25
  30. data/lib/rspec/mocks/space.rb +24 -24
  31. data/lib/rspec/mocks/syntax.rb +8 -8
  32. data/lib/rspec/mocks/targets.rb +6 -6
  33. data/lib/rspec/mocks/test_double.rb +3 -3
  34. data/lib/rspec/mocks/verifying_double.rb +10 -12
  35. data/lib/rspec/mocks/verifying_message_expecation.rb +15 -13
  36. data/lib/rspec/mocks/verifying_proxy.rb +11 -15
  37. data/lib/rspec/mocks/version.rb +1 -1
  38. metadata +5 -5
  39. metadata.gz.sig +0 -0
@@ -5,23 +5,23 @@ module RSpec
5
5
  # the scope of an example. Called "root" because it serves
6
6
  # as the root of the space stack.
7
7
  class RootSpace
8
- def proxy_for(*args)
8
+ def proxy_for(*_args)
9
9
  raise_lifecycle_message
10
10
  end
11
11
 
12
- def any_instance_recorder_for(*args)
12
+ def any_instance_recorder_for(*_args)
13
13
  raise_lifecycle_message
14
14
  end
15
15
 
16
- def any_instance_proxy_for(*args)
16
+ def any_instance_proxy_for(*_args)
17
17
  raise_lifecycle_message
18
18
  end
19
19
 
20
- def register_constant_mutator(mutator)
20
+ def register_constant_mutator(_mutator)
21
21
  raise_lifecycle_message
22
22
  end
23
23
 
24
- def any_instance_recorders_from_ancestry_of(object)
24
+ def any_instance_recorders_from_ancestry_of(_object)
25
25
  raise_lifecycle_message
26
26
  end
27
27
 
@@ -31,7 +31,7 @@ module RSpec
31
31
  def verify_all
32
32
  end
33
33
 
34
- def registered?(object)
34
+ def registered?(_object)
35
35
  false
36
36
  end
37
37
 
@@ -43,7 +43,7 @@ module RSpec
43
43
 
44
44
  def raise_lifecycle_message
45
45
  raise OutsideOfExampleError,
46
- "The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported."
46
+ "The use of doubles or partial doubles from rspec-mocks outside of the per-test lifecycle is not supported."
47
47
  end
48
48
  end
49
49
 
@@ -84,7 +84,7 @@ module RSpec
84
84
  @constant_mutators.find { |m| m.full_constant_name == name }
85
85
  end
86
86
 
87
- def any_instance_recorder_for(klass, only_return_existing = false)
87
+ def any_instance_recorder_for(klass, only_return_existing=false)
88
88
  any_instance_mutex.synchronize do
89
89
  id = klass.__id__
90
90
  any_instance_recorders.fetch(id) do
@@ -112,7 +112,7 @@ module RSpec
112
112
  alias ensure_registered proxy_for
113
113
 
114
114
  def registered?(object)
115
- proxies.has_key?(id_for object)
115
+ proxies.key?(id_for object)
116
116
  end
117
117
 
118
118
  def any_instance_recorders_from_ancestry_of(object)
@@ -147,21 +147,21 @@ module RSpec
147
147
 
148
148
  def proxy_not_found_for(id, object)
149
149
  proxies[id] = case object
150
- when NilClass then ProxyForNil.new(@expectation_ordering)
151
- when TestDouble then object.__build_mock_proxy_unless_expired(@expectation_ordering)
152
- when Class
153
- if RSpec::Mocks.configuration.verify_partial_doubles?
154
- VerifyingPartialClassDoubleProxy.new(self, object, @expectation_ordering)
155
- else
156
- PartialClassDoubleProxy.new(self, object, @expectation_ordering)
157
- end
158
- else
159
- if RSpec::Mocks.configuration.verify_partial_doubles?
160
- VerifyingPartialDoubleProxy.new(object, @expectation_ordering)
161
- else
162
- PartialDoubleProxy.new(object, @expectation_ordering)
163
- end
164
- end
150
+ when NilClass then ProxyForNil.new(@expectation_ordering)
151
+ when TestDouble then object.__build_mock_proxy_unless_expired(@expectation_ordering)
152
+ when Class
153
+ if RSpec::Mocks.configuration.verify_partial_doubles?
154
+ VerifyingPartialClassDoubleProxy.new(self, object, @expectation_ordering)
155
+ else
156
+ PartialClassDoubleProxy.new(self, object, @expectation_ordering)
157
+ end
158
+ else
159
+ if RSpec::Mocks.configuration.verify_partial_doubles?
160
+ VerifyingPartialDoubleProxy.new(object, @expectation_ordering)
161
+ else
162
+ PartialDoubleProxy.new(object, @expectation_ordering)
163
+ end
164
+ end
165
165
  end
166
166
 
167
167
  def any_instance_recorder_not_found_for(id, klass)
@@ -10,7 +10,7 @@ module RSpec
10
10
  end
11
11
 
12
12
  # @private
13
- def self.warn_unless_should_configured(method_name ,replacement = "the new `:expect` syntax or explicitly enable `:should`")
13
+ def self.warn_unless_should_configured(method_name , replacement="the new `:expect` syntax or explicitly enable `:should`")
14
14
  if @warn_about_should
15
15
  RSpec.deprecate(
16
16
  "Using `#{method_name}` from rspec-mocks' old `:should` syntax without explicitly enabling the syntax",
@@ -23,7 +23,7 @@ module RSpec
23
23
 
24
24
  # @api private
25
25
  # Enables the should syntax (`dbl.stub`, `dbl.should_receive`, etc).
26
- def self.enable_should(syntax_host = default_should_syntax_host)
26
+ def self.enable_should(syntax_host=default_should_syntax_host)
27
27
  @warn_about_should = false if syntax_host == default_should_syntax_host
28
28
  return if should_enabled?(syntax_host)
29
29
 
@@ -41,7 +41,7 @@ module RSpec
41
41
  def stub(message_or_hash, opts={}, &block)
42
42
  ::RSpec::Mocks::Syntax.warn_unless_should_configured(__method__)
43
43
  if ::Hash === message_or_hash
44
- message_or_hash.each {|message, value| stub(message).and_return value }
44
+ message_or_hash.each { |message, value| stub(message).and_return value }
45
45
  else
46
46
  ::RSpec::Mocks.allow_message(self, message_or_hash, opts, &block)
47
47
  end
@@ -86,7 +86,7 @@ module RSpec
86
86
 
87
87
  # @api private
88
88
  # Disables the should syntax (`dbl.stub`, `dbl.should_receive`, etc).
89
- def self.disable_should(syntax_host = default_should_syntax_host)
89
+ def self.disable_should(syntax_host=default_should_syntax_host)
90
90
  return unless should_enabled?(syntax_host)
91
91
 
92
92
  syntax_host.class_exec do
@@ -107,7 +107,7 @@ module RSpec
107
107
 
108
108
  # @api private
109
109
  # Enables the expect syntax (`expect(dbl).to receive`, `allow(dbl).to receive`, etc).
110
- def self.enable_expect(syntax_host = ::RSpec::Mocks::ExampleMethods)
110
+ def self.enable_expect(syntax_host=::RSpec::Mocks::ExampleMethods)
111
111
  return if expect_enabled?(syntax_host)
112
112
 
113
113
  syntax_host.class_exec do
@@ -147,7 +147,7 @@ module RSpec
147
147
 
148
148
  # @api private
149
149
  # Disables the expect syntax (`expect(dbl).to receive`, `allow(dbl).to receive`, etc).
150
- def self.disable_expect(syntax_host = ::RSpec::Mocks::ExampleMethods)
150
+ def self.disable_expect(syntax_host=::RSpec::Mocks::ExampleMethods)
151
151
  return unless expect_enabled?(syntax_host)
152
152
 
153
153
  syntax_host.class_exec do
@@ -166,13 +166,13 @@ module RSpec
166
166
 
167
167
  # @api private
168
168
  # Indicates whether or not the should syntax is enabled.
169
- def self.should_enabled?(syntax_host = default_should_syntax_host)
169
+ def self.should_enabled?(syntax_host=default_should_syntax_host)
170
170
  syntax_host.method_defined?(:should_receive)
171
171
  end
172
172
 
173
173
  # @api private
174
174
  # Indicates whether or not the expect syntax is enabled.
175
- def self.expect_enabled?(syntax_host = ::RSpec::Mocks::ExampleMethods)
175
+ def self.expect_enabled?(syntax_host=::RSpec::Mocks::ExampleMethods)
176
176
  syntax_host.method_defined?(:allow)
177
177
  end
178
178
 
@@ -15,7 +15,7 @@ module RSpec
15
15
  end
16
16
  end
17
17
 
18
- def self.delegate_not_to(matcher_method, options = {})
18
+ def self.delegate_not_to(matcher_method, options={})
19
19
  method_name = options.fetch(:from)
20
20
  define_method(method_name) do |matcher, &block|
21
21
  case matcher
@@ -30,7 +30,7 @@ module RSpec
30
30
  end
31
31
 
32
32
  def self.disallow_negation(method_name)
33
- define_method(method_name) do |matcher, *args|
33
+ define_method(method_name) do |matcher, *_args|
34
34
  raise_negation_unsupported(method_name, matcher)
35
35
  end
36
36
  end
@@ -47,14 +47,14 @@ module RSpec
47
47
 
48
48
  def raise_unsupported_matcher(method_name, matcher)
49
49
  raise UnsupportedMatcherError,
50
- "only the `receive` or `receive_messages` matchers are supported " +
51
- "with `#{expression}(...).#{method_name}`, but you have provided: #{matcher}"
50
+ "only the `receive` or `receive_messages` matchers are supported " \
51
+ "with `#{expression}(...).#{method_name}`, but you have provided: #{matcher}"
52
52
  end
53
53
 
54
54
  def raise_negation_unsupported(method_name, matcher)
55
55
  raise NegationUnsupportedError,
56
- "`#{expression}(...).#{method_name} #{matcher.name}` is not supported since it " +
57
- "doesn't really make sense. What would it even mean?"
56
+ "`#{expression}(...).#{method_name} #{matcher.name}` is not supported since it " \
57
+ "doesn't really make sense. What would it even mean?"
58
58
  end
59
59
 
60
60
  def expression
@@ -39,12 +39,12 @@ module RSpec
39
39
 
40
40
  # @private
41
41
  def inspect
42
- "#<#{self.class}:#{sprintf '0x%x', self.object_id} @name=#{@name.inspect}>"
42
+ "#<#{self.class}:#{'0x%x' % object_id} @name=#{@name.inspect}>"
43
43
  end
44
44
 
45
45
  # @private
46
46
  def to_s
47
- inspect.gsub('<','[').gsub('>',']')
47
+ inspect.gsub('<', '[').gsub('>', ']')
48
48
  end
49
49
 
50
50
  # @private
@@ -54,7 +54,7 @@ module RSpec
54
54
 
55
55
  # @private
56
56
  def __build_mock_proxy_unless_expired(order_group)
57
- __raise_expired_error or __build_mock_proxy(order_group)
57
+ __raise_expired_error || __build_mock_proxy(order_group)
58
58
  end
59
59
 
60
60
  # @private
@@ -3,7 +3,6 @@ require 'stringio'
3
3
 
4
4
  module RSpec
5
5
  module Mocks
6
-
7
6
  # @private
8
7
  module VerifyingDouble
9
8
  def respond_to?(message, include_private=false)
@@ -11,11 +10,11 @@ module RSpec
11
10
 
12
11
  method_ref = __mock_proxy.method_reference[message]
13
12
 
14
- return case method_ref.visibility
15
- when :public then true
16
- when :private then include_private
17
- when :protected then include_private || RUBY_VERSION.to_f < 2.0
18
- else !method_ref.unimplemented?
13
+ case method_ref.visibility
14
+ when :public then true
15
+ when :private then include_private
16
+ when :protected then include_private || RUBY_VERSION.to_f < 2.0
17
+ else !method_ref.unimplemented?
19
18
  end
20
19
  end
21
20
 
@@ -74,8 +73,8 @@ module RSpec
74
73
 
75
74
  def __build_mock_proxy(order_group)
76
75
  VerifyingProxy.new(self, order_group, @name,
77
- @doubled_module,
78
- InstanceMethodReference
76
+ @doubled_module,
77
+ InstanceMethodReference
79
78
  )
80
79
  end
81
80
  end
@@ -88,7 +87,7 @@ module RSpec
88
87
  include TestDouble
89
88
  include VerifyingDouble
90
89
 
91
- def as_stubbed_const(options = {})
90
+ def as_stubbed_const(options={})
92
91
  ConstantMutator.stub(@doubled_module.const_to_replace, self, options)
93
92
  self
94
93
  end
@@ -102,8 +101,8 @@ module RSpec
102
101
 
103
102
  def __build_mock_proxy(order_group)
104
103
  VerifyingProxy.new(self, order_group, @name,
105
- @doubled_module,
106
- ObjectMethodReference
104
+ @doubled_module,
105
+ ObjectMethodReference
107
106
  )
108
107
  end
109
108
  end
@@ -124,6 +123,5 @@ module RSpec
124
123
  class ClassVerifyingDouble < Module
125
124
  include ObjectVerifyingDoubleMethods
126
125
  end
127
-
128
126
  end
129
127
  end
@@ -2,13 +2,11 @@ RSpec::Support.require_rspec_support 'method_signature_verifier'
2
2
 
3
3
  module RSpec
4
4
  module Mocks
5
-
6
5
  # A message expectation that knows about the real implementation of the
7
6
  # message being expected, so that it can verify that any expectations
8
7
  # have the valid arguments.
9
8
  # @api private
10
9
  class VerifyingMessageExpectation < MessageExpectation
11
-
12
10
  # A level of indirection is used here rather than just passing in the
13
11
  # method itself, since method look up is expensive and we only want to
14
12
  # do it if actually needed.
@@ -27,26 +25,30 @@ module RSpec
27
25
  def with(*args, &block)
28
26
  unless ArgumentMatchers::AnyArgsMatcher === args.first
29
27
  expected_args = if ArgumentMatchers::NoArgsMatcher === args.first
30
- []
31
- elsif args.length > 0
32
- args
33
- else
34
- # No arguments given, this will raise.
35
- super
36
- end
37
-
38
- validate_arguments!(expected_args)
28
+ []
29
+ elsif args.length > 0
30
+ args
31
+ else
32
+ # No arguments given, this will raise.
33
+ super
34
+ end
35
+
36
+ validate_expected_arguments!(expected_args)
39
37
  end
40
38
  super
41
39
  end
42
40
 
43
41
  private
44
42
 
45
- def validate_arguments!(actual_args)
43
+ def validate_expected_arguments!(actual_args)
46
44
  return if method_reference.nil?
47
45
 
48
46
  method_reference.with_signature do |signature|
49
- verifier = Support::MethodSignatureVerifier.new(signature, actual_args)
47
+ verifier = Support::LooseSignatureVerifier.new(
48
+ signature,
49
+ actual_args
50
+ )
51
+
50
52
  unless verifier.valid?
51
53
  # Fail fast is required, otherwise the message expecation will fail
52
54
  # as well ("expected method not called") and clobber this one.
@@ -3,7 +3,6 @@ RSpec::Support.require_rspec_mocks 'method_reference'
3
3
 
4
4
  module RSpec
5
5
  module Mocks
6
-
7
6
  # @private
8
7
  module VerifyingProxyMethods
9
8
  def add_stub(method_name, opts={}, &implementation)
@@ -22,21 +21,20 @@ module RSpec
22
21
  end
23
22
 
24
23
  def ensure_implemented(method_name)
25
- if method_reference[method_name].unimplemented?
26
- @error_generator.raise_unimplemented_error(
27
- @doubled_module,
28
- method_name
29
- )
30
- end
24
+ return unless method_reference[method_name].unimplemented?
25
+
26
+ @error_generator.raise_unimplemented_error(
27
+ @doubled_module,
28
+ method_name
29
+ )
31
30
  end
32
31
 
33
- def ensure_publicly_implemented(method_name, object)
32
+ def ensure_publicly_implemented(method_name, _object)
34
33
  ensure_implemented(method_name)
35
34
  visibility = method_reference[method_name].visibility
36
35
 
37
- unless visibility == :public
38
- @error_generator.raise_non_public_error(method_name, visibility)
39
- end
36
+ return if visibility == :public
37
+ @error_generator.raise_non_public_error(method_name, visibility)
40
38
  end
41
39
  end
42
40
 
@@ -132,10 +130,8 @@ module RSpec
132
130
 
133
131
  def validate_arguments!(actual_args)
134
132
  @method_reference.with_signature do |signature|
135
- verifier = Support::MethodSignatureVerifier.new(signature, actual_args)
136
- unless verifier.valid?
137
- raise ArgumentError, verifier.error_message
138
- end
133
+ verifier = Support::StrictSignatureVerifier.new(signature, actual_args)
134
+ raise ArgumentError, verifier.error_message unless verifier.valid?
139
135
  end
140
136
  end
141
137
  end
@@ -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.0.4'
6
+ STRING = '3.1.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.0.4
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steven Baker
@@ -33,7 +33,7 @@ cert_chain:
33
33
  1yHC1AcSYpvi2dAbOiHT5iQF+krm4wse8KctXgTNnjMsHEoGKulJS2/sZl90jcCz
34
34
  muA=
35
35
  -----END CERTIFICATE-----
36
- date: 2014-08-14 00:00:00.000000000 Z
36
+ date: 2014-09-05 00:00:00.000000000 Z
37
37
  dependencies:
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: rspec-support
@@ -41,14 +41,14 @@ dependencies:
41
41
  requirements:
42
42
  - - "~>"
43
43
  - !ruby/object:Gem::Version
44
- version: 3.0.0
44
+ version: 3.1.0
45
45
  type: :runtime
46
46
  prerelease: false
47
47
  version_requirements: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - "~>"
50
50
  - !ruby/object:Gem::Version
51
- version: 3.0.0
51
+ version: 3.1.0
52
52
  - !ruby/object:Gem::Dependency
53
53
  name: rake
54
54
  requirement: !ruby/object:Gem::Requirement
@@ -179,6 +179,6 @@ rubyforge_project: rspec
179
179
  rubygems_version: 2.2.2
180
180
  signing_key:
181
181
  specification_version: 4
182
- summary: rspec-mocks-3.0.4
182
+ summary: rspec-mocks-3.1.0
183
183
  test_files: []
184
184
  has_rdoc:
metadata.gz.sig CHANGED
Binary file