mocha 2.7.1 → 2.8.1

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 (33) hide show
  1. checksums.yaml +4 -4
  2. data/RELEASE.md +26 -0
  3. data/lib/mocha/api.rb +1 -1
  4. data/lib/mocha/configuration.rb +1 -1
  5. data/lib/mocha/expectation.rb +2 -2
  6. data/lib/mocha/integration/minitest/adapter.rb +3 -1
  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 +24 -4
  12. data/lib/mocha/parameter_matchers/deprecations.rb +44 -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/version.rb +1 -1
  33. metadata +4 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 61f3a7bc2e73c16b715a31472883ed85fc55726d28e43d051b5d62da21362b52
4
- data.tar.gz: 8e2b6b411543932dfb02f9d97cbe0eb35ed48e983e9079a426c7963f075416da
3
+ metadata.gz: c403814a1f0f6fd604e2978ecbbd18341c543f9e894ce9da078e3ed277e5a92c
4
+ data.tar.gz: 55313439e576d54b112d313a8ce3e3ccca809e8716c0bccbeed1f6f87c33aadf
5
5
  SHA512:
6
- metadata.gz: dd352ea7b0ef64b7e56880a90faecd452b67891765a23441013f73405546da1746314025bb4c556b1322ea621a7d28d940efc77272a52b63716993bc27ebe94f
7
- data.tar.gz: e229f55ddd4d53350941bef0af9d3b1026a76f904b666d187ebd6d808feb284101677c66e47005ea3889767626e1cd556330e222d80752f57be89665d4fafd3a
6
+ metadata.gz: 7383b0e2494d3cb257f21094204437fd86b2dfb55090642b036f0ed86facb0e8f6800933c8ebacc3b45145f4975d2aad0bfe84e772b683c33b5bb6fcfe0f9c03
7
+ data.tar.gz: 2963d0995efa21bff9ac7ee98e7b3ff321223a0a51d2dbc9d6011c490e00071b100e05e30026eebe5b43fae23c602f2da0398ff93b03b357ab349fd4eb7d108e
data/RELEASE.md CHANGED
@@ -1,5 +1,31 @@
1
1
  # Release Notes
2
2
 
3
+ ## 2.8.1
4
+
5
+ ### External changes
6
+
7
+ * Restore unqualified access to `ParameterMatchers` matcher classes, but deprecate such access (5231a4f7)
8
+ * Restore unqualified access to `ParameterMatchers::BaseMethods`, but deprecate such access (8a898567)
9
+
10
+ ## 2.8.0
11
+
12
+ Many thanks to @etiennebarrie for his help in testing v3.0.0 release candidates which led to many of these changes.
13
+
14
+ ### External changes
15
+
16
+ * Extract `ParameterMatchers::BaseMethods` module and deprecate inheriting from `ParameterMatchers::Base` class (0ddfbe4b)
17
+ * Move matcher builder methods into `ParameterMatchers::Methods` module and only include that module into `API` (2de41423)
18
+ * Provide deprecated access to matcher builder methods when including `ParameterMatchers` module (299488e1)
19
+ * Provide deprecated access to matcher classes, e.g. `ParameterMatchers::Equals`, from within tests/specs (dcced1b4)
20
+
21
+ ### Internal changes
22
+
23
+ * Move `ParameterMatchers#parse_option` -> `HasEntry.parse_option` (9e2a6f66)
24
+
25
+ **WARNING: This release accidentally removed access to ParameterMatchers classes**
26
+ * Fully-qualified access from within a test/spec class still works, e.g. `Mocha::ParameterMatchers::HasKey`, but unqualified access does not work, e.g. `HasKey`.
27
+ * The mistake has been fixed in v2.8.1 where unqualified access is restored but deprecated. Unqualified access will be removed in v3.
28
+
3
29
  ## 2.7.1
4
30
 
5
31
  ### 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
@@ -263,7 +263,7 @@ module Mocha
263
263
  #
264
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}.
265
265
  #
266
- # 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.
267
267
  #
268
268
  # This configuration option is +false+ by default to enable gradual adoption, but will be +true+ by default in the future.
269
269
  #
@@ -191,7 +191,7 @@ 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
195
  #
196
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
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.
@@ -207,7 +207,7 @@ module Mocha
207
207
  # @see ParameterMatchers
208
208
  # @see Configuration#strict_keyword_argument_matching=
209
209
  #
210
- # @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.
211
211
  # @yield optional block specifying custom matching.
212
212
  # @yieldparam [Array<Object>] actual_parameters parameters with which expected method was invoked.
213
213
  # @yieldreturn [Boolean] +true+ if +actual_parameters+ are acceptable; +false+ otherwise.
@@ -1,6 +1,7 @@
1
1
  require 'mocha/api'
2
2
  require 'mocha/integration/assertion_counter'
3
3
  require 'mocha/expectation_error_factory'
4
+ require 'mocha/parameter_matchers/deprecations'
4
5
 
5
6
  module Mocha
6
7
  module Integration
@@ -22,7 +23,8 @@ module Mocha
22
23
  end
23
24
 
24
25
  # @private
25
- def self.included(_mod)
26
+ def self.included(mod)
27
+ mod.extend(Mocha::ParameterMatchers::Deprecations)
26
28
  Mocha::ExpectationErrorFactory.exception_class = ::Minitest::Assertion
27
29
  end
28
30
 
@@ -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,22 @@ module Mocha
56
59
  AnyOf.new(self, other)
57
60
  end
58
61
  end
62
+
63
+ provide_deprecated_access_to(:BaseMethods)
64
+
65
+ # @deprecated Include +BaseMethods+ module instead.
66
+ class Base
67
+ include BaseMethods
68
+
69
+ # @private
70
+ def self.inherited(subclass)
71
+ super
72
+ Deprecation.warning(
73
+ "Include #{BaseMethods} module into #{subclass} instead of inheriting from #{self}."
74
+ )
75
+ end
76
+ end
77
+
78
+ provide_deprecated_access_to(:Base)
59
79
  end
60
80
  end
@@ -0,0 +1,44 @@
1
+ require 'mocha/deprecation'
2
+ require 'set'
3
+
4
+ module Mocha
5
+ module ParameterMatchers
6
+ module Deprecations
7
+ # @private
8
+ def const_missing(name)
9
+ if ParameterMatchers.access_deprecated?(name)
10
+ ParameterMatchers.const_get(name).tap do |mod|
11
+ Deprecation.warning(
12
+ "Referencing #{name} outside its namespace is deprecated. Use fully-qualified #{mod} instead."
13
+ )
14
+ end
15
+ else
16
+ super(name)
17
+ end
18
+ end
19
+ end
20
+
21
+ # @private
22
+ @classes_with_access_deprecated = Set.new
23
+
24
+ # @private
25
+ def self.provide_deprecated_access_to(name)
26
+ @classes_with_access_deprecated.add(name)
27
+ end
28
+
29
+ # @private
30
+ def self.access_deprecated?(name)
31
+ @classes_with_access_deprecated.include?(name)
32
+ end
33
+
34
+ # @private
35
+ def self.define_deprecated_matcher_method(name)
36
+ define_method(name) do |*args|
37
+ Deprecation.warning(
38
+ "Calling #{ParameterMatchers}##{name} is deprecated. Use #{Methods}##{name} instead."
39
+ )
40
+ Methods.instance_method(name).bind(self).call(*args)
41
+ end
42
+ end
43
+ end
44
+ 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
@@ -1,33 +1,40 @@
1
1
  require 'mocha/parameter_matchers/base'
2
+ require 'mocha/parameter_matchers/deprecations'
2
3
  require 'uri'
3
4
  require 'cgi'
4
5
 
5
6
  module Mocha
6
7
  module ParameterMatchers
7
- # Matches a URI without regard to the ordering of parameters in the query string.
8
- #
9
- # @param [String] uri URI to match.
10
- # @return [EquivalentUri] parameter matcher.
11
- #
12
- # @see Expectation#with
13
- #
14
- # @example Actual URI is equivalent.
15
- # object = mock()
16
- # object.expects(:method_1).with(equivalent_uri('http://example.com/foo?a=1&b=2))
17
- # object.method_1('http://example.com/foo?b=2&a=1')
18
- # # no error raised
19
- #
20
- # @example Actual URI is not equivalent.
21
- # object = mock()
22
- # object.expects(:method_1).with(equivalent_uri('http://example.com/foo?a=1&b=2))
23
- # object.method_1('http://example.com/foo?a=1&b=3')
24
- # # error raised, because the query parameters were different
25
- def equivalent_uri(uri)
26
- EquivalentUri.new(uri)
8
+ module Methods
9
+ # Matches a URI without regard to the ordering of parameters in the query string.
10
+ #
11
+ # @param [String] uri URI to match.
12
+ # @return [EquivalentUri] parameter matcher.
13
+ #
14
+ # @see Expectation#with
15
+ #
16
+ # @example Actual URI is equivalent.
17
+ # object = mock()
18
+ # object.expects(:method_1).with(equivalent_uri('http://example.com/foo?a=1&b=2))
19
+ # object.method_1('http://example.com/foo?b=2&a=1')
20
+ # # no error raised
21
+ #
22
+ # @example Actual URI is not equivalent.
23
+ # object = mock()
24
+ # object.expects(:method_1).with(equivalent_uri('http://example.com/foo?a=1&b=2))
25
+ # object.method_1('http://example.com/foo?a=1&b=3')
26
+ # # error raised, because the query parameters were different
27
+ def equivalent_uri(uri)
28
+ EquivalentUri.new(uri)
29
+ end
27
30
  end
28
31
 
32
+ define_deprecated_matcher_method(:equivalent_uri)
33
+
29
34
  # Parameter matcher which matches URIs with equivalent query strings.
30
- class EquivalentUri < Base
35
+ class EquivalentUri
36
+ include BaseMethods
37
+
31
38
  # @private
32
39
  def initialize(uri)
33
40
  @uri = URI.parse(uri)
@@ -53,5 +60,7 @@ module Mocha
53
60
  URI::Generic::COMPONENT.inject({}) { |h, k| h.merge(k => uri.__send__(k)) }.merge(query: query_hash)
54
61
  end
55
62
  end
63
+
64
+ provide_deprecated_access_to(:EquivalentUri)
56
65
  end
57
66
  end