mocha 2.8.0 → 3.0.0.pre.rc.2

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 (105) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +37 -3
  3. data/.rubocop_todo.yml +25 -13
  4. data/.yardopts +2 -0
  5. data/Gemfile +9 -28
  6. data/README.md +3 -4
  7. data/RELEASE.md +64 -0
  8. data/Rakefile +43 -22
  9. data/gemfiles/Gemfile.minitest.latest +3 -3
  10. data/gemfiles/Gemfile.rubocop +9 -0
  11. data/gemfiles/Gemfile.test-unit.latest +3 -3
  12. data/lib/mocha/any_instance_method.rb +6 -4
  13. data/lib/mocha/any_instance_receiver.rb +20 -0
  14. data/lib/mocha/api.rb +4 -2
  15. data/lib/mocha/argument_iterator.rb +5 -5
  16. data/lib/mocha/backtrace_filter.rb +2 -0
  17. data/lib/mocha/{block_matcher.rb → block_matchers.rb} +2 -0
  18. data/lib/mocha/cardinality.rb +2 -2
  19. data/lib/mocha/central.rb +4 -0
  20. data/lib/mocha/change_state_side_effect.rb +2 -0
  21. data/lib/mocha/class_methods.rb +14 -9
  22. data/lib/mocha/configuration.rb +18 -41
  23. data/lib/mocha/default_name.rb +15 -0
  24. data/lib/mocha/default_receiver.rb +13 -0
  25. data/lib/mocha/deprecation.rb +15 -9
  26. data/lib/mocha/detection/minitest.rb +2 -0
  27. data/lib/mocha/detection/test_unit.rb +4 -1
  28. data/lib/mocha/error_with_filtered_backtrace.rb +2 -0
  29. data/lib/mocha/exception_raiser.rb +3 -0
  30. data/lib/mocha/expectation.rb +57 -23
  31. data/lib/mocha/expectation_error.rb +2 -0
  32. data/lib/mocha/expectation_error_factory.rb +2 -0
  33. data/lib/mocha/expectation_list.rb +3 -1
  34. data/lib/mocha/hooks.rb +6 -4
  35. data/lib/mocha/ignoring_warning.rb +20 -0
  36. data/lib/mocha/impersonating_any_instance_name.rb +13 -0
  37. data/lib/mocha/impersonating_name.rb +13 -0
  38. data/lib/mocha/in_state_ordering_constraint.rb +2 -0
  39. data/lib/mocha/inspect.rb +13 -10
  40. data/lib/mocha/instance_method.rb +6 -4
  41. data/lib/mocha/integration/assertion_counter.rb +2 -0
  42. data/lib/mocha/integration/minitest/adapter.rb +7 -3
  43. data/lib/mocha/integration/minitest.rb +5 -4
  44. data/lib/mocha/integration/monkey_patcher.rb +4 -2
  45. data/lib/mocha/integration/test_unit/adapter.rb +10 -4
  46. data/lib/mocha/integration/test_unit.rb +5 -4
  47. data/lib/mocha/integration.rb +5 -0
  48. data/lib/mocha/invocation.rb +9 -6
  49. data/lib/mocha/logger.rb +2 -0
  50. data/lib/mocha/macos_version.rb +2 -0
  51. data/lib/mocha/method_matcher.rb +2 -0
  52. data/lib/mocha/minitest.rb +2 -1
  53. data/lib/mocha/mock.rb +16 -12
  54. data/lib/mocha/mockery.rb +35 -17
  55. data/lib/mocha/name.rb +13 -0
  56. data/lib/mocha/not_initialized_error.rb +2 -0
  57. data/lib/mocha/object_methods.rb +20 -6
  58. data/lib/mocha/object_receiver.rb +20 -0
  59. data/lib/mocha/parameter_matchers/all_of.rb +3 -6
  60. data/lib/mocha/parameter_matchers/any_of.rb +3 -6
  61. data/lib/mocha/parameter_matchers/any_parameters.rb +3 -6
  62. data/lib/mocha/parameter_matchers/anything.rb +3 -6
  63. data/lib/mocha/parameter_matchers/{base.rb → base_methods.rb} +2 -16
  64. data/lib/mocha/parameter_matchers/equals.rb +3 -6
  65. data/lib/mocha/parameter_matchers/equivalent_uri.rb +9 -10
  66. data/lib/mocha/parameter_matchers/has_entries.rb +4 -7
  67. data/lib/mocha/parameter_matchers/has_entry.rb +5 -7
  68. data/lib/mocha/parameter_matchers/has_key.rb +5 -7
  69. data/lib/mocha/parameter_matchers/has_keys.rb +5 -8
  70. data/lib/mocha/parameter_matchers/has_value.rb +5 -7
  71. data/lib/mocha/parameter_matchers/includes.rb +6 -12
  72. data/lib/mocha/parameter_matchers/instance_methods.rb +5 -3
  73. data/lib/mocha/parameter_matchers/instance_of.rb +3 -6
  74. data/lib/mocha/parameter_matchers/is_a.rb +4 -7
  75. data/lib/mocha/parameter_matchers/kind_of.rb +3 -6
  76. data/lib/mocha/parameter_matchers/not.rb +3 -6
  77. data/lib/mocha/parameter_matchers/optionally.rb +2 -5
  78. data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +39 -19
  79. data/lib/mocha/parameter_matchers/regexp_matches.rb +4 -6
  80. data/lib/mocha/parameter_matchers/responds_with.rb +3 -6
  81. data/lib/mocha/parameter_matchers/yaml_equivalent.rb +3 -6
  82. data/lib/mocha/parameter_matchers.rb +2 -1
  83. data/lib/mocha/parameters_matcher.rb +9 -1
  84. data/lib/mocha/raised_exception.rb +2 -0
  85. data/lib/mocha/return_values.rb +2 -0
  86. data/lib/mocha/ruby_version.rb +3 -0
  87. data/lib/mocha/sequence.rb +2 -0
  88. data/lib/mocha/single_return_value.rb +1 -1
  89. data/lib/mocha/state_machine.rb +3 -1
  90. data/lib/mocha/stubbed_method.rb +15 -8
  91. data/lib/mocha/stubbing_error.rb +2 -0
  92. data/lib/mocha/test_unit.rb +2 -1
  93. data/lib/mocha/thrower.rb +2 -0
  94. data/lib/mocha/thrown_object.rb +2 -0
  95. data/lib/mocha/version.rb +3 -1
  96. data/lib/mocha/yield_parameters.rb +2 -0
  97. data/lib/mocha.rb +20 -0
  98. data/mocha.gemspec +10 -4
  99. metadata +18 -12
  100. data/lib/mocha/debug.rb +0 -9
  101. data/lib/mocha/integration/minitest/exception_translation.rb +0 -14
  102. data/lib/mocha/is_a.rb +0 -7
  103. data/lib/mocha/names.rb +0 -43
  104. data/lib/mocha/parameter_matchers/deprecations.rb +0 -46
  105. data/lib/mocha/receivers.rb +0 -45
@@ -1,7 +1,7 @@
1
- require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
3
4
  require 'uri'
4
- require 'cgi'
5
5
 
6
6
  module Mocha
7
7
  module ParameterMatchers
@@ -15,13 +15,13 @@ module Mocha
15
15
  #
16
16
  # @example Actual URI is equivalent.
17
17
  # object = mock()
18
- # object.expects(:method_1).with(equivalent_uri('http://example.com/foo?a=1&b=2))
18
+ # object.expects(:method_1).with(equivalent_uri('http://example.com/foo?a=1&b=2'))
19
19
  # object.method_1('http://example.com/foo?b=2&a=1')
20
20
  # # no error raised
21
21
  #
22
22
  # @example Actual URI is not equivalent.
23
23
  # object = mock()
24
- # object.expects(:method_1).with(equivalent_uri('http://example.com/foo?a=1&b=2))
24
+ # object.expects(:method_1).with(equivalent_uri('http://example.com/foo?a=1&b=2'))
25
25
  # object.method_1('http://example.com/foo?a=1&b=3')
26
26
  # # error raised, because the query parameters were different
27
27
  def equivalent_uri(uri)
@@ -29,8 +29,6 @@ module Mocha
29
29
  end
30
30
  end
31
31
 
32
- define_deprecated_matcher_method(:equivalent_uri)
33
-
34
32
  # Parameter matcher which matches URIs with equivalent query strings.
35
33
  class EquivalentUri
36
34
  include BaseMethods
@@ -56,11 +54,12 @@ module Mocha
56
54
 
57
55
  # @private
58
56
  def explode(uri)
59
- query_hash = CGI.parse(uri.query || '')
57
+ query_hash = Hash.new { |hash, key| hash[key] = [] }
58
+ URI.decode_www_form(uri.query || '').each do |key, value|
59
+ query_hash[key] << value
60
+ end
60
61
  URI::Generic::COMPONENT.inject({}) { |h, k| h.merge(k => uri.__send__(k)) }.merge(query: query_hash)
61
62
  end
62
63
  end
63
-
64
- provide_deprecated_access_to(:EquivalentUri)
65
64
  end
66
65
  end
@@ -1,7 +1,8 @@
1
- require 'mocha/parameter_matchers/base'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
2
4
  require 'mocha/parameter_matchers/all_of'
3
5
  require 'mocha/parameter_matchers/has_entry'
4
- require 'mocha/parameter_matchers/deprecations'
5
6
 
6
7
  module Mocha
7
8
  module ParameterMatchers
@@ -25,13 +26,11 @@ module Mocha
25
26
  # object.method_1('key_1' => 1, 'key_2' => 99)
26
27
  # # error raised, because method_1 was not called with Hash containing entries: 'key_1' => 1, 'key_2' => 2
27
28
  #
28
- def has_entries(entries) # rubocop:disable Naming/PredicateName
29
+ def has_entries(entries) # rubocop:disable Naming/PredicatePrefix
29
30
  HasEntries.new(entries)
30
31
  end
31
32
  end
32
33
 
33
- define_deprecated_matcher_method(:has_entries)
34
-
35
34
  # Parameter matcher which matches when actual parameter contains all expected +Hash+ entries.
36
35
  class HasEntries
37
36
  include BaseMethods
@@ -58,7 +57,5 @@ module Mocha
58
57
  @exact ? @entries.mocha_inspect : "has_entries(#{@entries.mocha_inspect})"
59
58
  end
60
59
  end
61
-
62
- provide_deprecated_access_to(:HasEntries)
63
60
  end
64
61
  end
@@ -1,5 +1,6 @@
1
- require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
@@ -42,7 +43,7 @@ module Mocha
42
43
  # object.method_1('key_1' => 2, 'key_2' => 1)
43
44
  # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1
44
45
  #
45
- def has_entry(*options) # rubocop:disable Naming/PredicateName
46
+ def has_entry(*options) # rubocop:disable Naming/PredicatePrefix
46
47
  case options.length
47
48
  when 0
48
49
  raise ArgumentError, 'No arguments. Expecting at least one.'
@@ -57,8 +58,6 @@ module Mocha
57
58
  end
58
59
  end
59
60
 
60
- define_deprecated_matcher_method(:has_entry)
61
-
62
61
  # Parameter matcher which matches when actual parameter contains expected +Hash+ entry.
63
62
  class HasEntry
64
63
  include BaseMethods
@@ -73,6 +72,7 @@ module Mocha
73
72
  def matches?(available_parameters)
74
73
  parameter = available_parameters.shift
75
74
  return false unless parameter.respond_to?(:keys) && parameter.respond_to?(:[])
75
+
76
76
  matching_keys = parameter.keys.select { |key| @key.to_matcher.matches?([key]) }
77
77
  matching_keys.any? { |key| @value.to_matcher.matches?([parameter[key]]) }
78
78
  end
@@ -99,7 +99,5 @@ module Mocha
99
99
  end
100
100
  end
101
101
  end
102
-
103
- provide_deprecated_access_to(:HasEntry)
104
102
  end
105
103
  end
@@ -1,5 +1,6 @@
1
- require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
@@ -23,13 +24,11 @@ module Mocha
23
24
  # object.method_1('key_2' => 2)
24
25
  # # error raised, because method_1 was not called with Hash containing key: 'key_1'
25
26
  #
26
- def has_key(key) # rubocop:disable Naming/PredicateName
27
+ def has_key(key) # rubocop:disable Naming/PredicatePrefix
27
28
  HasKey.new(key)
28
29
  end
29
30
  end
30
31
 
31
- define_deprecated_matcher_method(:has_key)
32
-
33
32
  # Parameter matcher which matches when actual parameter contains +Hash+ entry with expected key.
34
33
  class HasKey
35
34
  include BaseMethods
@@ -43,6 +42,7 @@ module Mocha
43
42
  def matches?(available_parameters)
44
43
  parameter = available_parameters.shift
45
44
  return false unless parameter.respond_to?(:keys)
45
+
46
46
  parameter.keys.any? { |key| @key.to_matcher.matches?([key]) }
47
47
  end
48
48
 
@@ -51,7 +51,5 @@ module Mocha
51
51
  "has_key(#{@key.mocha_inspect})"
52
52
  end
53
53
  end
54
-
55
- provide_deprecated_access_to(:HasKey)
56
54
  end
57
55
  end
@@ -1,5 +1,6 @@
1
- require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
@@ -23,13 +24,11 @@ module Mocha
23
24
  # object.method_1(:key_2 => 2)
24
25
  # # error raised, because method_1 was not called with Hash containing key: :key_1
25
26
  #
26
- def has_keys(*keys) # rubocop:disable Naming/PredicateName
27
+ def has_keys(*keys) # rubocop:disable Naming/PredicatePrefix
27
28
  HasKeys.new(*keys)
28
29
  end
29
30
  end
30
31
 
31
- define_deprecated_matcher_method(:has_keys)
32
-
33
32
  # Parameter matcher which matches when actual parameter contains +Hash+ with all expected keys.
34
33
  class HasKeys
35
34
  include BaseMethods
@@ -53,10 +52,8 @@ module Mocha
53
52
 
54
53
  # @private
55
54
  def mocha_inspect
56
- "has_keys(#{@keys.mocha_inspect(false)})"
55
+ "has_keys(#{@keys.mocha_inspect(wrapped: false)})"
57
56
  end
58
57
  end
59
-
60
- provide_deprecated_access_to(:HasKeys)
61
58
  end
62
59
  end
@@ -1,5 +1,6 @@
1
- require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
@@ -23,13 +24,11 @@ module Mocha
23
24
  # object.method_1('key_2' => 2)
24
25
  # # error raised, because method_1 was not called with Hash containing value: 1
25
26
  #
26
- def has_value(value) # rubocop:disable Naming/PredicateName
27
+ def has_value(value) # rubocop:disable Naming/PredicatePrefix
27
28
  HasValue.new(value)
28
29
  end
29
30
  end
30
31
 
31
- define_deprecated_matcher_method(:has_value)
32
-
33
32
  # Parameter matcher which matches when actual parameter contains +Hash+ entry with expected value.
34
33
  class HasValue
35
34
  include BaseMethods
@@ -43,6 +42,7 @@ module Mocha
43
42
  def matches?(available_parameters)
44
43
  parameter = available_parameters.shift
45
44
  return false unless parameter.respond_to?(:values)
45
+
46
46
  parameter.values.any? { |value| @value.to_matcher.matches?([value]) }
47
47
  end
48
48
 
@@ -51,7 +51,5 @@ module Mocha
51
51
  "has_value(#{@value.mocha_inspect})"
52
52
  end
53
53
  end
54
-
55
- provide_deprecated_access_to(:HasValue)
56
54
  end
57
55
  end
@@ -1,6 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/parameter_matchers/all_of'
2
- require 'mocha/parameter_matchers/base'
3
- require 'mocha/parameter_matchers/deprecations'
4
+ require 'mocha/parameter_matchers/base_methods'
4
5
 
5
6
  module Mocha
6
7
  module ParameterMatchers
@@ -67,8 +68,6 @@ module Mocha
67
68
  end
68
69
  end
69
70
 
70
- define_deprecated_matcher_method(:includes)
71
-
72
71
  # Parameter matcher which matches when actual parameter includes expected values.
73
72
  class Includes
74
73
  include BaseMethods
@@ -79,25 +78,22 @@ module Mocha
79
78
  end
80
79
 
81
80
  # @private
82
- # rubocop:disable Metrics/PerceivedComplexity
83
81
  def matches?(available_parameters)
84
82
  parameter = available_parameters.shift
85
83
  return false unless parameter.respond_to?(:include?)
84
+
86
85
  if @items.size == 1
87
- # rubocop:disable Style/GuardClause
88
86
  if parameter.respond_to?(:any?) && !parameter.is_a?(String)
89
87
  parameter = parameter.keys if parameter.is_a?(Hash)
90
- return parameter.any? { |p| @items.first.to_matcher.matches?([p]) }
88
+ parameter.any? { |p| @items.first.to_matcher.matches?([p]) }
91
89
  else
92
- return parameter.include?(@items.first)
90
+ parameter.include?(@items.first)
93
91
  end
94
- # rubocop:enable Style/GuardClause
95
92
  else
96
93
  includes_matchers = @items.map { |item| Includes.new(item) }
97
94
  AllOf.new(*includes_matchers).matches?([parameter])
98
95
  end
99
96
  end
100
- # rubocop:enable Metrics/PerceivedComplexity
101
97
 
102
98
  # @private
103
99
  def mocha_inspect
@@ -105,7 +101,5 @@ module Mocha
105
101
  "includes(#{item_descriptions.join(', ')})"
106
102
  end
107
103
  end
108
-
109
- provide_deprecated_access_to(:Includes)
110
104
  end
111
105
  end
@@ -1,4 +1,6 @@
1
- require 'mocha/parameter_matchers/base'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
2
4
  require 'mocha/parameter_matchers/equals'
3
5
  require 'mocha/parameter_matchers/positional_or_keyword_hash'
4
6
 
@@ -7,11 +9,11 @@ module Mocha
7
9
  # @private
8
10
  module InstanceMethods
9
11
  # @private
10
- def to_matcher(expectation: nil, top_level: false)
12
+ def to_matcher(expectation: nil, top_level: false, last: false)
11
13
  if is_a?(BaseMethods)
12
14
  self
13
15
  elsif Hash === self && top_level
14
- Mocha::ParameterMatchers::PositionalOrKeywordHash.new(self, expectation)
16
+ Mocha::ParameterMatchers::PositionalOrKeywordHash.new(self, expectation, last)
15
17
  else
16
18
  Mocha::ParameterMatchers::Equals.new(self)
17
19
  end
@@ -1,5 +1,6 @@
1
- require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
@@ -28,8 +29,6 @@ module Mocha
28
29
  end
29
30
  end
30
31
 
31
- define_deprecated_matcher_method(:instance_of)
32
-
33
32
  # Parameter matcher which matches when actual parameter is an instance of the specified class.
34
33
  class InstanceOf
35
34
  include BaseMethods
@@ -50,7 +49,5 @@ module Mocha
50
49
  "instance_of(#{@klass.mocha_inspect})"
51
50
  end
52
51
  end
53
-
54
- provide_deprecated_access_to(:InstanceOf)
55
52
  end
56
53
  end
@@ -1,5 +1,6 @@
1
- require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
@@ -24,13 +25,11 @@ module Mocha
24
25
  # object.method_1('string')
25
26
  # # error raised, because method_1 was not called with an Integer
26
27
  #
27
- def is_a(klass) # rubocop:disable Naming/PredicateName
28
+ def is_a(klass) # rubocop:disable Naming/PredicatePrefix
28
29
  IsA.new(klass)
29
30
  end
30
31
  end
31
32
 
32
- define_deprecated_matcher_method(:is_a)
33
-
34
33
  # Parameter matcher which matches when actual parameter is a specific class.
35
34
  class IsA
36
35
  include BaseMethods
@@ -51,7 +50,5 @@ module Mocha
51
50
  "is_a(#{@klass.mocha_inspect})"
52
51
  end
53
52
  end
54
-
55
- provide_deprecated_access_to(:IsA)
56
53
  end
57
54
  end
@@ -1,5 +1,6 @@
1
- require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
@@ -28,8 +29,6 @@ module Mocha
28
29
  end
29
30
  end
30
31
 
31
- define_deprecated_matcher_method(:kind_of)
32
-
33
32
  # Parameter matcher which matches when actual parameter is a kind of specified class.
34
33
  class KindOf
35
34
  include BaseMethods
@@ -52,7 +51,5 @@ module Mocha
52
51
  "kind_of(#{@klass.mocha_inspect})"
53
52
  end
54
53
  end
55
-
56
- provide_deprecated_access_to(:KindOf)
57
54
  end
58
55
  end
@@ -1,5 +1,6 @@
1
- require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
@@ -28,8 +29,6 @@ module Mocha
28
29
  end
29
30
  end
30
31
 
31
- define_deprecated_matcher_method(:Not)
32
-
33
32
  # Parameter matcher which inverts the logic of the specified matcher using a logical NOT operation.
34
33
  class Not
35
34
  include BaseMethods
@@ -50,7 +49,5 @@ module Mocha
50
49
  "Not(#{@matcher.mocha_inspect})"
51
50
  end
52
51
  end
53
-
54
- provide_deprecated_access_to(:Not)
55
52
  end
56
53
  end
@@ -1,4 +1,4 @@
1
- require 'mocha/parameter_matchers/deprecations'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Mocha
4
4
  module ParameterMatchers
@@ -38,8 +38,6 @@ module Mocha
38
38
  end
39
39
  end
40
40
 
41
- define_deprecated_matcher_method(:optionally)
42
-
43
41
  # Parameter matcher which allows optional parameters to be specified.
44
42
  class Optionally
45
43
  include BaseMethods
@@ -55,6 +53,7 @@ module Mocha
55
53
  while !available_parameters.empty? && (index < @matchers.length)
56
54
  matcher = @matchers[index]
57
55
  return false unless matcher.matches?(available_parameters)
56
+
58
57
  index += 1
59
58
  end
60
59
  true
@@ -65,7 +64,5 @@ module Mocha
65
64
  "optionally(#{@matchers.map(&:mocha_inspect).join(', ')})"
66
65
  end
67
66
  end
68
-
69
- provide_deprecated_access_to(:Optionally)
70
67
  end
71
68
  end
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/configuration'
2
4
  require 'mocha/deprecation'
3
- require 'mocha/parameter_matchers/base'
5
+ require 'mocha/ruby_version'
6
+ require 'mocha/parameter_matchers/base_methods'
4
7
  require 'mocha/parameter_matchers/has_entries'
5
- require 'mocha/parameter_matchers/deprecations'
6
8
 
7
9
  module Mocha
8
10
  module ParameterMatchers
@@ -10,33 +12,53 @@ module Mocha
10
12
  class PositionalOrKeywordHash
11
13
  include BaseMethods
12
14
 
13
- def initialize(value, expectation)
14
- @value = value
15
+ def initialize(expected_value, expectation, last_expected_value)
16
+ @expected_value = expected_value
15
17
  @expectation = expectation
18
+ @last_expected_value = last_expected_value
16
19
  end
17
20
 
18
- def matches?(available_parameters)
19
- parameter, is_last_parameter = extract_parameter(available_parameters)
20
-
21
- return false unless HasEntries.new(@value, exact: true).matches?([parameter])
22
-
23
- if is_last_parameter && !same_type_of_hash?(parameter, @value)
24
- return false if Mocha.configuration.strict_keyword_argument_matching?
21
+ def matches?(actual_values)
22
+ actual_value, is_last_actual_value = extract_actual_value(actual_values)
25
23
 
26
- deprecation_warning(parameter, @value) if Mocha::RUBY_V27_PLUS
24
+ if !matches_entries_exactly?(actual_value)
25
+ false
26
+ elsif is_last_actual_value
27
+ matches_last_actual_value?(actual_value)
28
+ else
29
+ true
27
30
  end
28
-
29
- true
30
31
  end
31
32
 
32
33
  def mocha_inspect
33
- @value.mocha_inspect
34
+ @expected_value.mocha_inspect
34
35
  end
35
36
 
36
37
  private
37
38
 
38
- def extract_parameter(available_parameters)
39
- [available_parameters.shift, available_parameters.empty?]
39
+ def matches_entries_exactly?(actual_value)
40
+ HasEntries.new(@expected_value, exact: true).matches?([actual_value])
41
+ end
42
+
43
+ def matches_last_actual_value?(actual_value)
44
+ if same_type_of_hash?(actual_value, @expected_value)
45
+ true
46
+ elsif last_expected_value_is_positional_hash? # rubocop:disable Lint/DuplicateBranch
47
+ true
48
+ elsif Mocha.configuration.strict_keyword_argument_matching?
49
+ false
50
+ else
51
+ deprecation_warning(actual_value, @expected_value) if Mocha::RUBY_V27_PLUS
52
+ true
53
+ end
54
+ end
55
+
56
+ def last_expected_value_is_positional_hash?
57
+ @last_expected_value && !ruby2_keywords_hash?(@expected_value)
58
+ end
59
+
60
+ def extract_actual_value(actual_values)
61
+ [actual_values.shift, actual_values.empty?]
40
62
  end
41
63
 
42
64
  def same_type_of_hash?(actual, expected)
@@ -65,7 +87,5 @@ module Mocha
65
87
  "defined at #{@expectation.definition_location}"
66
88
  end
67
89
  end
68
-
69
- provide_deprecated_access_to(:PositionalOrKeywordHash)
70
90
  end
71
91
  end
@@ -1,5 +1,6 @@
1
- require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
3
4
 
4
5
  module Mocha
5
6
  module ParameterMatchers
@@ -28,8 +29,6 @@ module Mocha
28
29
  end
29
30
  end
30
31
 
31
- define_deprecated_matcher_method(:regexp_matches)
32
-
33
32
  # Parameter matcher which matches if specified regular expression matches actual paramter.
34
33
  class RegexpMatches
35
34
  include BaseMethods
@@ -43,6 +42,7 @@ module Mocha
43
42
  def matches?(available_parameters)
44
43
  parameter = available_parameters.shift
45
44
  return false unless parameter.respond_to?(:=~)
45
+
46
46
  parameter =~ @regexp
47
47
  end
48
48
 
@@ -51,7 +51,5 @@ module Mocha
51
51
  "regexp_matches(#{@regexp.mocha_inspect})"
52
52
  end
53
53
  end
54
-
55
- provide_deprecated_access_to(:RegexpMatches)
56
54
  end
57
55
  end
@@ -1,6 +1,7 @@
1
- require 'mocha/parameter_matchers/base'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
2
4
  require 'mocha/parameter_matchers/all_of'
3
- require 'mocha/parameter_matchers/deprecations'
4
5
  require 'yaml'
5
6
 
6
7
  module Mocha
@@ -56,8 +57,6 @@ module Mocha
56
57
  end
57
58
  end
58
59
 
59
- define_deprecated_matcher_method(:responds_with)
60
-
61
60
  # Parameter matcher which matches if actual parameter returns expected result when specified method is invoked.
62
61
  class RespondsWith
63
62
  include BaseMethods
@@ -79,7 +78,5 @@ module Mocha
79
78
  "responds_with(#{@message.mocha_inspect}, #{@result.mocha_inspect})"
80
79
  end
81
80
  end
82
-
83
- provide_deprecated_access_to(:RespondsWith)
84
81
  end
85
82
  end
@@ -1,5 +1,6 @@
1
- require 'mocha/parameter_matchers/base'
2
- require 'mocha/parameter_matchers/deprecations'
1
+ # frozen_string_literal: true
2
+
3
+ require 'mocha/parameter_matchers/base_methods'
3
4
  require 'yaml'
4
5
 
5
6
  module Mocha
@@ -28,8 +29,6 @@ module Mocha
28
29
  end
29
30
  end
30
31
 
31
- define_deprecated_matcher_method(:yaml_equivalent)
32
-
33
32
  # Parameter matcher which matches if actual parameter is YAML equivalent of specified object.
34
33
  class YamlEquivalent
35
34
  include BaseMethods
@@ -52,7 +51,5 @@ module Mocha
52
51
  "yaml_equivalent(#{@object.mocha_inspect})"
53
52
  end
54
53
  end
55
-
56
- provide_deprecated_access_to(:YamlEquivalent)
57
54
  end
58
55
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  # Matcher classes used as parameters for {Expectation#with} to restrict the parameter values which will match the expectation. Can be nested. Build matcher instances in tests using methods in {Methods}, e.g. {Methods#includes}.
3
5
  module ParameterMatchers
@@ -6,7 +8,6 @@ module Mocha
6
8
  end
7
9
  end
8
10
 
9
- require 'mocha/parameter_matchers/deprecations'
10
11
  require 'mocha/parameter_matchers/instance_methods'
11
12
 
12
13
  require 'mocha/parameter_matchers/all_of'
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/inspect'
2
4
  require 'mocha/parameter_matchers'
3
5
 
@@ -32,7 +34,13 @@ module Mocha
32
34
  end
33
35
 
34
36
  def matchers
35
- @expected_parameters.map { |p| p.to_matcher(expectation: @expectation, top_level: true) }
37
+ @expected_parameters.map.with_index do |parameter, index|
38
+ parameter.to_matcher(
39
+ expectation: @expectation,
40
+ top_level: true,
41
+ last: index == @expected_parameters.length - 1
42
+ )
43
+ end
36
44
  end
37
45
  end
38
46
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  class RaisedException
3
5
  def initialize(exception)