mocha 2.7.1 → 3.0.0.pre.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +67 -3
- data/.rubocop_todo.yml +25 -13
- data/Gemfile +11 -27
- data/README.md +3 -4
- data/RELEASE.md +37 -0
- data/Rakefile +6 -5
- data/gemfiles/Gemfile.minitest.latest +3 -3
- data/gemfiles/Gemfile.rubocop +9 -0
- data/gemfiles/Gemfile.test-unit.latest +3 -3
- data/lib/mocha/any_instance_method.rb +2 -0
- data/lib/mocha/any_instance_receiver.rb +20 -0
- data/lib/mocha/api.rb +4 -2
- data/lib/mocha/argument_iterator.rb +5 -5
- data/lib/mocha/backtrace_filter.rb +2 -0
- data/lib/mocha/{block_matcher.rb → block_matchers.rb} +2 -0
- data/lib/mocha/cardinality.rb +2 -2
- data/lib/mocha/central.rb +4 -0
- data/lib/mocha/change_state_side_effect.rb +2 -0
- data/lib/mocha/class_methods.rb +5 -4
- data/lib/mocha/configuration.rb +18 -41
- data/lib/mocha/default_name.rb +15 -0
- data/lib/mocha/default_receiver.rb +13 -0
- data/lib/mocha/deprecation.rb +15 -9
- data/lib/mocha/detection/minitest.rb +2 -0
- data/lib/mocha/detection/test_unit.rb +4 -1
- data/lib/mocha/error_with_filtered_backtrace.rb +2 -0
- data/lib/mocha/exception_raiser.rb +3 -0
- data/lib/mocha/expectation.rb +57 -23
- data/lib/mocha/expectation_error.rb +2 -0
- data/lib/mocha/expectation_error_factory.rb +2 -0
- data/lib/mocha/expectation_list.rb +2 -0
- data/lib/mocha/hooks.rb +2 -0
- data/lib/mocha/impersonating_any_instance_name.rb +13 -0
- data/lib/mocha/impersonating_name.rb +13 -0
- data/lib/mocha/in_state_ordering_constraint.rb +2 -0
- data/lib/mocha/inspect.rb +13 -10
- data/lib/mocha/instance_method.rb +2 -0
- data/lib/mocha/integration/assertion_counter.rb +2 -0
- data/lib/mocha/integration/minitest/adapter.rb +3 -0
- data/lib/mocha/integration/minitest.rb +4 -3
- data/lib/mocha/integration/monkey_patcher.rb +4 -2
- data/lib/mocha/integration/test_unit/adapter.rb +3 -0
- data/lib/mocha/integration/test_unit.rb +4 -3
- data/lib/mocha/invocation.rb +9 -6
- data/lib/mocha/logger.rb +2 -0
- data/lib/mocha/macos_version.rb +2 -0
- data/lib/mocha/method_matcher.rb +2 -0
- data/lib/mocha/minitest.rb +2 -1
- data/lib/mocha/mock.rb +8 -8
- data/lib/mocha/mockery.rb +16 -6
- data/lib/mocha/name.rb +13 -0
- data/lib/mocha/not_initialized_error.rb +2 -0
- data/lib/mocha/object_methods.rb +7 -5
- data/lib/mocha/object_receiver.rb +20 -0
- data/lib/mocha/parameter_matchers/all_of.rb +5 -1
- data/lib/mocha/parameter_matchers/any_of.rb +5 -1
- data/lib/mocha/parameter_matchers/any_parameters.rb +5 -1
- data/lib/mocha/parameter_matchers/anything.rb +5 -1
- data/lib/mocha/parameter_matchers/base.rb +4 -2
- data/lib/mocha/parameter_matchers/equals.rb +5 -1
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +5 -1
- data/lib/mocha/parameter_matchers/has_entries.rb +5 -1
- data/lib/mocha/parameter_matchers/has_entry.rb +6 -1
- data/lib/mocha/parameter_matchers/has_key.rb +6 -1
- data/lib/mocha/parameter_matchers/has_keys.rb +6 -2
- data/lib/mocha/parameter_matchers/has_value.rb +6 -1
- data/lib/mocha/parameter_matchers/includes.rb +8 -7
- data/lib/mocha/parameter_matchers/instance_methods.rb +4 -2
- data/lib/mocha/parameter_matchers/instance_of.rb +5 -1
- data/lib/mocha/parameter_matchers/is_a.rb +5 -1
- data/lib/mocha/parameter_matchers/kind_of.rb +5 -1
- data/lib/mocha/parameter_matchers/not.rb +5 -1
- data/lib/mocha/parameter_matchers/optionally.rb +6 -1
- data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +41 -16
- data/lib/mocha/parameter_matchers/regexp_matches.rb +6 -1
- data/lib/mocha/parameter_matchers/responds_with.rb +5 -1
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +5 -1
- data/lib/mocha/parameter_matchers.rb +2 -0
- data/lib/mocha/parameters_matcher.rb +9 -1
- data/lib/mocha/raised_exception.rb +2 -0
- data/lib/mocha/return_values.rb +2 -0
- data/lib/mocha/ruby_version.rb +3 -0
- data/lib/mocha/sequence.rb +2 -0
- data/lib/mocha/single_return_value.rb +1 -1
- data/lib/mocha/state_machine.rb +2 -0
- data/lib/mocha/stubbed_method.rb +9 -2
- data/lib/mocha/stubbing_error.rb +2 -0
- data/lib/mocha/test_unit.rb +2 -1
- data/lib/mocha/thrower.rb +2 -0
- data/lib/mocha/thrown_object.rb +2 -0
- data/lib/mocha/version.rb +3 -1
- data/lib/mocha/yield_parameters.rb +2 -0
- data/lib/mocha.rb +5 -0
- data/mocha.gemspec +10 -4
- metadata +17 -15
- data/lib/mocha/debug.rb +0 -9
- data/lib/mocha/integration/minitest/exception_translation.rb +0 -14
- data/lib/mocha/is_a.rb +0 -7
- data/lib/mocha/names.rb +0 -43
- data/lib/mocha/receivers.rb +0 -45
data/lib/mocha/sequence.rb
CHANGED
data/lib/mocha/state_machine.rb
CHANGED
data/lib/mocha/stubbed_method.rb
CHANGED
@@ -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.
|
59
|
-
|
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
|
|
data/lib/mocha/stubbing_error.rb
CHANGED
data/lib/mocha/test_unit.rb
CHANGED
data/lib/mocha/thrower.rb
CHANGED
data/lib/mocha/thrown_object.rb
CHANGED
data/lib/mocha/version.rb
CHANGED
data/lib/mocha.rb
CHANGED
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.
|
14
|
+
s.required_ruby_version = '>= 2.2'
|
10
15
|
|
11
16
|
s.authors = ['James Mead']
|
12
|
-
s.description =
|
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.
|
39
|
+
s.add_dependency 'ruby2_keywords', '>= 0.0.5'
|
34
40
|
end
|
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:
|
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:
|
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:
|
28
|
-
|
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/
|
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/
|
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,27 +70,28 @@ 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/
|
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
|
@@ -114,7 +118,6 @@ files:
|
|
114
118
|
- lib/mocha/parameter_matchers/yaml_equivalent.rb
|
115
119
|
- lib/mocha/parameters_matcher.rb
|
116
120
|
- lib/mocha/raised_exception.rb
|
117
|
-
- lib/mocha/receivers.rb
|
118
121
|
- lib/mocha/return_values.rb
|
119
122
|
- lib/mocha/ruby_version.rb
|
120
123
|
- lib/mocha/sequence.rb
|
@@ -139,7 +142,7 @@ metadata:
|
|
139
142
|
funding_uri: https://github.com/sponsors/floehopper
|
140
143
|
homepage_uri: https://mocha.jamesmead.org
|
141
144
|
source_code_uri: https://github.com/freerange/mocha
|
142
|
-
|
145
|
+
rubygems_mfa_required: 'true'
|
143
146
|
rdoc_options: []
|
144
147
|
require_paths:
|
145
148
|
- lib
|
@@ -147,15 +150,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
147
150
|
requirements:
|
148
151
|
- - ">="
|
149
152
|
- !ruby/object:Gem::Version
|
150
|
-
version: '2.
|
153
|
+
version: '2.2'
|
151
154
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
155
|
requirements:
|
153
156
|
- - ">="
|
154
157
|
- !ruby/object:Gem::Version
|
155
158
|
version: '0'
|
156
159
|
requirements: []
|
157
|
-
rubygems_version: 3.
|
158
|
-
signing_key:
|
160
|
+
rubygems_version: 3.6.2
|
159
161
|
specification_version: 4
|
160
162
|
summary: Mocking and stubbing library
|
161
163
|
test_files: []
|
data/lib/mocha/debug.rb
DELETED
@@ -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
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
|
data/lib/mocha/receivers.rb
DELETED
@@ -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
|