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
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mocha
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.8.0
4
+ version: 3.0.0.pre.rc.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Mead
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2025-11-11 00:00:00.000000000 Z
10
+ date: 2025-01-24 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: ruby2_keywords
@@ -24,8 +23,9 @@ dependencies:
24
23
  - - ">="
25
24
  - !ruby/object:Gem::Version
26
25
  version: 0.0.5
27
- description: Mocking and stubbing library with JMock/SchMock syntax, which allows
28
- mocking and stubbing of methods on real (non-mock) classes.
26
+ description: A library for mocking and stubbing with a unified, simple and readable
27
+ syntax for both full & partial mocking. Built-in support for Minitest and Test::Unit.
28
+ Supported by many other test frameworks, e.g. RSpec.
29
29
  email: mocha-developer@googlegroups.com
30
30
  executables: []
31
31
  extensions: []
@@ -44,19 +44,22 @@ files:
44
44
  - RELEASE.md
45
45
  - Rakefile
46
46
  - gemfiles/Gemfile.minitest.latest
47
+ - gemfiles/Gemfile.rubocop
47
48
  - gemfiles/Gemfile.test-unit.latest
48
49
  - lib/mocha.rb
49
50
  - lib/mocha/any_instance_method.rb
51
+ - lib/mocha/any_instance_receiver.rb
50
52
  - lib/mocha/api.rb
51
53
  - lib/mocha/argument_iterator.rb
52
54
  - lib/mocha/backtrace_filter.rb
53
- - lib/mocha/block_matcher.rb
55
+ - lib/mocha/block_matchers.rb
54
56
  - lib/mocha/cardinality.rb
55
57
  - lib/mocha/central.rb
56
58
  - lib/mocha/change_state_side_effect.rb
57
59
  - lib/mocha/class_methods.rb
58
60
  - lib/mocha/configuration.rb
59
- - lib/mocha/debug.rb
61
+ - lib/mocha/default_name.rb
62
+ - lib/mocha/default_receiver.rb
60
63
  - lib/mocha/deprecation.rb
61
64
  - lib/mocha/detection/minitest.rb
62
65
  - lib/mocha/detection/test_unit.rb
@@ -67,34 +70,34 @@ files:
67
70
  - lib/mocha/expectation_error_factory.rb
68
71
  - lib/mocha/expectation_list.rb
69
72
  - lib/mocha/hooks.rb
73
+ - lib/mocha/impersonating_any_instance_name.rb
74
+ - lib/mocha/impersonating_name.rb
70
75
  - lib/mocha/in_state_ordering_constraint.rb
71
76
  - lib/mocha/inspect.rb
72
77
  - lib/mocha/instance_method.rb
73
78
  - lib/mocha/integration/assertion_counter.rb
74
79
  - lib/mocha/integration/minitest.rb
75
80
  - lib/mocha/integration/minitest/adapter.rb
76
- - lib/mocha/integration/minitest/exception_translation.rb
77
81
  - lib/mocha/integration/monkey_patcher.rb
78
82
  - lib/mocha/integration/test_unit.rb
79
83
  - lib/mocha/integration/test_unit/adapter.rb
80
84
  - lib/mocha/invocation.rb
81
- - lib/mocha/is_a.rb
82
85
  - lib/mocha/logger.rb
83
86
  - lib/mocha/macos_version.rb
84
87
  - lib/mocha/method_matcher.rb
85
88
  - lib/mocha/minitest.rb
86
89
  - lib/mocha/mock.rb
87
90
  - lib/mocha/mockery.rb
88
- - lib/mocha/names.rb
91
+ - lib/mocha/name.rb
89
92
  - lib/mocha/not_initialized_error.rb
90
93
  - lib/mocha/object_methods.rb
94
+ - lib/mocha/object_receiver.rb
91
95
  - lib/mocha/parameter_matchers.rb
92
96
  - lib/mocha/parameter_matchers/all_of.rb
93
97
  - lib/mocha/parameter_matchers/any_of.rb
94
98
  - lib/mocha/parameter_matchers/any_parameters.rb
95
99
  - lib/mocha/parameter_matchers/anything.rb
96
100
  - lib/mocha/parameter_matchers/base.rb
97
- - lib/mocha/parameter_matchers/deprecations.rb
98
101
  - lib/mocha/parameter_matchers/equals.rb
99
102
  - lib/mocha/parameter_matchers/equivalent_uri.rb
100
103
  - lib/mocha/parameter_matchers/has_entries.rb
@@ -115,7 +118,6 @@ files:
115
118
  - lib/mocha/parameter_matchers/yaml_equivalent.rb
116
119
  - lib/mocha/parameters_matcher.rb
117
120
  - lib/mocha/raised_exception.rb
118
- - lib/mocha/receivers.rb
119
121
  - lib/mocha/return_values.rb
120
122
  - lib/mocha/ruby_version.rb
121
123
  - lib/mocha/sequence.rb
@@ -140,7 +142,7 @@ metadata:
140
142
  funding_uri: https://github.com/sponsors/floehopper
141
143
  homepage_uri: https://mocha.jamesmead.org
142
144
  source_code_uri: https://github.com/freerange/mocha
143
- post_install_message:
145
+ rubygems_mfa_required: 'true'
144
146
  rdoc_options: []
145
147
  require_paths:
146
148
  - lib
@@ -148,15 +150,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
150
  requirements:
149
151
  - - ">="
150
152
  - !ruby/object:Gem::Version
151
- version: '2.1'
153
+ version: '2.2'
152
154
  required_rubygems_version: !ruby/object:Gem::Requirement
153
155
  requirements:
154
156
  - - ">="
155
157
  - !ruby/object:Gem::Version
156
158
  version: '0'
157
159
  requirements: []
158
- rubygems_version: 3.5.3
159
- signing_key:
160
+ rubygems_version: 3.6.2
160
161
  specification_version: 4
161
162
  summary: Mocking and stubbing library
162
163
  test_files: []
data/lib/mocha/debug.rb DELETED
@@ -1,9 +0,0 @@
1
- module Mocha
2
- module Debug
3
- OPTIONS = (ENV['MOCHA_OPTIONS'] || '').split(',').freeze
4
-
5
- def self.puts(message)
6
- warn(message) if OPTIONS.include?('debug')
7
- end
8
- end
9
- end
@@ -1,14 +0,0 @@
1
- require 'mocha/expectation_error'
2
-
3
- module Mocha
4
- module Integration
5
- module Minitest
6
- def self.translate(exception)
7
- return exception unless exception.is_a?(::Mocha::ExpectationError)
8
- translated_exception = ::Minitest::Assertion.new(exception.message)
9
- translated_exception.set_backtrace(exception.backtrace)
10
- translated_exception
11
- end
12
- end
13
- end
14
- end
data/lib/mocha/is_a.rb DELETED
@@ -1,7 +0,0 @@
1
- class Object
2
- # :stopdoc:
3
-
4
- alias_method :__is_a__, :is_a?
5
-
6
- # :startdoc:
7
- end
data/lib/mocha/names.rb DELETED
@@ -1,43 +0,0 @@
1
- module Mocha
2
- class ImpersonatingName
3
- def initialize(object)
4
- @object = object
5
- end
6
-
7
- def mocha_inspect
8
- @object.mocha_inspect
9
- end
10
- end
11
-
12
- class ImpersonatingAnyInstanceName
13
- def initialize(klass)
14
- @klass = klass
15
- end
16
-
17
- def mocha_inspect
18
- "#<AnyInstance:#{@klass.mocha_inspect}>"
19
- end
20
- end
21
-
22
- class Name
23
- def initialize(name)
24
- @name = name.to_s
25
- end
26
-
27
- def mocha_inspect
28
- "#<Mock:#{@name}>"
29
- end
30
- end
31
-
32
- class DefaultName
33
- def initialize(mock)
34
- @mock = mock
35
- end
36
-
37
- def mocha_inspect
38
- address = @mock.__id__ * 2
39
- address += 0x100000000 if address < 0
40
- "#<Mock:0x#{format('%<address>x', address: address)}>"
41
- end
42
- end
43
- end
@@ -1,46 +0,0 @@
1
- require 'mocha/deprecation'
2
- require 'set'
3
-
4
- module Mocha
5
- module ParameterMatchers
6
- module Methods
7
- # @private
8
- def self.included(base)
9
- base.define_singleton_method(:const_missing) do |name|
10
- if ParameterMatchers.access_deprecated?(name)
11
- Mocha::ParameterMatchers.const_get(name).tap do |mod|
12
- Deprecation.warning(
13
- "Referencing #{name} outside its namespace is deprecated. Use fully-qualified #{mod} instead."
14
- )
15
- end
16
- else
17
- super(name)
18
- end
19
- end
20
- end
21
- end
22
-
23
- # @private
24
- @classes_with_access_deprecated = Set.new
25
-
26
- # @private
27
- def self.provide_deprecated_access_to(name)
28
- @classes_with_access_deprecated.add(name)
29
- end
30
-
31
- # @private
32
- def self.access_deprecated?(name)
33
- @classes_with_access_deprecated.include?(name)
34
- end
35
-
36
- # @private
37
- def self.define_deprecated_matcher_method(name)
38
- define_method(name) do |*args|
39
- Deprecation.warning(
40
- "Calling #{ParameterMatchers}##{name} is deprecated. Use #{Methods}##{name} instead."
41
- )
42
- Methods.instance_method(name).bind(self).call(*args)
43
- end
44
- end
45
- end
46
- end
@@ -1,45 +0,0 @@
1
- module Mocha
2
- class ObjectReceiver
3
- def initialize(object)
4
- @object = object
5
- end
6
-
7
- def mocks
8
- object = @object
9
- mocks = []
10
- while object
11
- mocha = object.mocha(false)
12
- mocks << mocha if mocha
13
- object = object.is_a?(Class) ? object.superclass : nil
14
- end
15
- mocks
16
- end
17
- end
18
-
19
- class AnyInstanceReceiver
20
- def initialize(klass)
21
- @klass = klass
22
- end
23
-
24
- def mocks
25
- klass = @klass
26
- mocks = []
27
- while klass
28
- mocha = klass.any_instance.mocha(false)
29
- mocks << mocha if mocha
30
- klass = klass.superclass
31
- end
32
- mocks
33
- end
34
- end
35
-
36
- class DefaultReceiver
37
- def initialize(mock)
38
- @mock = mock
39
- end
40
-
41
- def mocks
42
- [@mock]
43
- end
44
- end
45
- end