mocha 3.0.0.pre.rc.1 → 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.
- checksums.yaml +4 -4
- data/.rubocop.yml +7 -37
- data/.yardopts +2 -0
- data/Gemfile +2 -5
- data/RELEASE.md +42 -0
- data/Rakefile +39 -19
- data/lib/mocha/any_instance_method.rb +4 -4
- data/lib/mocha/api.rb +1 -1
- data/lib/mocha/class_methods.rb +9 -5
- data/lib/mocha/configuration.rb +1 -1
- data/lib/mocha/deprecation.rb +1 -1
- data/lib/mocha/expectation.rb +2 -2
- data/lib/mocha/expectation_list.rb +1 -1
- data/lib/mocha/hooks.rb +4 -4
- data/lib/mocha/ignoring_warning.rb +20 -0
- data/lib/mocha/instance_method.rb +4 -4
- data/lib/mocha/integration/minitest/adapter.rb +4 -3
- data/lib/mocha/integration/minitest.rb +1 -1
- data/lib/mocha/integration/test_unit/adapter.rb +7 -4
- data/lib/mocha/integration/test_unit.rb +1 -1
- data/lib/mocha/integration.rb +5 -0
- data/lib/mocha/mock.rb +8 -4
- data/lib/mocha/mockery.rb +20 -12
- data/lib/mocha/object_methods.rb +13 -1
- data/lib/mocha/parameter_matchers/all_of.rb +24 -22
- data/lib/mocha/parameter_matchers/any_of.rb +30 -28
- data/lib/mocha/parameter_matchers/any_parameters.rb +22 -20
- data/lib/mocha/parameter_matchers/anything.rb +19 -17
- data/lib/mocha/parameter_matchers/{base.rb → base_methods.rb} +6 -4
- data/lib/mocha/parameter_matchers/equals.rb +25 -23
- data/lib/mocha/parameter_matchers/equivalent_uri.rb +28 -24
- data/lib/mocha/parameter_matchers/has_entries.rb +25 -23
- data/lib/mocha/parameter_matchers/has_entry.rb +66 -66
- data/lib/mocha/parameter_matchers/has_key.rb +25 -23
- data/lib/mocha/parameter_matchers/has_keys.rb +25 -23
- data/lib/mocha/parameter_matchers/has_value.rb +25 -23
- data/lib/mocha/parameter_matchers/includes.rb +63 -61
- data/lib/mocha/parameter_matchers/instance_methods.rb +2 -2
- data/lib/mocha/parameter_matchers/instance_of.rb +25 -23
- data/lib/mocha/parameter_matchers/is_a.rb +26 -24
- data/lib/mocha/parameter_matchers/kind_of.rb +25 -23
- data/lib/mocha/parameter_matchers/not.rb +25 -23
- data/lib/mocha/parameter_matchers/optionally.rb +35 -33
- data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +2 -2
- data/lib/mocha/parameter_matchers/regexp_matches.rb +25 -23
- data/lib/mocha/parameter_matchers/responds_with.rb +49 -47
- data/lib/mocha/parameter_matchers/yaml_equivalent.rb +24 -22
- data/lib/mocha/parameter_matchers.rb +5 -2
- data/lib/mocha/state_machine.rb +1 -1
- data/lib/mocha/stubbed_method.rb +7 -7
- data/lib/mocha/version.rb +1 -1
- data/lib/mocha.rb +15 -0
- metadata +9 -4
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'mocha/parameter_matchers/
|
|
3
|
+
require 'mocha/parameter_matchers/base_methods'
|
|
4
4
|
|
|
5
5
|
module Mocha
|
|
6
6
|
module ParameterMatchers
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
7
|
+
module Methods
|
|
8
|
+
# Matches any +Object+ that is a kind of +klass+.
|
|
9
|
+
#
|
|
10
|
+
# @param [Class] klass expected class.
|
|
11
|
+
# @return [KindOf] parameter matcher.
|
|
12
|
+
#
|
|
13
|
+
# @see Expectation#with
|
|
14
|
+
# @see Kernel#kind_of?
|
|
15
|
+
#
|
|
16
|
+
# @example Actual parameter is a kind of +Integer+.
|
|
17
|
+
# object = mock()
|
|
18
|
+
# object.expects(:method_1).with(kind_of(Integer))
|
|
19
|
+
# object.method_1(99)
|
|
20
|
+
# # no error raised
|
|
21
|
+
#
|
|
22
|
+
# @example Actual parameter is not a kind of +Integer+.
|
|
23
|
+
# object = mock()
|
|
24
|
+
# object.expects(:method_1).with(kind_of(Integer))
|
|
25
|
+
# object.method_1('string')
|
|
26
|
+
# # error raised, because method_1 was not called with a kind of Integer
|
|
27
|
+
def kind_of(klass)
|
|
28
|
+
KindOf.new(klass)
|
|
29
|
+
end
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
# Parameter matcher which matches when actual parameter is a kind of specified class.
|
|
31
33
|
class KindOf
|
|
32
|
-
include
|
|
34
|
+
include BaseMethods
|
|
33
35
|
|
|
34
36
|
# @private
|
|
35
37
|
def initialize(klass)
|
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'mocha/parameter_matchers/
|
|
3
|
+
require 'mocha/parameter_matchers/base_methods'
|
|
4
4
|
|
|
5
5
|
module Mocha
|
|
6
6
|
module ParameterMatchers
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
Not
|
|
7
|
+
module Methods
|
|
8
|
+
# Matches if +matcher+ does *not* match.
|
|
9
|
+
#
|
|
10
|
+
# @param [BaseMethods] matcher matcher whose logic to invert.
|
|
11
|
+
# @return [Not] parameter matcher.
|
|
12
|
+
#
|
|
13
|
+
# @see Expectation#with
|
|
14
|
+
#
|
|
15
|
+
# @example Actual parameter does not include the value +1+.
|
|
16
|
+
# object = mock()
|
|
17
|
+
# object.expects(:method_1).with(Not(includes(1)))
|
|
18
|
+
# object.method_1([0, 2, 3])
|
|
19
|
+
# # no error raised
|
|
20
|
+
#
|
|
21
|
+
# @example Actual parameter does include the value +1+.
|
|
22
|
+
# object = mock()
|
|
23
|
+
# object.expects(:method_1).with(Not(includes(1)))
|
|
24
|
+
# object.method_1([0, 1, 2, 3])
|
|
25
|
+
# # error raised, because method_1 was not called with object not including 1
|
|
26
|
+
#
|
|
27
|
+
def Not(matcher) # rubocop:disable Naming/MethodName
|
|
28
|
+
Not.new(matcher)
|
|
29
|
+
end
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
# Parameter matcher which inverts the logic of the specified matcher using a logical NOT operation.
|
|
31
33
|
class Not
|
|
32
|
-
include
|
|
34
|
+
include BaseMethods
|
|
33
35
|
|
|
34
36
|
# @private
|
|
35
37
|
def initialize(matcher)
|
|
@@ -2,43 +2,45 @@
|
|
|
2
2
|
|
|
3
3
|
module Mocha
|
|
4
4
|
module ParameterMatchers
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
5
|
+
module Methods
|
|
6
|
+
# Matches optional parameters if available.
|
|
7
|
+
#
|
|
8
|
+
# @param [*Array<BaseMethods>] matchers matchers for optional parameters.
|
|
9
|
+
# @return [Optionally] parameter matcher.
|
|
10
|
+
#
|
|
11
|
+
# @see Expectation#with
|
|
12
|
+
#
|
|
13
|
+
# @example Only the two required parameters are supplied and they both match their expected value.
|
|
14
|
+
# object = mock()
|
|
15
|
+
# object.expects(:method_1).with(1, 2, optionally(3, 4))
|
|
16
|
+
# object.method_1(1, 2)
|
|
17
|
+
# # no error raised
|
|
18
|
+
#
|
|
19
|
+
# @example Both required parameters and one of the optional parameters are supplied and they all match their expected value.
|
|
20
|
+
# object = mock()
|
|
21
|
+
# object.expects(:method_1).with(1, 2, optionally(3, 4))
|
|
22
|
+
# object.method_1(1, 2, 3)
|
|
23
|
+
# # no error raised
|
|
24
|
+
#
|
|
25
|
+
# @example Both required parameters and both of the optional parameters are supplied and they all match their expected value.
|
|
26
|
+
# object = mock()
|
|
27
|
+
# object.expects(:method_1).with(1, 2, optionally(3, 4))
|
|
28
|
+
# object.method_1(1, 2, 3, 4)
|
|
29
|
+
# # no error raised
|
|
30
|
+
#
|
|
31
|
+
# @example One of the actual optional parameters does not match the expected value.
|
|
32
|
+
# object = mock()
|
|
33
|
+
# object.expects(:method_1).with(1, 2, optionally(3, 4))
|
|
34
|
+
# object.method_1(1, 2, 3, 5)
|
|
35
|
+
# # error raised, because optional parameters did not match
|
|
36
|
+
def optionally(*matchers)
|
|
37
|
+
Optionally.new(*matchers)
|
|
38
|
+
end
|
|
37
39
|
end
|
|
38
40
|
|
|
39
41
|
# Parameter matcher which allows optional parameters to be specified.
|
|
40
42
|
class Optionally
|
|
41
|
-
include
|
|
43
|
+
include BaseMethods
|
|
42
44
|
|
|
43
45
|
# @private
|
|
44
46
|
def initialize(*parameters)
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
require 'mocha/configuration'
|
|
4
4
|
require 'mocha/deprecation'
|
|
5
5
|
require 'mocha/ruby_version'
|
|
6
|
-
require 'mocha/parameter_matchers/
|
|
6
|
+
require 'mocha/parameter_matchers/base_methods'
|
|
7
7
|
require 'mocha/parameter_matchers/has_entries'
|
|
8
8
|
|
|
9
9
|
module Mocha
|
|
10
10
|
module ParameterMatchers
|
|
11
11
|
# @private
|
|
12
12
|
class PositionalOrKeywordHash
|
|
13
|
-
include
|
|
13
|
+
include BaseMethods
|
|
14
14
|
|
|
15
15
|
def initialize(expected_value, expectation, last_expected_value)
|
|
16
16
|
@expected_value = expected_value
|
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'mocha/parameter_matchers/
|
|
3
|
+
require 'mocha/parameter_matchers/base_methods'
|
|
4
4
|
|
|
5
5
|
module Mocha
|
|
6
6
|
module ParameterMatchers
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
7
|
+
module Methods
|
|
8
|
+
# Matches any object that matches +regexp+.
|
|
9
|
+
#
|
|
10
|
+
# @param [Regexp] regexp regular expression to match.
|
|
11
|
+
# @return [RegexpMatches] parameter matcher.
|
|
12
|
+
#
|
|
13
|
+
# @see Expectation#with
|
|
14
|
+
#
|
|
15
|
+
# @example Actual parameter is matched by specified regular expression.
|
|
16
|
+
# object = mock()
|
|
17
|
+
# object.expects(:method_1).with(regexp_matches(/e/))
|
|
18
|
+
# object.method_1('hello')
|
|
19
|
+
# # no error raised
|
|
20
|
+
#
|
|
21
|
+
# @example Actual parameter is not matched by specified regular expression.
|
|
22
|
+
# object = mock()
|
|
23
|
+
# object.expects(:method_1).with(regexp_matches(/a/))
|
|
24
|
+
# object.method_1('hello')
|
|
25
|
+
# # error raised, because method_1 was not called with a parameter that matched the
|
|
26
|
+
# # regular expression
|
|
27
|
+
def regexp_matches(regexp)
|
|
28
|
+
RegexpMatches.new(regexp)
|
|
29
|
+
end
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
# Parameter matcher which matches if specified regular expression matches actual paramter.
|
|
31
33
|
class RegexpMatches
|
|
32
|
-
include
|
|
34
|
+
include BaseMethods
|
|
33
35
|
|
|
34
36
|
# @private
|
|
35
37
|
def initialize(regexp)
|
|
@@ -1,63 +1,65 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'mocha/parameter_matchers/
|
|
3
|
+
require 'mocha/parameter_matchers/base_methods'
|
|
4
4
|
require 'mocha/parameter_matchers/all_of'
|
|
5
5
|
require 'yaml'
|
|
6
6
|
|
|
7
7
|
module Mocha
|
|
8
8
|
module ParameterMatchers
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
9
|
+
module Methods
|
|
10
|
+
# @overload def responds_with(message, result)
|
|
11
|
+
# Matches any object that responds to +message+ with +result+. To put it another way, it tests the quack, not the duck.
|
|
12
|
+
# @param [Symbol] message method to invoke.
|
|
13
|
+
# @param [Object] result expected result of sending +message+.
|
|
14
|
+
# @overload def responds_with(messages_vs_results)
|
|
15
|
+
# Matches any object that responds to all the messages with the corresponding results as specified by +messages_vs_results+.
|
|
16
|
+
# @param [Hash<Symbol,Object>] messages_vs_results +Hash+ of messages vs results.
|
|
17
|
+
# @raise [ArgumentError] if +messages_vs_results+ does not contain at least one entry.
|
|
18
|
+
#
|
|
19
|
+
# @return [RespondsWith] parameter matcher.
|
|
20
|
+
#
|
|
21
|
+
# @see Expectation#with
|
|
22
|
+
#
|
|
23
|
+
# @example Actual parameter responds with "FOO" when :upcase is invoked.
|
|
24
|
+
# object = mock()
|
|
25
|
+
# object.expects(:method_1).with(responds_with(:upcase, "FOO"))
|
|
26
|
+
# object.method_1("foo")
|
|
27
|
+
# # no error raised, because "foo".upcase == "FOO"
|
|
28
|
+
#
|
|
29
|
+
# @example Actual parameter does not respond with "FOO" when :upcase is invoked.
|
|
30
|
+
# object = mock()
|
|
31
|
+
# object.expects(:method_1).with(responds_with(:upcase, "BAR"))
|
|
32
|
+
# object.method_1("foo")
|
|
33
|
+
# # error raised, because "foo".upcase != "BAR"
|
|
34
|
+
#
|
|
35
|
+
# @example Actual parameter responds with "FOO" when :upcase is invoked and "oof" when :reverse is invoked.
|
|
36
|
+
# object = mock()
|
|
37
|
+
# object.expects(:method_1).with(responds_with(upcase: "FOO", reverse: "oof"))
|
|
38
|
+
# object.method_1("foo")
|
|
39
|
+
# # no error raised, because "foo".upcase == "FOO" and "foo".reverse == "oof"
|
|
40
|
+
def responds_with(*options)
|
|
41
|
+
case options.length
|
|
42
|
+
when 0
|
|
43
|
+
raise ArgumentError, 'No arguments. Expecting at least one.'
|
|
44
|
+
when 1
|
|
45
|
+
option = options.first
|
|
46
|
+
raise ArgumentError, 'Argument is not a Hash.' unless option.is_a?(Hash)
|
|
47
|
+
raise ArgumentError, 'Argument has no entries.' if option.empty?
|
|
47
48
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
49
|
+
matchers = option.map { |message, result| RespondsWith.new(message, result) }
|
|
50
|
+
AllOf.new(*matchers)
|
|
51
|
+
when 2
|
|
52
|
+
message, result = options
|
|
53
|
+
RespondsWith.new(message, result)
|
|
54
|
+
else
|
|
55
|
+
raise ArgumentError, 'Too many arguments; use either a single argument (must be a Hash) or two arguments (a message and a result).'
|
|
56
|
+
end
|
|
55
57
|
end
|
|
56
58
|
end
|
|
57
59
|
|
|
58
60
|
# Parameter matcher which matches if actual parameter returns expected result when specified method is invoked.
|
|
59
61
|
class RespondsWith
|
|
60
|
-
include
|
|
62
|
+
include BaseMethods
|
|
61
63
|
|
|
62
64
|
# @private
|
|
63
65
|
def initialize(message, result)
|
|
@@ -1,35 +1,37 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'mocha/parameter_matchers/
|
|
3
|
+
require 'mocha/parameter_matchers/base_methods'
|
|
4
4
|
require 'yaml'
|
|
5
5
|
|
|
6
6
|
module Mocha
|
|
7
7
|
module ParameterMatchers
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
8
|
+
module Methods
|
|
9
|
+
# Matches any YAML that represents the specified +object+
|
|
10
|
+
#
|
|
11
|
+
# @param [Object] object object whose YAML to compare.
|
|
12
|
+
# @return [YamlEquivalent] parameter matcher.
|
|
13
|
+
#
|
|
14
|
+
# @see Expectation#with
|
|
15
|
+
#
|
|
16
|
+
# @example Actual parameter is YAML equivalent of specified +object+.
|
|
17
|
+
# object = mock()
|
|
18
|
+
# object.expects(:method_1).with(yaml_equivalent(1, 2, 3))
|
|
19
|
+
# object.method_1("--- \n- 1\n- 2\n- 3\n")
|
|
20
|
+
# # no error raised
|
|
21
|
+
#
|
|
22
|
+
# @example Actual parameter is not YAML equivalent of specified +object+.
|
|
23
|
+
# object = mock()
|
|
24
|
+
# object.expects(:method_1).with(yaml_equivalent(1, 2, 3))
|
|
25
|
+
# object.method_1("--- \n- 1\n- 2\n")
|
|
26
|
+
# # error raised, because method_1 was not called with YAML representing the specified Array
|
|
27
|
+
def yaml_equivalent(object)
|
|
28
|
+
YamlEquivalent.new(object)
|
|
29
|
+
end
|
|
28
30
|
end
|
|
29
31
|
|
|
30
32
|
# Parameter matcher which matches if actual parameter is YAML equivalent of specified object.
|
|
31
33
|
class YamlEquivalent
|
|
32
|
-
include
|
|
34
|
+
include BaseMethods
|
|
33
35
|
|
|
34
36
|
# @private
|
|
35
37
|
def initialize(object)
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module Mocha
|
|
4
|
-
#
|
|
5
|
-
module ParameterMatchers
|
|
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}.
|
|
5
|
+
module ParameterMatchers
|
|
6
|
+
# 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.
|
|
7
|
+
module Methods; end
|
|
8
|
+
end
|
|
6
9
|
end
|
|
7
10
|
|
|
8
11
|
require 'mocha/parameter_matchers/instance_methods'
|
data/lib/mocha/state_machine.rb
CHANGED
|
@@ -83,7 +83,7 @@ module Mocha
|
|
|
83
83
|
#
|
|
84
84
|
# @param [String] unexpected_state_name name of unexpected state.
|
|
85
85
|
# @return [StatePredicate] state predicate which, when queried, will indicate whether the {StateMachine} is *not* in the state specified by +unexpected_state_name+.
|
|
86
|
-
def is_not(unexpected_state_name) # rubocop:disable Naming/
|
|
86
|
+
def is_not(unexpected_state_name) # rubocop:disable Naming/PredicatePrefix
|
|
87
87
|
StatePredicate.new(self, unexpected_state_name, 'is not') { |current, given| current != given }
|
|
88
88
|
end
|
|
89
89
|
|
data/lib/mocha/stubbed_method.rb
CHANGED
|
@@ -7,10 +7,10 @@ module Mocha
|
|
|
7
7
|
class StubbedMethod
|
|
8
8
|
PrependedModule = Class.new(Module)
|
|
9
9
|
|
|
10
|
-
attr_reader :
|
|
10
|
+
attr_reader :stubba_object, :method_name
|
|
11
11
|
|
|
12
|
-
def initialize(
|
|
13
|
-
@
|
|
12
|
+
def initialize(stubba_object, method_name)
|
|
13
|
+
@stubba_object = stubba_object
|
|
14
14
|
@original_method = nil
|
|
15
15
|
@original_visibility = nil
|
|
16
16
|
@method_name = method_name.to_sym
|
|
@@ -30,11 +30,11 @@ module Mocha
|
|
|
30
30
|
end
|
|
31
31
|
|
|
32
32
|
def mock
|
|
33
|
-
|
|
33
|
+
stubbee.mocha
|
|
34
34
|
end
|
|
35
35
|
|
|
36
36
|
def reset_mocha
|
|
37
|
-
|
|
37
|
+
stubbee.reset_mocha
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
def hide_original_method
|
|
@@ -61,14 +61,14 @@ module Mocha
|
|
|
61
61
|
def matches?(other)
|
|
62
62
|
return false unless other.instance_of?(self.class)
|
|
63
63
|
|
|
64
|
-
(
|
|
64
|
+
(stubba_object.object_id == other.stubba_object.object_id) && # rubocop:disable Lint/IdentityComparison
|
|
65
65
|
(method_name == other.method_name)
|
|
66
66
|
end
|
|
67
67
|
|
|
68
68
|
alias_method :==, :eql?
|
|
69
69
|
|
|
70
70
|
def to_s
|
|
71
|
-
"#{
|
|
71
|
+
"#{stubba_object}.#{method_name}"
|
|
72
72
|
end
|
|
73
73
|
|
|
74
74
|
private
|
data/lib/mocha/version.rb
CHANGED
data/lib/mocha.rb
CHANGED
|
@@ -2,5 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
require 'mocha/version'
|
|
4
4
|
|
|
5
|
+
# Mocha's top level namespace, which also provides the ability to {.configure configure} Mocha's behavior.
|
|
6
|
+
#
|
|
7
|
+
# Methods in the {API} are directly available in +Test::Unit::TestCase+, +Minitest::Unit::TestCase+.
|
|
8
|
+
#
|
|
9
|
+
# The mock creation methods are {API#mock mock}, {API#stub stub} and {API#stub_everything stub_everything}, all of which return a {Mock}
|
|
10
|
+
#
|
|
11
|
+
# A {Mock} {Mock#expects expects} or {Mock#stubs stubs} a method, which sets up (returns) an {Expectation}.
|
|
12
|
+
#
|
|
13
|
+
# An {Expectation} can be further qualified through its {Expectation fluent interface}.
|
|
14
|
+
#
|
|
15
|
+
# {ParameterMatchers} for {Expectation#with} restrict the parameter values which will match the {Expectation}.
|
|
16
|
+
#
|
|
17
|
+
# Adapters in {Integration} provide built-in support for +Minitest+ and +Test::Unit+.
|
|
18
|
+
#
|
|
19
|
+
# Integration {Hooks} enable support for other test frameworks.
|
|
5
20
|
module Mocha
|
|
6
21
|
end
|
metadata
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mocha
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 3.0.0.pre.rc.
|
|
4
|
+
version: 3.0.0.pre.rc.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- James Mead
|
|
8
|
+
autorequire:
|
|
8
9
|
bindir: bin
|
|
9
10
|
cert_chain: []
|
|
10
|
-
date: 2025-
|
|
11
|
+
date: 2025-11-11 00:00:00.000000000 Z
|
|
11
12
|
dependencies:
|
|
12
13
|
- !ruby/object:Gem::Dependency
|
|
13
14
|
name: ruby2_keywords
|
|
@@ -70,11 +71,13 @@ files:
|
|
|
70
71
|
- lib/mocha/expectation_error_factory.rb
|
|
71
72
|
- lib/mocha/expectation_list.rb
|
|
72
73
|
- lib/mocha/hooks.rb
|
|
74
|
+
- lib/mocha/ignoring_warning.rb
|
|
73
75
|
- lib/mocha/impersonating_any_instance_name.rb
|
|
74
76
|
- lib/mocha/impersonating_name.rb
|
|
75
77
|
- lib/mocha/in_state_ordering_constraint.rb
|
|
76
78
|
- lib/mocha/inspect.rb
|
|
77
79
|
- lib/mocha/instance_method.rb
|
|
80
|
+
- lib/mocha/integration.rb
|
|
78
81
|
- lib/mocha/integration/assertion_counter.rb
|
|
79
82
|
- lib/mocha/integration/minitest.rb
|
|
80
83
|
- lib/mocha/integration/minitest/adapter.rb
|
|
@@ -97,7 +100,7 @@ files:
|
|
|
97
100
|
- lib/mocha/parameter_matchers/any_of.rb
|
|
98
101
|
- lib/mocha/parameter_matchers/any_parameters.rb
|
|
99
102
|
- lib/mocha/parameter_matchers/anything.rb
|
|
100
|
-
- lib/mocha/parameter_matchers/
|
|
103
|
+
- lib/mocha/parameter_matchers/base_methods.rb
|
|
101
104
|
- lib/mocha/parameter_matchers/equals.rb
|
|
102
105
|
- lib/mocha/parameter_matchers/equivalent_uri.rb
|
|
103
106
|
- lib/mocha/parameter_matchers/has_entries.rb
|
|
@@ -143,6 +146,7 @@ metadata:
|
|
|
143
146
|
homepage_uri: https://mocha.jamesmead.org
|
|
144
147
|
source_code_uri: https://github.com/freerange/mocha
|
|
145
148
|
rubygems_mfa_required: 'true'
|
|
149
|
+
post_install_message:
|
|
146
150
|
rdoc_options: []
|
|
147
151
|
require_paths:
|
|
148
152
|
- lib
|
|
@@ -157,7 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
157
161
|
- !ruby/object:Gem::Version
|
|
158
162
|
version: '0'
|
|
159
163
|
requirements: []
|
|
160
|
-
rubygems_version: 3.
|
|
164
|
+
rubygems_version: 3.5.3
|
|
165
|
+
signing_key:
|
|
161
166
|
specification_version: 4
|
|
162
167
|
summary: Mocking and stubbing library
|
|
163
168
|
test_files: []
|