mocha 2.1.0 → 2.7.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -1
- data/.yardopts +1 -1
- data/Gemfile +6 -1
- data/README.md +13 -18
- data/RELEASE.md +199 -0
- data/Rakefile +9 -9
- data/lib/mocha/api.rb +25 -6
- data/lib/mocha/cardinality.rb +4 -0
- data/lib/mocha/configuration.rb +7 -0
- data/lib/mocha/detection/{mini_test.rb → minitest.rb} +5 -5
- data/lib/mocha/detection/test_unit.rb +2 -2
- data/lib/mocha/expectation.rb +38 -6
- data/lib/mocha/expectation_error_factory.rb +2 -2
- data/lib/mocha/expectation_list.rb +8 -6
- data/lib/mocha/hooks.rb +10 -4
- data/lib/mocha/inspect.rb +13 -2
- data/lib/mocha/integration/{mini_test → minitest}/adapter.rb +20 -5
- data/lib/mocha/integration/{mini_test → minitest}/exception_translation.rb +2 -2
- data/lib/mocha/integration/minitest.rb +28 -0
- data/lib/mocha/integration/test_unit/adapter.rb +5 -0
- data/lib/mocha/minitest.rb +3 -3
- data/lib/mocha/mock.rb +37 -14
- data/lib/mocha/mockery.rb +13 -9
- data/lib/mocha/object_methods.rb +2 -2
- data/lib/mocha/parameter_matchers/base.rb +4 -9
- data/lib/mocha/parameter_matchers/has_entries.rb +7 -2
- data/lib/mocha/parameter_matchers/includes.rb +3 -3
- data/lib/mocha/parameter_matchers/instance_methods.rb +9 -10
- data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +3 -1
- data/lib/mocha/parameter_matchers/responds_with.rb +32 -5
- data/lib/mocha/parameters_matcher.rb +8 -4
- data/lib/mocha/ruby_version.rb +1 -0
- data/lib/mocha/version.rb +1 -1
- data/mocha.gemspec +9 -1
- metadata +15 -9
- data/lib/mocha/integration/mini_test.rb +0 -28
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
require 'mocha/parameter_matchers/base'
|
|
2
|
+
require 'mocha/parameter_matchers/all_of'
|
|
2
3
|
require 'yaml'
|
|
3
4
|
|
|
4
5
|
module Mocha
|
|
5
6
|
module ParameterMatchers
|
|
6
|
-
#
|
|
7
|
+
# @overload def responds_with(message, result)
|
|
8
|
+
# Matches any object that responds to +message+ with +result+. To put it another way, it tests the quack, not the duck.
|
|
9
|
+
# @param [Symbol] message method to invoke.
|
|
10
|
+
# @param [Object] result expected result of sending +message+.
|
|
11
|
+
# @overload def responds_with(messages_vs_results)
|
|
12
|
+
# Matches any object that responds to all the messages with the corresponding results as specified by +messages_vs_results+.
|
|
13
|
+
# @param [Hash<Symbol,Object>] messages_vs_results +Hash+ of messages vs results.
|
|
14
|
+
# @raise [ArgumentError] if +messages_vs_results+ does not contain at least one entry.
|
|
7
15
|
#
|
|
8
|
-
# @param [Symbol] message method to invoke.
|
|
9
|
-
# @param [Object] result expected result of sending +message+.
|
|
10
16
|
# @return [RespondsWith] parameter matcher.
|
|
11
17
|
#
|
|
12
18
|
# @see Expectation#with
|
|
@@ -22,8 +28,29 @@ module Mocha
|
|
|
22
28
|
# object.expects(:method_1).with(responds_with(:upcase, "BAR"))
|
|
23
29
|
# object.method_1("foo")
|
|
24
30
|
# # error raised, because "foo".upcase != "BAR"
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
#
|
|
32
|
+
# @example Actual parameter responds with "FOO" when :upcase is invoked and "oof" when :reverse is invoked.
|
|
33
|
+
# object = mock()
|
|
34
|
+
# object.expects(:method_1).with(responds_with(upcase: "FOO", reverse: "oof"))
|
|
35
|
+
# object.method_1("foo")
|
|
36
|
+
# # no error raised, because "foo".upcase == "FOO" and "foo".reverse == "oof"
|
|
37
|
+
def responds_with(*options)
|
|
38
|
+
case options.length
|
|
39
|
+
when 0
|
|
40
|
+
raise ArgumentError, 'No arguments. Expecting at least one.'
|
|
41
|
+
when 1
|
|
42
|
+
option = options.first
|
|
43
|
+
raise ArgumentError, 'Argument is not a Hash.' unless option.is_a?(Hash)
|
|
44
|
+
raise ArgumentError, 'Argument has no entries.' if option.empty?
|
|
45
|
+
|
|
46
|
+
matchers = option.map { |message, result| RespondsWith.new(message, result) }
|
|
47
|
+
AllOf.new(*matchers)
|
|
48
|
+
when 2
|
|
49
|
+
message, result = options
|
|
50
|
+
RespondsWith.new(message, result)
|
|
51
|
+
else
|
|
52
|
+
raise ArgumentError, 'Too many arguments; use either a single argument (must be a Hash) or two arguments (a message and a result).'
|
|
53
|
+
end
|
|
27
54
|
end
|
|
28
55
|
|
|
29
56
|
# Parameter matcher which matches if actual parameter returns expected result when specified method is invoked.
|
|
@@ -22,13 +22,17 @@ module Mocha
|
|
|
22
22
|
end
|
|
23
23
|
|
|
24
24
|
def mocha_inspect
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
if @matching_block
|
|
26
|
+
'(arguments_accepted_by_custom_matching_block)'
|
|
27
|
+
else
|
|
28
|
+
signature = matchers.mocha_inspect
|
|
29
|
+
signature = signature.gsub(/^\[|\]$/, '')
|
|
30
|
+
"(#{signature})"
|
|
31
|
+
end
|
|
28
32
|
end
|
|
29
33
|
|
|
30
34
|
def matchers
|
|
31
|
-
@expected_parameters.map { |p| p.to_matcher(@expectation) }
|
|
35
|
+
@expected_parameters.map { |p| p.to_matcher(expectation: @expectation, top_level: true) }
|
|
32
36
|
end
|
|
33
37
|
end
|
|
34
38
|
end
|
data/lib/mocha/ruby_version.rb
CHANGED
data/lib/mocha/version.rb
CHANGED
data/mocha.gemspec
CHANGED
|
@@ -6,7 +6,7 @@ Gem::Specification.new do |s|
|
|
|
6
6
|
s.name = 'mocha'
|
|
7
7
|
s.version = Mocha::VERSION
|
|
8
8
|
s.licenses = ['MIT', 'BSD-2-Clause']
|
|
9
|
-
s.required_ruby_version = '>= 2.
|
|
9
|
+
s.required_ruby_version = '>= 2.1'
|
|
10
10
|
|
|
11
11
|
s.authors = ['James Mead']
|
|
12
12
|
s.description = 'Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes.'
|
|
@@ -21,6 +21,14 @@ Gem::Specification.new do |s|
|
|
|
21
21
|
s.homepage = 'https://mocha.jamesmead.org'
|
|
22
22
|
s.require_paths = ['lib']
|
|
23
23
|
s.summary = 'Mocking and stubbing library'
|
|
24
|
+
s.metadata = {
|
|
25
|
+
'bug_tracker_uri' => 'https://github.com/freerange/mocha/issues',
|
|
26
|
+
'changelog_uri' => 'https://github.com/freerange/mocha/blob/main/RELEASE.md',
|
|
27
|
+
'documentation_uri' => 'https://mocha.jamesmead.org/',
|
|
28
|
+
'funding_uri' => 'https://github.com/sponsors/floehopper',
|
|
29
|
+
'homepage_uri' => s.homepage,
|
|
30
|
+
'source_code_uri' => 'https://github.com/freerange/mocha'
|
|
31
|
+
}
|
|
24
32
|
|
|
25
33
|
s.add_runtime_dependency 'ruby2_keywords', '>= 0.0.5'
|
|
26
34
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mocha
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.1
|
|
4
|
+
version: 2.7.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Mead
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2024-12-09 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: ruby2_keywords
|
|
@@ -58,7 +58,7 @@ files:
|
|
|
58
58
|
- lib/mocha/configuration.rb
|
|
59
59
|
- lib/mocha/debug.rb
|
|
60
60
|
- lib/mocha/deprecation.rb
|
|
61
|
-
- lib/mocha/detection/
|
|
61
|
+
- lib/mocha/detection/minitest.rb
|
|
62
62
|
- lib/mocha/detection/test_unit.rb
|
|
63
63
|
- lib/mocha/error_with_filtered_backtrace.rb
|
|
64
64
|
- lib/mocha/exception_raiser.rb
|
|
@@ -71,9 +71,9 @@ files:
|
|
|
71
71
|
- lib/mocha/inspect.rb
|
|
72
72
|
- lib/mocha/instance_method.rb
|
|
73
73
|
- lib/mocha/integration/assertion_counter.rb
|
|
74
|
-
- lib/mocha/integration/
|
|
75
|
-
- lib/mocha/integration/
|
|
76
|
-
- lib/mocha/integration/
|
|
74
|
+
- lib/mocha/integration/minitest.rb
|
|
75
|
+
- lib/mocha/integration/minitest/adapter.rb
|
|
76
|
+
- lib/mocha/integration/minitest/exception_translation.rb
|
|
77
77
|
- lib/mocha/integration/monkey_patcher.rb
|
|
78
78
|
- lib/mocha/integration/test_unit.rb
|
|
79
79
|
- lib/mocha/integration/test_unit/adapter.rb
|
|
@@ -132,7 +132,13 @@ homepage: https://mocha.jamesmead.org
|
|
|
132
132
|
licenses:
|
|
133
133
|
- MIT
|
|
134
134
|
- BSD-2-Clause
|
|
135
|
-
metadata:
|
|
135
|
+
metadata:
|
|
136
|
+
bug_tracker_uri: https://github.com/freerange/mocha/issues
|
|
137
|
+
changelog_uri: https://github.com/freerange/mocha/blob/main/RELEASE.md
|
|
138
|
+
documentation_uri: https://mocha.jamesmead.org/
|
|
139
|
+
funding_uri: https://github.com/sponsors/floehopper
|
|
140
|
+
homepage_uri: https://mocha.jamesmead.org
|
|
141
|
+
source_code_uri: https://github.com/freerange/mocha
|
|
136
142
|
post_install_message:
|
|
137
143
|
rdoc_options: []
|
|
138
144
|
require_paths:
|
|
@@ -141,14 +147,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
141
147
|
requirements:
|
|
142
148
|
- - ">="
|
|
143
149
|
- !ruby/object:Gem::Version
|
|
144
|
-
version: '2.
|
|
150
|
+
version: '2.1'
|
|
145
151
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
146
152
|
requirements:
|
|
147
153
|
- - ">="
|
|
148
154
|
- !ruby/object:Gem::Version
|
|
149
155
|
version: '0'
|
|
150
156
|
requirements: []
|
|
151
|
-
rubygems_version: 3.
|
|
157
|
+
rubygems_version: 3.5.22
|
|
152
158
|
signing_key:
|
|
153
159
|
specification_version: 4
|
|
154
160
|
summary: Mocking and stubbing library
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
require 'mocha/debug'
|
|
2
|
-
require 'mocha/detection/mini_test'
|
|
3
|
-
require 'mocha/integration/mini_test/adapter'
|
|
4
|
-
|
|
5
|
-
module Mocha
|
|
6
|
-
module Integration
|
|
7
|
-
module MiniTest
|
|
8
|
-
def self.activate
|
|
9
|
-
target = Detection::MiniTest.testcase
|
|
10
|
-
return false unless target
|
|
11
|
-
|
|
12
|
-
mini_test_version = Gem::Version.new(Detection::MiniTest.version)
|
|
13
|
-
Debug.puts "Detected MiniTest version: #{mini_test_version}"
|
|
14
|
-
|
|
15
|
-
unless MiniTest::Adapter.applicable_to?(mini_test_version)
|
|
16
|
-
raise 'Versions of minitest earlier than v3.3.0 are not supported.'
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
unless target < MiniTest::Adapter
|
|
20
|
-
Debug.puts "Applying #{MiniTest::Adapter.description}"
|
|
21
|
-
target.send(:include, MiniTest::Adapter)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
true
|
|
25
|
-
end
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|