mocha 2.8.2 → 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 -25
  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 +4 -3
  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 -23
  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 -44
  102. data/lib/mocha/receivers.rb +0 -45
@@ -1,42 +1,64 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/configuration'
2
4
  require 'mocha/deprecation'
5
+ require 'mocha/ruby_version'
3
6
  require 'mocha/parameter_matchers/base'
4
7
  require 'mocha/parameter_matchers/has_entries'
5
- require 'mocha/parameter_matchers/deprecations'
6
8
 
7
9
  module Mocha
8
10
  module ParameterMatchers
9
11
  # @private
10
12
  class PositionalOrKeywordHash
11
- include BaseMethods
13
+ include Base
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,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 that matches +regexp+.
8
- #
9
- # @param [Regexp] regexp regular expression to match.
10
- # @return [RegexpMatches] parameter matcher.
11
- #
12
- # @see Expectation#with
13
- #
14
- # @example Actual parameter is matched by specified regular expression.
15
- # object = mock()
16
- # object.expects(:method_1).with(regexp_matches(/e/))
17
- # object.method_1('hello')
18
- # # no error raised
19
- #
20
- # @example Actual parameter is not matched by specified regular expression.
21
- # object = mock()
22
- # object.expects(:method_1).with(regexp_matches(/a/))
23
- # object.method_1('hello')
24
- # # error raised, because method_1 was not called with a parameter that matched the
25
- # # regular expression
26
- def regexp_matches(regexp)
27
- RegexpMatches.new(regexp)
28
- end
7
+ # Matches any object that matches +regexp+.
8
+ #
9
+ # @param [Regexp] regexp regular expression to match.
10
+ # @return [RegexpMatches] parameter matcher.
11
+ #
12
+ # @see Expectation#with
13
+ #
14
+ # @example Actual parameter is matched by specified regular expression.
15
+ # object = mock()
16
+ # object.expects(:method_1).with(regexp_matches(/e/))
17
+ # object.method_1('hello')
18
+ # # no error raised
19
+ #
20
+ # @example Actual parameter is not matched by specified regular expression.
21
+ # object = mock()
22
+ # object.expects(:method_1).with(regexp_matches(/a/))
23
+ # object.method_1('hello')
24
+ # # error raised, because method_1 was not called with a parameter that matched the
25
+ # # regular expression
26
+ def regexp_matches(regexp)
27
+ RegexpMatches.new(regexp)
29
28
  end
30
29
 
31
- define_deprecated_matcher_method(:regexp_matches)
32
-
33
30
  # Parameter matcher which matches if specified regular expression matches actual paramter.
34
31
  class RegexpMatches
35
- include BaseMethods
32
+ include Base
36
33
 
37
34
  # @private
38
35
  def initialize(regexp)
@@ -43,6 +40,7 @@ module Mocha
43
40
  def matches?(available_parameters)
44
41
  parameter = available_parameters.shift
45
42
  return false unless parameter.respond_to?(:=~)
43
+
46
44
  parameter =~ @regexp
47
45
  end
48
46
 
@@ -51,7 +49,5 @@ module Mocha
51
49
  "regexp_matches(#{@regexp.mocha_inspect})"
52
50
  end
53
51
  end
54
-
55
- provide_deprecated_access_to(:RegexpMatches)
56
52
  end
57
53
  end
@@ -1,66 +1,63 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/parameter_matchers/base'
2
4
  require 'mocha/parameter_matchers/all_of'
3
- require 'mocha/parameter_matchers/deprecations'
4
5
  require 'yaml'
5
6
 
6
7
  module Mocha
7
8
  module ParameterMatchers
8
- module Methods
9
- # @overload def responds_with(message, result)
10
- # Matches any object that responds to +message+ with +result+. To put it another way, it tests the quack, not the duck.
11
- # @param [Symbol] message method to invoke.
12
- # @param [Object] result expected result of sending +message+.
13
- # @overload def responds_with(messages_vs_results)
14
- # Matches any object that responds to all the messages with the corresponding results as specified by +messages_vs_results+.
15
- # @param [Hash<Symbol,Object>] messages_vs_results +Hash+ of messages vs results.
16
- # @raise [ArgumentError] if +messages_vs_results+ does not contain at least one entry.
17
- #
18
- # @return [RespondsWith] parameter matcher.
19
- #
20
- # @see Expectation#with
21
- #
22
- # @example Actual parameter responds with "FOO" when :upcase is invoked.
23
- # object = mock()
24
- # object.expects(:method_1).with(responds_with(:upcase, "FOO"))
25
- # object.method_1("foo")
26
- # # no error raised, because "foo".upcase == "FOO"
27
- #
28
- # @example Actual parameter does not respond with "FOO" when :upcase is invoked.
29
- # object = mock()
30
- # object.expects(:method_1).with(responds_with(:upcase, "BAR"))
31
- # object.method_1("foo")
32
- # # error raised, because "foo".upcase != "BAR"
33
- #
34
- # @example Actual parameter responds with "FOO" when :upcase is invoked and "oof" when :reverse is invoked.
35
- # object = mock()
36
- # object.expects(:method_1).with(responds_with(upcase: "FOO", reverse: "oof"))
37
- # object.method_1("foo")
38
- # # no error raised, because "foo".upcase == "FOO" and "foo".reverse == "oof"
39
- def responds_with(*options)
40
- case options.length
41
- when 0
42
- raise ArgumentError, 'No arguments. Expecting at least one.'
43
- when 1
44
- option = options.first
45
- raise ArgumentError, 'Argument is not a Hash.' unless option.is_a?(Hash)
46
- raise ArgumentError, 'Argument has no entries.' if option.empty?
9
+ # @overload def responds_with(message, result)
10
+ # Matches any object that responds to +message+ with +result+. To put it another way, it tests the quack, not the duck.
11
+ # @param [Symbol] message method to invoke.
12
+ # @param [Object] result expected result of sending +message+.
13
+ # @overload def responds_with(messages_vs_results)
14
+ # Matches any object that responds to all the messages with the corresponding results as specified by +messages_vs_results+.
15
+ # @param [Hash<Symbol,Object>] messages_vs_results +Hash+ of messages vs results.
16
+ # @raise [ArgumentError] if +messages_vs_results+ does not contain at least one entry.
17
+ #
18
+ # @return [RespondsWith] parameter matcher.
19
+ #
20
+ # @see Expectation#with
21
+ #
22
+ # @example Actual parameter responds with "FOO" when :upcase is invoked.
23
+ # object = mock()
24
+ # object.expects(:method_1).with(responds_with(:upcase, "FOO"))
25
+ # object.method_1("foo")
26
+ # # no error raised, because "foo".upcase == "FOO"
27
+ #
28
+ # @example Actual parameter does not respond with "FOO" when :upcase is invoked.
29
+ # object = mock()
30
+ # object.expects(:method_1).with(responds_with(:upcase, "BAR"))
31
+ # object.method_1("foo")
32
+ # # error raised, because "foo".upcase != "BAR"
33
+ #
34
+ # @example Actual parameter responds with "FOO" when :upcase is invoked and "oof" when :reverse is invoked.
35
+ # object = mock()
36
+ # object.expects(:method_1).with(responds_with(upcase: "FOO", reverse: "oof"))
37
+ # object.method_1("foo")
38
+ # # no error raised, because "foo".upcase == "FOO" and "foo".reverse == "oof"
39
+ def responds_with(*options)
40
+ case options.length
41
+ when 0
42
+ raise ArgumentError, 'No arguments. Expecting at least one.'
43
+ when 1
44
+ option = options.first
45
+ raise ArgumentError, 'Argument is not a Hash.' unless option.is_a?(Hash)
46
+ raise ArgumentError, 'Argument has no entries.' if option.empty?
47
47
 
48
- matchers = option.map { |message, result| RespondsWith.new(message, result) }
49
- AllOf.new(*matchers)
50
- when 2
51
- message, result = options
52
- RespondsWith.new(message, result)
53
- else
54
- raise ArgumentError, 'Too many arguments; use either a single argument (must be a Hash) or two arguments (a message and a result).'
55
- end
48
+ matchers = option.map { |message, result| RespondsWith.new(message, result) }
49
+ AllOf.new(*matchers)
50
+ when 2
51
+ message, result = options
52
+ RespondsWith.new(message, result)
53
+ else
54
+ raise ArgumentError, 'Too many arguments; use either a single argument (must be a Hash) or two arguments (a message and a result).'
56
55
  end
57
56
  end
58
57
 
59
- define_deprecated_matcher_method(:responds_with)
60
-
61
58
  # Parameter matcher which matches if actual parameter returns expected result when specified method is invoked.
62
59
  class RespondsWith
63
- include BaseMethods
60
+ include Base
64
61
 
65
62
  # @private
66
63
  def initialize(message, result)
@@ -79,7 +76,5 @@ module Mocha
79
76
  "responds_with(#{@message.mocha_inspect}, #{@result.mocha_inspect})"
80
77
  end
81
78
  end
82
-
83
- provide_deprecated_access_to(:RespondsWith)
84
79
  end
85
80
  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
  require 'yaml'
4
5
 
5
6
  module Mocha
6
7
  module ParameterMatchers
7
- module Methods
8
- # Matches any YAML that represents the specified +object+
9
- #
10
- # @param [Object] object object whose YAML to compare.
11
- # @return [YamlEquivalent] parameter matcher.
12
- #
13
- # @see Expectation#with
14
- #
15
- # @example Actual parameter is YAML equivalent of specified +object+.
16
- # object = mock()
17
- # object.expects(:method_1).with(yaml_equivalent(1, 2, 3))
18
- # object.method_1("--- \n- 1\n- 2\n- 3\n")
19
- # # no error raised
20
- #
21
- # @example Actual parameter is not YAML equivalent of specified +object+.
22
- # object = mock()
23
- # object.expects(:method_1).with(yaml_equivalent(1, 2, 3))
24
- # object.method_1("--- \n- 1\n- 2\n")
25
- # # error raised, because method_1 was not called with YAML representing the specified Array
26
- def yaml_equivalent(object)
27
- YamlEquivalent.new(object)
28
- end
8
+ # Matches any YAML that represents the specified +object+
9
+ #
10
+ # @param [Object] object object whose YAML to compare.
11
+ # @return [YamlEquivalent] parameter matcher.
12
+ #
13
+ # @see Expectation#with
14
+ #
15
+ # @example Actual parameter is YAML equivalent of specified +object+.
16
+ # object = mock()
17
+ # object.expects(:method_1).with(yaml_equivalent(1, 2, 3))
18
+ # object.method_1("--- \n- 1\n- 2\n- 3\n")
19
+ # # no error raised
20
+ #
21
+ # @example Actual parameter is not YAML equivalent of specified +object+.
22
+ # object = mock()
23
+ # object.expects(:method_1).with(yaml_equivalent(1, 2, 3))
24
+ # object.method_1("--- \n- 1\n- 2\n")
25
+ # # error raised, because method_1 was not called with YAML representing the specified Array
26
+ def yaml_equivalent(object)
27
+ YamlEquivalent.new(object)
29
28
  end
30
29
 
31
- define_deprecated_matcher_method(:yaml_equivalent)
32
-
33
30
  # Parameter matcher which matches if actual parameter is YAML equivalent of specified object.
34
31
  class YamlEquivalent
35
- include BaseMethods
32
+ include Base
36
33
 
37
34
  # @private
38
35
  def initialize(object)
@@ -52,7 +49,5 @@ module Mocha
52
49
  "yaml_equivalent(#{@object.mocha_inspect})"
53
50
  end
54
51
  end
55
-
56
- provide_deprecated_access_to(:YamlEquivalent)
57
52
  end
58
53
  end
@@ -1,12 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
- # 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
- module ParameterMatchers
4
- # These methods build instances of the {ParameterMatchers} classes which are used with {Expectation#with} to restrict the parameter values. Can be nested, e.g. see {Methods#all_of} examples.
5
- module Methods; end
6
- end
4
+ # Used as parameters for {Expectation#with} to restrict the parameter values which will match the expectation. Can be nested.
5
+ module ParameterMatchers; end
7
6
  end
8
7
 
9
- require 'mocha/parameter_matchers/deprecations'
10
8
  require 'mocha/parameter_matchers/instance_methods'
11
9
 
12
10
  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)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/single_return_value'
2
4
 
3
5
  module Mocha
@@ -1,4 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  RUBY_V27_PLUS = Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.7')
5
+ RUBY_V30_PLUS = Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('3.0')
3
6
  RUBY_V34_PLUS = Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('3.4')
4
7
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  # Used to constrain the order in which expectations can occur.
3
5
  #
@@ -1,4 +1,4 @@
1
- require 'mocha/is_a'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module Mocha
4
4
  class SingleReturnValue
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  # A state machine that is used to constrain the order of invocations.
3
5
  # An invocation can be constrained to occur when a state {#is}, or {#is_not}, active.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ruby2_keywords'
2
4
  require 'mocha/ruby_version'
3
5
 
@@ -23,6 +25,7 @@ module Mocha
23
25
  remove_new_method
24
26
  mock.unstub(method_name.to_sym)
25
27
  return if mock.any_expectations?
28
+
26
29
  reset_mocha
27
30
  end
28
31
 
@@ -36,6 +39,7 @@ module Mocha
36
39
 
37
40
  def hide_original_method
38
41
  return unless original_method_owner.__method_exists__?(method_name)
42
+
39
43
  store_original_method_visibility
40
44
  use_prepended_module_for_stub_method
41
45
  end
@@ -55,8 +59,10 @@ module Mocha
55
59
  end
56
60
 
57
61
  def matches?(other)
58
- return false unless other.class == self.class
59
- (stubbee.object_id == other.stubbee.object_id) && (method_name == other.method_name)
62
+ return false unless other.instance_of?(self.class)
63
+
64
+ (stubbee.object_id == other.stubbee.object_id) && # rubocop:disable Lint/IdentityComparison
65
+ (method_name == other.method_name)
60
66
  end
61
67
 
62
68
  alias_method :==, :eql?
@@ -69,6 +75,7 @@ module Mocha
69
75
 
70
76
  def retain_original_visibility(method_owner)
71
77
  return unless @original_visibility
78
+
72
79
  Module.instance_method(@original_visibility).bind(method_owner).call(method_name)
73
80
  end
74
81
 
@@ -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,4 +1,5 @@
1
- require 'mocha/ruby_version'
1
+ # frozen_string_literal: true
2
+
2
3
  require 'mocha/integration/test_unit'
3
4
 
4
5
  unless Mocha::Integration::TestUnit.activate
data/lib/mocha/thrower.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  class Thrower
3
5
  def initialize(tag, object = nil)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  class ThrownObject
3
5
  def initialize(tag, value = nil)
data/lib/mocha/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
- VERSION = '2.8.2'.freeze
4
+ VERSION = '3.0.0-rc.1'
3
5
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mocha
2
4
  class YieldParameters
3
5
  def initialize
data/lib/mocha.rb CHANGED
@@ -1 +1,6 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'mocha/version'
4
+
5
+ module Mocha
6
+ end
data/mocha.gemspec CHANGED
@@ -2,14 +2,19 @@ lib = File.expand_path('../lib/', __FILE__)
2
2
  $LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
3
3
  require 'mocha/version'
4
4
 
5
+ DESCRIPTION =
6
+ 'A library for mocking and stubbing with a unified, simple and readable syntax ' \
7
+ 'for both full & partial mocking. Built-in support for Minitest and Test::Unit. ' \
8
+ 'Supported by many other test frameworks, e.g. RSpec.'.freeze
9
+
5
10
  Gem::Specification.new do |s|
6
11
  s.name = 'mocha'
7
12
  s.version = Mocha::VERSION
8
13
  s.licenses = ['MIT', 'BSD-2-Clause']
9
- s.required_ruby_version = '>= 2.1'
14
+ s.required_ruby_version = '>= 2.2'
10
15
 
11
16
  s.authors = ['James Mead']
12
- s.description = 'Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.'
17
+ s.description = DESCRIPTION
13
18
  s.email = 'mocha-developer@googlegroups.com'
14
19
 
15
20
  s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
@@ -27,8 +32,9 @@ Gem::Specification.new do |s|
27
32
  'documentation_uri' => 'https://mocha.jamesmead.org/',
28
33
  'funding_uri' => 'https://github.com/sponsors/floehopper',
29
34
  'homepage_uri' => s.homepage,
30
- 'source_code_uri' => 'https://github.com/freerange/mocha'
35
+ 'source_code_uri' => 'https://github.com/freerange/mocha',
36
+ 'rubygems_mfa_required' => 'true'
31
37
  }
32
38
 
33
- s.add_runtime_dependency 'ruby2_keywords', '>= 0.0.5'
39
+ s.add_dependency 'ruby2_keywords', '>= 0.0.5'
34
40
  end