mocha 2.8.0 → 3.0.0.pre.rc.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 (102) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +67 -3
  3. data/.rubocop_todo.yml +25 -13
  4. data/Gemfile +11 -27
  5. data/README.md +3 -4
  6. data/RELEASE.md +30 -8
  7. data/Rakefile +6 -5
  8. data/gemfiles/Gemfile.minitest.latest +3 -3
  9. data/gemfiles/Gemfile.rubocop +9 -0
  10. data/gemfiles/Gemfile.test-unit.latest +3 -3
  11. data/lib/mocha/any_instance_method.rb +2 -0
  12. data/lib/mocha/any_instance_receiver.rb +20 -0
  13. data/lib/mocha/api.rb +5 -3
  14. data/lib/mocha/argument_iterator.rb +5 -5
  15. data/lib/mocha/backtrace_filter.rb +2 -0
  16. data/lib/mocha/{block_matcher.rb → block_matchers.rb} +2 -0
  17. data/lib/mocha/cardinality.rb +2 -2
  18. data/lib/mocha/central.rb +4 -0
  19. data/lib/mocha/change_state_side_effect.rb +2 -0
  20. data/lib/mocha/class_methods.rb +5 -4
  21. data/lib/mocha/configuration.rb +19 -42
  22. data/lib/mocha/default_name.rb +15 -0
  23. data/lib/mocha/default_receiver.rb +13 -0
  24. data/lib/mocha/deprecation.rb +15 -9
  25. data/lib/mocha/detection/minitest.rb +2 -0
  26. data/lib/mocha/detection/test_unit.rb +4 -1
  27. data/lib/mocha/error_with_filtered_backtrace.rb +2 -0
  28. data/lib/mocha/exception_raiser.rb +3 -0
  29. data/lib/mocha/expectation.rb +59 -25
  30. data/lib/mocha/expectation_error.rb +2 -0
  31. data/lib/mocha/expectation_error_factory.rb +2 -0
  32. data/lib/mocha/expectation_list.rb +2 -0
  33. data/lib/mocha/hooks.rb +2 -0
  34. data/lib/mocha/impersonating_any_instance_name.rb +13 -0
  35. data/lib/mocha/impersonating_name.rb +13 -0
  36. data/lib/mocha/in_state_ordering_constraint.rb +2 -0
  37. data/lib/mocha/inspect.rb +13 -10
  38. data/lib/mocha/instance_method.rb +2 -0
  39. data/lib/mocha/integration/assertion_counter.rb +2 -0
  40. data/lib/mocha/integration/minitest/adapter.rb +3 -0
  41. data/lib/mocha/integration/minitest.rb +4 -3
  42. data/lib/mocha/integration/monkey_patcher.rb +4 -2
  43. data/lib/mocha/integration/test_unit/adapter.rb +3 -0
  44. data/lib/mocha/integration/test_unit.rb +4 -3
  45. data/lib/mocha/invocation.rb +9 -6
  46. data/lib/mocha/logger.rb +2 -0
  47. data/lib/mocha/macos_version.rb +2 -0
  48. data/lib/mocha/method_matcher.rb +2 -0
  49. data/lib/mocha/minitest.rb +2 -1
  50. data/lib/mocha/mock.rb +8 -8
  51. data/lib/mocha/mockery.rb +16 -6
  52. data/lib/mocha/name.rb +13 -0
  53. data/lib/mocha/not_initialized_error.rb +2 -0
  54. data/lib/mocha/object_methods.rb +7 -5
  55. data/lib/mocha/object_receiver.rb +20 -0
  56. data/lib/mocha/parameter_matchers/all_of.rb +23 -28
  57. data/lib/mocha/parameter_matchers/any_of.rb +29 -34
  58. data/lib/mocha/parameter_matchers/any_parameters.rb +21 -26
  59. data/lib/mocha/parameter_matchers/anything.rb +18 -23
  60. data/lib/mocha/parameter_matchers/base.rb +5 -21
  61. data/lib/mocha/parameter_matchers/equals.rb +24 -29
  62. data/lib/mocha/parameter_matchers/equivalent_uri.rb +23 -28
  63. data/lib/mocha/parameter_matchers/has_entries.rb +24 -29
  64. data/lib/mocha/parameter_matchers/has_entry.rb +68 -70
  65. data/lib/mocha/parameter_matchers/has_key.rb +25 -29
  66. data/lib/mocha/parameter_matchers/has_keys.rb +25 -30
  67. data/lib/mocha/parameter_matchers/has_value.rb +25 -29
  68. data/lib/mocha/parameter_matchers/includes.rb +65 -73
  69. data/lib/mocha/parameter_matchers/instance_methods.rb +5 -3
  70. data/lib/mocha/parameter_matchers/instance_of.rb +24 -29
  71. data/lib/mocha/parameter_matchers/is_a.rb +25 -30
  72. data/lib/mocha/parameter_matchers/kind_of.rb +24 -29
  73. data/lib/mocha/parameter_matchers/not.rb +24 -29
  74. data/lib/mocha/parameter_matchers/optionally.rb +35 -40
  75. data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +39 -19
  76. data/lib/mocha/parameter_matchers/regexp_matches.rb +25 -29
  77. data/lib/mocha/parameter_matchers/responds_with.rb +48 -53
  78. data/lib/mocha/parameter_matchers/yaml_equivalent.rb +23 -28
  79. data/lib/mocha/parameter_matchers.rb +4 -6
  80. data/lib/mocha/parameters_matcher.rb +9 -1
  81. data/lib/mocha/raised_exception.rb +2 -0
  82. data/lib/mocha/return_values.rb +2 -0
  83. data/lib/mocha/ruby_version.rb +3 -0
  84. data/lib/mocha/sequence.rb +2 -0
  85. data/lib/mocha/single_return_value.rb +1 -1
  86. data/lib/mocha/state_machine.rb +2 -0
  87. data/lib/mocha/stubbed_method.rb +9 -2
  88. data/lib/mocha/stubbing_error.rb +2 -0
  89. data/lib/mocha/test_unit.rb +2 -1
  90. data/lib/mocha/thrower.rb +2 -0
  91. data/lib/mocha/thrown_object.rb +2 -0
  92. data/lib/mocha/version.rb +3 -1
  93. data/lib/mocha/yield_parameters.rb +2 -0
  94. data/lib/mocha.rb +5 -0
  95. data/mocha.gemspec +10 -4
  96. metadata +17 -16
  97. data/lib/mocha/debug.rb +0 -9
  98. data/lib/mocha/integration/minitest/exception_translation.rb +0 -14
  99. data/lib/mocha/is_a.rb +0 -7
  100. data/lib/mocha/names.rb +0 -43
  101. data/lib/mocha/parameter_matchers/deprecations.rb +0 -46
  102. data/lib/mocha/receivers.rb +0 -45
data/lib/mocha/mockery.rb CHANGED
@@ -1,7 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/central'
2
4
  require 'mocha/mock'
3
- require 'mocha/names'
4
- require 'mocha/receivers'
5
+ require 'mocha/name'
6
+ require 'mocha/impersonating_name'
7
+ require 'mocha/impersonating_any_instance_name'
8
+ require 'mocha/object_receiver'
9
+ require 'mocha/any_instance_receiver'
5
10
  require 'mocha/state_machine'
6
11
  require 'mocha/logger'
7
12
  require 'mocha/configuration'
@@ -49,9 +54,13 @@ module Mocha
49
54
  end
50
55
 
51
56
  def teardown(origin = nil)
57
+ if @instances.nil?
58
+ raise NotInitializedError, 'Mocha::Mockery.teardown called before Mocha::Mockery.setup'
59
+ end
60
+
52
61
  instance.teardown(origin)
53
62
  ensure
54
- @instances.pop
63
+ @instances.pop unless @instances.nil?
55
64
  end
56
65
  end
57
66
 
@@ -124,12 +133,11 @@ module Mocha
124
133
  def on_stubbing(object, method)
125
134
  signature_proc = lambda { "#{object.mocha_inspect}.#{method}" }
126
135
  check(:stubbing_non_existent_method, 'non-existent method', signature_proc) do
127
- !(object.stubba_class.__method_exists__?(method, true) || object.respond_to?(method))
136
+ !(object.stubba_class.__method_exists__?(method) || object.respond_to?(method))
128
137
  end
129
138
  check(:stubbing_non_public_method, 'non-public method', signature_proc) do
130
- object.stubba_class.__method_exists__?(method, false)
139
+ object.stubba_class.__method_exists__?(method, include_public_methods: false)
131
140
  end
132
- check(:stubbing_method_on_nil, 'method on nil', signature_proc) { object.nil? }
133
141
  check(:stubbing_method_on_non_mock_object, 'method on non-mock object', signature_proc)
134
142
  end
135
143
 
@@ -144,9 +152,11 @@ module Mocha
144
152
  def check(action, description, signature_proc, backtrace = caller)
145
153
  treatment = Mocha.configuration.send(action)
146
154
  return if (treatment == :allow) || (block_given? && !yield)
155
+
147
156
  method_signature = signature_proc.call
148
157
  message = "stubbing #{description}: #{method_signature}"
149
158
  raise StubbingError.new(message, backtrace) if treatment == :prevent
159
+
150
160
  logger.warn(message) if treatment == :warn
151
161
  end
152
162
 
data/lib/mocha/name.rb ADDED
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mocha
4
+ class Name
5
+ def initialize(name)
6
+ @name = name.to_s
7
+ end
8
+
9
+ def mocha_inspect
10
+ "#<Mock:#{@name}>"
11
+ end
12
+ end
13
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/error_with_filtered_backtrace'
2
4
 
3
5
  module Mocha
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/mockery'
2
4
  require 'mocha/instance_method'
3
5
  require 'mocha/argument_iterator'
@@ -12,7 +14,7 @@ module Mocha
12
14
  alias_method :_method, :method
13
15
 
14
16
  # @private
15
- def mocha(instantiate = true)
17
+ def mocha(instantiate: true)
16
18
  if instantiate
17
19
  @mocha ||= Mocha::Mockery.instance.mock_impersonating(self)
18
20
  else
@@ -75,11 +77,11 @@ module Mocha
75
77
  if frozen?
76
78
  raise StubbingError.new("can't stub method on frozen object: #{mocha_inspect}", caller)
77
79
  end
80
+
78
81
  expectation = nil
79
82
  mockery = Mocha::Mockery.instance
80
83
  iterator = ArgumentIterator.new(expected_methods_vs_return_values)
81
- iterator.each do |*args|
82
- method_name = args.shift
84
+ iterator.each do |method_name, *args|
83
85
  mockery.on_stubbing(self, method_name)
84
86
  method = stubba_method.new(stubba_object, method_name)
85
87
  mockery.stubba.stub(method)
@@ -121,11 +123,11 @@ module Mocha
121
123
  if frozen?
122
124
  raise StubbingError.new("can't stub method on frozen object: #{mocha_inspect}", caller)
123
125
  end
126
+
124
127
  expectation = nil
125
128
  mockery = Mocha::Mockery.instance
126
129
  iterator = ArgumentIterator.new(stubbed_methods_vs_return_values)
127
- iterator.each do |*args|
128
- method_name = args.shift
130
+ iterator.each do |method_name, *args|
129
131
  mockery.on_stubbing(self, method_name)
130
132
  method = stubba_method.new(stubba_object, method_name)
131
133
  mockery.stubba.stub(method)
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mocha
4
+ class ObjectReceiver
5
+ def initialize(object)
6
+ @object = object
7
+ end
8
+
9
+ def mocks
10
+ object = @object
11
+ mocks = []
12
+ while object
13
+ mocha = object.mocha(instantiate: false)
14
+ mocks << mocha if mocha
15
+ object = object.is_a?(Class) ? object.superclass : nil
16
+ end
17
+ mocks
18
+ end
19
+ end
20
+ end
@@ -1,37 +1,34 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
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
7
+ # Matches if all +matchers+ match.
8
+ #
9
+ # @param [*Array<Base>] 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)
28
27
  end
29
28
 
30
- define_deprecated_matcher_method(:all_of)
31
-
32
29
  # Parameter matcher which combines a number of other matchers using a logical AND.
33
30
  class AllOf
34
- include BaseMethods
31
+ include Base
35
32
 
36
33
  # @private
37
34
  def initialize(*matchers)
@@ -49,7 +46,5 @@ module Mocha
49
46
  "all_of(#{@matchers.map(&:mocha_inspect).join(', ')})"
50
47
  end
51
48
  end
52
-
53
- provide_deprecated_access_to(:AllOf)
54
49
  end
55
50
  end
@@ -1,43 +1,40 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
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
7
+ # Matches if any +matchers+ match.
8
+ #
9
+ # @param [*Array<Base>] 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)
34
33
  end
35
34
 
36
- define_deprecated_matcher_method(:any_of)
37
-
38
35
  # Parameter matcher which combines a number of other matchers using a logical OR.
39
36
  class AnyOf
40
- include BaseMethods
37
+ include Base
41
38
 
42
39
  # @private
43
40
  def initialize(*matchers)
@@ -55,7 +52,5 @@ module Mocha
55
52
  "any_of(#{@matchers.map(&:mocha_inspect).join(', ')})"
56
53
  end
57
54
  end
58
-
59
- provide_deprecated_access_to(:AnyOf)
60
55
  end
61
56
  end
@@ -1,35 +1,32 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
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
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
26
25
  end
27
26
 
28
- define_deprecated_matcher_method(:any_parameters)
29
-
30
27
  # Parameter matcher which always matches whatever the parameters.
31
28
  class AnyParameters
32
- include BaseMethods
29
+ include Base
33
30
 
34
31
  # @private
35
32
  def matches?(available_parameters)
@@ -44,7 +41,5 @@ module Mocha
44
41
  'any_parameters'
45
42
  end
46
43
  end
47
-
48
- provide_deprecated_access_to(:AnyParameters)
49
44
  end
50
45
  end
@@ -1,32 +1,29 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
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
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
23
22
  end
24
23
 
25
- define_deprecated_matcher_method(:anything)
26
-
27
24
  # Parameter matcher which always matches a single parameter.
28
25
  class Anything
29
- include BaseMethods
26
+ include Base
30
27
 
31
28
  # @private
32
29
  def matches?(available_parameters)
@@ -39,7 +36,5 @@ module Mocha
39
36
  'anything'
40
37
  end
41
38
  end
42
-
43
- provide_deprecated_access_to(:Anything)
44
39
  end
45
40
  end
@@ -1,17 +1,16 @@
1
- require 'mocha/deprecation'
2
- require 'mocha/parameter_matchers/deprecations'
1
+ # frozen_string_literal: true
3
2
 
4
3
  module Mocha
5
4
  module ParameterMatchers
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
+ # @abstract Include 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}.
6
+ module Base
8
7
  # A shorthand way of combining two matchers when both must match.
9
8
  #
10
9
  # Returns a new {AllOf} parameter matcher combining two matchers using a logical AND.
11
10
  #
12
11
  # This shorthand will not work with an implicit equals match. Instead, an explicit {Equals} matcher should be used.
13
12
  #
14
- # @param [BaseMethods] other parameter matcher.
13
+ # @param [Base] other parameter matcher.
15
14
  # @return [AllOf] parameter matcher.
16
15
  #
17
16
  # @see Expectation#with
@@ -35,7 +34,7 @@ module Mocha
35
34
  #
36
35
  # This shorthand will not work with an implicit equals match. Instead, an explicit {Equals} matcher should be used.
37
36
  #
38
- # @param [BaseMethods] other parameter matcher.
37
+ # @param [Base] other parameter matcher.
39
38
  # @return [AnyOf] parameter matcher.
40
39
  #
41
40
  # @see Expectation#with
@@ -59,20 +58,5 @@ module Mocha
59
58
  AnyOf.new(self, other)
60
59
  end
61
60
  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)
77
61
  end
78
62
  end
@@ -1,38 +1,35 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
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
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)
29
28
  end
30
29
 
31
- define_deprecated_matcher_method(:equals)
32
-
33
30
  # Parameter matcher which matches when actual parameter equals expected value.
34
31
  class Equals
35
- include BaseMethods
32
+ include Base
36
33
 
37
34
  # @private
38
35
  def initialize(value)
@@ -50,7 +47,5 @@ module Mocha
50
47
  @value.mocha_inspect
51
48
  end
52
49
  end
53
-
54
- provide_deprecated_access_to(:Equals)
55
50
  end
56
51
  end
@@ -1,39 +1,36 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
3
4
  require 'uri'
4
5
  require 'cgi'
5
6
 
6
7
  module Mocha
7
8
  module ParameterMatchers
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
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)
30
29
  end
31
30
 
32
- define_deprecated_matcher_method(:equivalent_uri)
33
-
34
31
  # Parameter matcher which matches URIs with equivalent query strings.
35
32
  class EquivalentUri
36
- include BaseMethods
33
+ include Base
37
34
 
38
35
  # @private
39
36
  def initialize(uri)
@@ -60,7 +57,5 @@ module Mocha
60
57
  URI::Generic::COMPONENT.inject({}) { |h, k| h.merge(k => uri.__send__(k)) }.merge(query: query_hash)
61
58
  end
62
59
  end
63
-
64
- provide_deprecated_access_to(:EquivalentUri)
65
60
  end
66
61
  end