mocha 2.7.0 → 2.8.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 (34) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/RELEASE.md +23 -0
  4. data/lib/mocha/api.rb +1 -1
  5. data/lib/mocha/configuration.rb +8 -1
  6. data/lib/mocha/expectation.rb +26 -5
  7. data/lib/mocha/parameter_matchers/all_of.rb +30 -21
  8. data/lib/mocha/parameter_matchers/any_of.rb +36 -27
  9. data/lib/mocha/parameter_matchers/any_parameters.rb +28 -19
  10. data/lib/mocha/parameter_matchers/anything.rb +25 -16
  11. data/lib/mocha/parameter_matchers/base.rb +22 -4
  12. data/lib/mocha/parameter_matchers/deprecations.rb +46 -0
  13. data/lib/mocha/parameter_matchers/equals.rb +31 -22
  14. data/lib/mocha/parameter_matchers/equivalent_uri.rb +30 -21
  15. data/lib/mocha/parameter_matchers/has_entries.rb +31 -22
  16. data/lib/mocha/parameter_matchers/has_entry.rb +72 -65
  17. data/lib/mocha/parameter_matchers/has_key.rb +31 -22
  18. data/lib/mocha/parameter_matchers/has_keys.rb +31 -22
  19. data/lib/mocha/parameter_matchers/has_value.rb +31 -22
  20. data/lib/mocha/parameter_matchers/includes.rb +69 -60
  21. data/lib/mocha/parameter_matchers/instance_methods.rb +1 -1
  22. data/lib/mocha/parameter_matchers/instance_of.rb +31 -22
  23. data/lib/mocha/parameter_matchers/is_a.rb +32 -23
  24. data/lib/mocha/parameter_matchers/kind_of.rb +31 -22
  25. data/lib/mocha/parameter_matchers/not.rb +31 -22
  26. data/lib/mocha/parameter_matchers/optionally.rb +43 -33
  27. data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +6 -1
  28. data/lib/mocha/parameter_matchers/regexp_matches.rb +31 -22
  29. data/lib/mocha/parameter_matchers/responds_with.rb +55 -46
  30. data/lib/mocha/parameter_matchers/yaml_equivalent.rb +30 -21
  31. data/lib/mocha/parameter_matchers.rb +6 -2
  32. data/lib/mocha/parameters_matcher.rb +7 -3
  33. data/lib/mocha/version.rb +1 -1
  34. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36441d2fc56cc4d162b3f1e790c6add3c70eebac844ec6e6b275ef1b6e5f268c
4
- data.tar.gz: b63504e88684874b3609b91096bcd90d18f31639b3d32ba95e36f48e8fc67ecf
3
+ metadata.gz: f100e1c21f105d22752ae4ffc7740ba8fb351559679d3972ae5eea253725e082
4
+ data.tar.gz: 31729a24bdde2da814bbf7d995fb77fc4c08dd7c98775bdb85d6d36fead87a35
5
5
  SHA512:
6
- metadata.gz: 43c0128284d592878e833404f53f95a3c64bfeca18c85f7f94313b475566f98dc0993ed2b41a9d5118c1b4aabbb99e8848510d7aa3b4afa55804d67c0dd25658
7
- data.tar.gz: d9b9785fbf25b80552a7f25e649a5e3ce08ef628c82a1dd36bccf260867156a4ac2c6cf1726e720c6ed8d836a8a1aa0e2441e29e869e65c244ac0c51f93c9423
6
+ metadata.gz: 57b38d4f7b71f41156ea6dd278416864caed11866f1137a5605491000d3603b8793200d6275962b77ed71aaf09707333b88301451b809e9774e3180d594451cf
7
+ data.tar.gz: 672e486d410a534ecf3eae8613294dfeb894c3fc8d324ae4414328e56ccd31ab9ebb46f13105b95cb3c1b0f35e5cd89eb6eeb5dee7493fbefe200dc03b251f0d
data/README.md CHANGED
@@ -8,6 +8,7 @@
8
8
  * Supported by many other test frameworks.
9
9
 
10
10
  ### Intended Usage
11
+
11
12
  Mocha is intended to be used in unit tests for the [Mock Object](http://xunitpatterns.com/Mock%20Object.html) or [Test Stub](http://xunitpatterns.com/Test%20Stub.html) types of [Test Double](http://xunitpatterns.com/Test%20Double.html), not the [Fake Object](http://xunitpatterns.com/Fake%20Object.html) or [Test Spy](http://xunitpatterns.com/Test%20Spy.html) types. Although it would be possible to extend Mocha to allow the implementation of fakes and spies, we have chosen to keep it focused on mocks and stubs.
12
13
 
13
14
  ### Installation
data/RELEASE.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # Release Notes
2
2
 
3
+ ## 2.8.0
4
+
5
+ Many thanks to @etiennebarrie for his help in testing v3.0.0 release candidates which led to many of these changes.
6
+
7
+ ### External changes
8
+
9
+ * Extract `ParameterMatchers::BaseMethods` module and deprecate inheriting from `ParameterMatchers::Base` class (0ddfbe4b)
10
+ * Move matcher builder methods into `ParameterMatchers::Methods` module and only include that module into `API` (2de41423)
11
+ * Provide deprecated access to matcher builder methods when including `ParameterMatchers` module (299488e1)
12
+ * Provide deprecated access to matcher classes, e.g. `ParameterMatchers::Equals`, from within tests/specs (dcced1b4)
13
+
14
+ ### Internal changes
15
+
16
+ * Move `ParameterMatchers#parse_option` -> `HasEntry.parse_option` (9e2a6f66)
17
+
18
+ ## 2.7.1
19
+
20
+ ### External changes
21
+
22
+ * Deprecate `Configuration#stubbing_method_on_nil=` (#694)
23
+ * Indicate when parameter matcher logic is defined by block passed to `Expectation#with` (#698, b30e4434)
24
+ * Improve documentation for `Expectation#with`, especially when it is passed a block (#698, #682, #606 & #681)
25
+
3
26
  ## 2.7.0
4
27
 
5
28
  ### External changes
data/lib/mocha/api.rb CHANGED
@@ -32,7 +32,7 @@ module Mocha
32
32
  # sheep.chew
33
33
  # sheep.foo # => raises NoMethodError exception
34
34
  module API
35
- include ParameterMatchers
35
+ include ParameterMatchers::Methods
36
36
  include Hooks
37
37
 
38
38
  # @private
@@ -1,4 +1,5 @@
1
1
  require 'mocha/ruby_version'
2
+ require 'mocha/deprecation'
2
3
 
3
4
  module Mocha
4
5
  # Allows setting of configuration options. See {Configuration} for the available options.
@@ -206,8 +207,14 @@ module Mocha
206
207
  # When +value+ is +:prevent+, raise a {StubbingError}. This is the default.
207
208
  #
208
209
  # @param [Symbol] value one of +:allow+, +:warn+, +:prevent+.
210
+ # @deprecated This method is deprecated and will be removed in a future release. +nil+ is frozen in Ruby >= v2.2 and Mocha will be dropping support for Ruby v2.1. At that point it won't be possible to stub methods on +nil+ any more.
209
211
  #
210
212
  def stubbing_method_on_nil=(value)
213
+ Deprecation.warning([
214
+ '`Mocha::Configuration#stubbing_method_on_nil=` is deprecated and will be removed in a future release.',
215
+ '`nil` is frozen in Ruby >= v2.2 and Mocha will be dropping support for Ruby v2.1.',
216
+ "At that point it won't be possible to stub methods on `nil` any more."
217
+ ].join(' '))
211
218
  @options[:stubbing_method_on_nil] = value
212
219
  end
213
220
 
@@ -256,7 +263,7 @@ module Mocha
256
263
  #
257
264
  # For more details on keyword arguments in Ruby v3, refer to {https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0 this article}.
258
265
  #
259
- # Note that +Hash+-related matchers such as {ParameterMatchers#has_value} or {ParameterMatchers#has_key} will still treat a positional +Hash+ and a set of keyword arguments the same, so misleading passing tests are still possible when they are used.
266
+ # Note that +Hash+-related matchers such as {ParameterMatchers::Methods#has_value} or {ParameterMatchers::Methods#has_key} will still treat a positional +Hash+ and a set of keyword arguments the same, so misleading passing tests are still possible when they are used.
260
267
  #
261
268
  # This configuration option is +false+ by default to enable gradual adoption, but will be +true+ by default in the future.
262
269
  #
@@ -191,7 +191,12 @@ module Mocha
191
191
 
192
192
  # Modifies expectation so that the expected method must be called with +expected_parameters_or_matchers+.
193
193
  #
194
- # May be used with Ruby literals or variables for exact matching or with parameter matchers for less-specific matching, e.g. {ParameterMatchers#includes}, {ParameterMatchers#has_key}, etc. See {ParameterMatchers} for a list of all available parameter matchers.
194
+ # May be used with Ruby literals or variables for exact matching or with parameter matchers for less-specific matching, e.g. {ParameterMatchers::Methods#includes}, {ParameterMatchers::Methods#has_key}, etc. See {ParameterMatchers} for a list of all available parameter matchers.
195
+ #
196
+ # Alternatively a block argument can be passed to {#with} to implement custom parameter matching. The block receives the +*actual_parameters+ as its arguments and should return +true+ if they are acceptable or +false+ otherwise. See the example below where a method is expected to be called with a value divisible by 4.
197
+ # The block argument takes precedence over +expected_parameters_or_matchers+. The block may be called multiple times per invocation of the expected method and so it should be idempotent.
198
+ #
199
+ # Note that if {#with} is called multiple times on the same expectation, the last call takes precedence; other calls are ignored.
195
200
  #
196
201
  # Positional arguments were separated from keyword arguments in Ruby v3 (see {https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0 this article}). In relation to this a new configuration option ({Configuration#strict_keyword_argument_matching=}) is available in Ruby >= 2.7.
197
202
  #
@@ -202,10 +207,10 @@ module Mocha
202
207
  # @see ParameterMatchers
203
208
  # @see Configuration#strict_keyword_argument_matching=
204
209
  #
205
- # @param [*Array<Object,ParameterMatchers::Base>] expected_parameters_or_matchers expected parameter values or parameter matchers.
210
+ # @param [Array<Object,ParameterMatchers::BaseMethods>] expected_parameters_or_matchers expected parameter values or parameter matchers.
206
211
  # @yield optional block specifying custom matching.
207
- # @yieldparam [*Array<Object>] actual_parameters parameters with which expected method was invoked.
208
- # @yieldreturn [Boolean] +true+ if +actual_parameters+ are acceptable.
212
+ # @yieldparam [Array<Object>] actual_parameters parameters with which expected method was invoked.
213
+ # @yieldreturn [Boolean] +true+ if +actual_parameters+ are acceptable; +false+ otherwise.
209
214
  # @return [Expectation] the same expectation, thereby allowing invocations of other {Expectation} methods to be chained.
210
215
  #
211
216
  # @example Expected method must be called with exact parameter values.
@@ -256,7 +261,7 @@ module Mocha
256
261
  # example.foo('a', { bar: 'b' })
257
262
  # # This now fails as expected
258
263
  #
259
- # @example Expected method must be called with a value divisible by 4.
264
+ # @example Using a block argument to expect the method to be called with a value divisible by 4.
260
265
  # object = mock()
261
266
  # object.expects(:expected_method).with() { |value| value % 4 == 0 }
262
267
  # object.expected_method(16)
@@ -266,6 +271,22 @@ module Mocha
266
271
  # object.expects(:expected_method).with() { |value| value % 4 == 0 }
267
272
  # object.expected_method(17)
268
273
  # # => verify fails
274
+ #
275
+ # @example Extracting a custom matcher into an instance method on the test class.
276
+ # class MyTest < Minitest::Test
277
+ # def test_expected_method_is_called_with_a_value_divisible_by_4
278
+ # object = mock()
279
+ # object.expects(:expected_method).with(&method(:divisible_by_4))
280
+ # object.expected_method(16)
281
+ # # => verify succeeds
282
+ # end
283
+ #
284
+ # private
285
+ #
286
+ # def divisible_by_4(value)
287
+ # value % 4 == 0
288
+ # end
289
+ # end
269
290
  def with(*expected_parameters_or_matchers, &matching_block)
270
291
  @parameters_matcher = ParametersMatcher.new(expected_parameters_or_matchers, self, &matching_block)
271
292
  self
@@ -1,31 +1,38 @@
1
1
  require 'mocha/parameter_matchers/base'
2
+ require 'mocha/parameter_matchers/deprecations'
2
3
 
3
4
  module Mocha
4
5
  module ParameterMatchers
5
- # Matches if all +matchers+ match.
6
- #
7
- # @param [*Array<Base>] matchers parameter matchers.
8
- # @return [AllOf] parameter matcher.
9
- #
10
- # @see Expectation#with
11
- #
12
- # @example All parameter matchers match.
13
- # object = mock()
14
- # object.expects(:method_1).with(all_of(includes(1), includes(3)))
15
- # object.method_1([1, 3])
16
- # # no error raised
17
- #
18
- # @example One of the parameter matchers does not match.
19
- # object = mock()
20
- # object.expects(:method_1).with(all_of(includes(1), includes(3)))
21
- # object.method_1([1, 2])
22
- # # error raised, because method_1 was not called with object including 1 and 3
23
- def all_of(*matchers)
24
- AllOf.new(*matchers)
6
+ module Methods
7
+ # Matches if all +matchers+ match.
8
+ #
9
+ # @param [*Array<BaseMethods>] matchers parameter matchers.
10
+ # @return [AllOf] parameter matcher.
11
+ #
12
+ # @see Expectation#with
13
+ #
14
+ # @example All parameter matchers match.
15
+ # object = mock()
16
+ # object.expects(:method_1).with(all_of(includes(1), includes(3)))
17
+ # object.method_1([1, 3])
18
+ # # no error raised
19
+ #
20
+ # @example One of the parameter matchers does not match.
21
+ # object = mock()
22
+ # object.expects(:method_1).with(all_of(includes(1), includes(3)))
23
+ # object.method_1([1, 2])
24
+ # # error raised, because method_1 was not called with object including 1 and 3
25
+ def all_of(*matchers)
26
+ AllOf.new(*matchers)
27
+ end
25
28
  end
26
29
 
30
+ define_deprecated_matcher_method(:all_of)
31
+
27
32
  # Parameter matcher which combines a number of other matchers using a logical AND.
28
- class AllOf < Base
33
+ class AllOf
34
+ include BaseMethods
35
+
29
36
  # @private
30
37
  def initialize(*matchers)
31
38
  @matchers = matchers
@@ -42,5 +49,7 @@ module Mocha
42
49
  "all_of(#{@matchers.map(&:mocha_inspect).join(', ')})"
43
50
  end
44
51
  end
52
+
53
+ provide_deprecated_access_to(:AllOf)
45
54
  end
46
55
  end
@@ -1,37 +1,44 @@
1
1
  require 'mocha/parameter_matchers/base'
2
+ require 'mocha/parameter_matchers/deprecations'
2
3
 
3
4
  module Mocha
4
5
  module ParameterMatchers
5
- # Matches if any +matchers+ match.
6
- #
7
- # @param [*Array<Base>] matchers parameter matchers.
8
- # @return [AnyOf] parameter matcher.
9
- #
10
- # @see Expectation#with
11
- #
12
- # @example One parameter matcher matches.
13
- # object = mock()
14
- # object.expects(:method_1).with(any_of(1, 3))
15
- # object.method_1(1)
16
- # # no error raised
17
- #
18
- # @example The other parameter matcher matches.
19
- # object = mock()
20
- # object.expects(:method_1).with(any_of(1, 3))
21
- # object.method_1(3)
22
- # # no error raised
23
- #
24
- # @example Neither parameter matcher matches.
25
- # object = mock()
26
- # object.expects(:method_1).with(any_of(1, 3))
27
- # object.method_1(2)
28
- # # error raised, because method_1 was not called with 1 or 3
29
- def any_of(*matchers)
30
- AnyOf.new(*matchers)
6
+ module Methods
7
+ # Matches if any +matchers+ match.
8
+ #
9
+ # @param [*Array<BaseMethods>] matchers parameter matchers.
10
+ # @return [AnyOf] parameter matcher.
11
+ #
12
+ # @see Expectation#with
13
+ #
14
+ # @example One parameter matcher matches.
15
+ # object = mock()
16
+ # object.expects(:method_1).with(any_of(1, 3))
17
+ # object.method_1(1)
18
+ # # no error raised
19
+ #
20
+ # @example The other parameter matcher matches.
21
+ # object = mock()
22
+ # object.expects(:method_1).with(any_of(1, 3))
23
+ # object.method_1(3)
24
+ # # no error raised
25
+ #
26
+ # @example Neither parameter matcher matches.
27
+ # object = mock()
28
+ # object.expects(:method_1).with(any_of(1, 3))
29
+ # object.method_1(2)
30
+ # # error raised, because method_1 was not called with 1 or 3
31
+ def any_of(*matchers)
32
+ AnyOf.new(*matchers)
33
+ end
31
34
  end
32
35
 
36
+ define_deprecated_matcher_method(:any_of)
37
+
33
38
  # Parameter matcher which combines a number of other matchers using a logical OR.
34
- class AnyOf < Base
39
+ class AnyOf
40
+ include BaseMethods
41
+
35
42
  # @private
36
43
  def initialize(*matchers)
37
44
  @matchers = matchers
@@ -48,5 +55,7 @@ module Mocha
48
55
  "any_of(#{@matchers.map(&:mocha_inspect).join(', ')})"
49
56
  end
50
57
  end
58
+
59
+ provide_deprecated_access_to(:AnyOf)
51
60
  end
52
61
  end
@@ -1,29 +1,36 @@
1
1
  require 'mocha/parameter_matchers/base'
2
+ require 'mocha/parameter_matchers/deprecations'
2
3
 
3
4
  module Mocha
4
5
  module ParameterMatchers
5
- # Matches any parameters. This is used as the default for a newly built expectation.
6
- #
7
- # @return [AnyParameters] parameter matcher.
8
- #
9
- # @see Expectation#with
10
- #
11
- # @example Any parameters will match.
12
- # object = mock()
13
- # object.expects(:method_1).with(any_parameters)
14
- # object.method_1(1, 2, 3, 4)
15
- # # no error raised
16
- #
17
- # object = mock()
18
- # object.expects(:method_1).with(any_parameters)
19
- # object.method_1(5, 6, 7, 8, 9, 0)
20
- # # no error raised
21
- def any_parameters
22
- AnyParameters.new
6
+ module Methods
7
+ # Matches any parameters. This is used as the default for a newly built expectation.
8
+ #
9
+ # @return [AnyParameters] parameter matcher.
10
+ #
11
+ # @see Expectation#with
12
+ #
13
+ # @example Any parameters will match.
14
+ # object = mock()
15
+ # object.expects(:method_1).with(any_parameters)
16
+ # object.method_1(1, 2, 3, 4)
17
+ # # no error raised
18
+ #
19
+ # object = mock()
20
+ # object.expects(:method_1).with(any_parameters)
21
+ # object.method_1(5, 6, 7, 8, 9, 0)
22
+ # # no error raised
23
+ def any_parameters
24
+ AnyParameters.new
25
+ end
23
26
  end
24
27
 
28
+ define_deprecated_matcher_method(:any_parameters)
29
+
25
30
  # Parameter matcher which always matches whatever the parameters.
26
- class AnyParameters < Base
31
+ class AnyParameters
32
+ include BaseMethods
33
+
27
34
  # @private
28
35
  def matches?(available_parameters)
29
36
  until available_parameters.empty?
@@ -37,5 +44,7 @@ module Mocha
37
44
  'any_parameters'
38
45
  end
39
46
  end
47
+
48
+ provide_deprecated_access_to(:AnyParameters)
40
49
  end
41
50
  end
@@ -1,26 +1,33 @@
1
1
  require 'mocha/parameter_matchers/base'
2
+ require 'mocha/parameter_matchers/deprecations'
2
3
 
3
4
  module Mocha
4
5
  module ParameterMatchers
5
- # Matches any object.
6
- #
7
- # @return [Anything] parameter matcher.
8
- #
9
- # @see Expectation#with
10
- #
11
- # @example Any object will match.
12
- # object = mock()
13
- # object.expects(:method_1).with(anything)
14
- # object.method_1('foo')
15
- # object.method_1(789)
16
- # object.method_1(:bar)
17
- # # no error raised
18
- def anything
19
- Anything.new
6
+ module Methods
7
+ # Matches any object.
8
+ #
9
+ # @return [Anything] parameter matcher.
10
+ #
11
+ # @see Expectation#with
12
+ #
13
+ # @example Any object will match.
14
+ # object = mock()
15
+ # object.expects(:method_1).with(anything)
16
+ # object.method_1('foo')
17
+ # object.method_1(789)
18
+ # object.method_1(:bar)
19
+ # # no error raised
20
+ def anything
21
+ Anything.new
22
+ end
20
23
  end
21
24
 
25
+ define_deprecated_matcher_method(:anything)
26
+
22
27
  # Parameter matcher which always matches a single parameter.
23
- class Anything < Base
28
+ class Anything
29
+ include BaseMethods
30
+
24
31
  # @private
25
32
  def matches?(available_parameters)
26
33
  available_parameters.shift
@@ -32,5 +39,7 @@ module Mocha
32
39
  'anything'
33
40
  end
34
41
  end
42
+
43
+ provide_deprecated_access_to(:Anything)
35
44
  end
36
45
  end
@@ -1,14 +1,17 @@
1
+ require 'mocha/deprecation'
2
+ require 'mocha/parameter_matchers/deprecations'
3
+
1
4
  module Mocha
2
5
  module ParameterMatchers
3
- # @abstract Subclass and implement +#matches?+ and +#mocha_inspect+ to define a custom matcher. Also add a suitably named instance method to {ParameterMatchers} to build an instance of the new matcher c.f. {#equals}.
4
- class Base
6
+ # @abstract Include and implement +#matches?+ and +#mocha_inspect+ to define a custom matcher. Also add a suitably named instance method to {Methods} to build an instance of the new matcher c.f. {Methods#equals}.
7
+ module BaseMethods
5
8
  # A shorthand way of combining two matchers when both must match.
6
9
  #
7
10
  # Returns a new {AllOf} parameter matcher combining two matchers using a logical AND.
8
11
  #
9
12
  # This shorthand will not work with an implicit equals match. Instead, an explicit {Equals} matcher should be used.
10
13
  #
11
- # @param [Base] other parameter matcher.
14
+ # @param [BaseMethods] other parameter matcher.
12
15
  # @return [AllOf] parameter matcher.
13
16
  #
14
17
  # @see Expectation#with
@@ -32,7 +35,7 @@ module Mocha
32
35
  #
33
36
  # This shorthand will not work with an implicit equals match. Instead, an explicit {Equals} matcher should be used.
34
37
  #
35
- # @param [Base] other parameter matcher.
38
+ # @param [BaseMethods] other parameter matcher.
36
39
  # @return [AnyOf] parameter matcher.
37
40
  #
38
41
  # @see Expectation#with
@@ -56,5 +59,20 @@ module Mocha
56
59
  AnyOf.new(self, other)
57
60
  end
58
61
  end
62
+
63
+ # @deprecated Include +BaseMethods+ module instead.
64
+ class Base
65
+ include BaseMethods
66
+
67
+ # @private
68
+ def self.inherited(subclass)
69
+ super
70
+ Deprecation.warning(
71
+ "Include #{BaseMethods} module into #{subclass} instead of inheriting from #{self}."
72
+ )
73
+ end
74
+ end
75
+
76
+ provide_deprecated_access_to(:Base)
59
77
  end
60
78
  end
@@ -0,0 +1,46 @@
1
+ require 'mocha/deprecation'
2
+ require 'set'
3
+
4
+ module Mocha
5
+ module ParameterMatchers
6
+ module Methods
7
+ # @private
8
+ def self.included(base)
9
+ base.define_singleton_method(:const_missing) do |name|
10
+ if ParameterMatchers.access_deprecated?(name)
11
+ Mocha::ParameterMatchers.const_get(name).tap do |mod|
12
+ Deprecation.warning(
13
+ "Referencing #{name} outside its namespace is deprecated. Use fully-qualified #{mod} instead."
14
+ )
15
+ end
16
+ else
17
+ super(name)
18
+ end
19
+ end
20
+ end
21
+ end
22
+
23
+ # @private
24
+ @classes_with_access_deprecated = Set.new
25
+
26
+ # @private
27
+ def self.provide_deprecated_access_to(name)
28
+ @classes_with_access_deprecated.add(name)
29
+ end
30
+
31
+ # @private
32
+ def self.access_deprecated?(name)
33
+ @classes_with_access_deprecated.include?(name)
34
+ end
35
+
36
+ # @private
37
+ def self.define_deprecated_matcher_method(name)
38
+ define_method(name) do |*args|
39
+ Deprecation.warning(
40
+ "Calling #{ParameterMatchers}##{name} is deprecated. Use #{Methods}##{name} instead."
41
+ )
42
+ Methods.instance_method(name).bind(self).call(*args)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,32 +1,39 @@
1
1
  require 'mocha/parameter_matchers/base'
2
+ require 'mocha/parameter_matchers/deprecations'
2
3
 
3
4
  module Mocha
4
5
  module ParameterMatchers
5
- # Matches any +Object+ equalling +value+.
6
- #
7
- # @param [Object] value expected value.
8
- # @return [Equals] parameter matcher.
9
- #
10
- # @see Expectation#with
11
- # @see Object#==
12
- #
13
- # @example Actual parameter equals expected parameter.
14
- # object = mock()
15
- # object.expects(:method_1).with(equals(2))
16
- # object.method_1(2)
17
- # # no error raised
18
- #
19
- # @example Actual parameter does not equal expected parameter.
20
- # object = mock()
21
- # object.expects(:method_1).with(equals(2))
22
- # object.method_1(3)
23
- # # error raised, because method_1 was not called with an +Object+ that equals 2
24
- def equals(value)
25
- Equals.new(value)
6
+ module Methods
7
+ # Matches any +Object+ equalling +value+.
8
+ #
9
+ # @param [Object] value expected value.
10
+ # @return [Equals] parameter matcher.
11
+ #
12
+ # @see Expectation#with
13
+ # @see Object#==
14
+ #
15
+ # @example Actual parameter equals expected parameter.
16
+ # object = mock()
17
+ # object.expects(:method_1).with(equals(2))
18
+ # object.method_1(2)
19
+ # # no error raised
20
+ #
21
+ # @example Actual parameter does not equal expected parameter.
22
+ # object = mock()
23
+ # object.expects(:method_1).with(equals(2))
24
+ # object.method_1(3)
25
+ # # error raised, because method_1 was not called with an +Object+ that equals 2
26
+ def equals(value)
27
+ Equals.new(value)
28
+ end
26
29
  end
27
30
 
31
+ define_deprecated_matcher_method(:equals)
32
+
28
33
  # Parameter matcher which matches when actual parameter equals expected value.
29
- class Equals < Base
34
+ class Equals
35
+ include BaseMethods
36
+
30
37
  # @private
31
38
  def initialize(value)
32
39
  @value = value
@@ -43,5 +50,7 @@ module Mocha
43
50
  @value.mocha_inspect
44
51
  end
45
52
  end
53
+
54
+ provide_deprecated_access_to(:Equals)
46
55
  end
47
56
  end