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.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +7 -37
  3. data/.yardopts +2 -0
  4. data/Gemfile +2 -5
  5. data/RELEASE.md +42 -0
  6. data/Rakefile +39 -19
  7. data/lib/mocha/any_instance_method.rb +4 -4
  8. data/lib/mocha/api.rb +1 -1
  9. data/lib/mocha/class_methods.rb +9 -5
  10. data/lib/mocha/configuration.rb +1 -1
  11. data/lib/mocha/deprecation.rb +1 -1
  12. data/lib/mocha/expectation.rb +2 -2
  13. data/lib/mocha/expectation_list.rb +1 -1
  14. data/lib/mocha/hooks.rb +4 -4
  15. data/lib/mocha/ignoring_warning.rb +20 -0
  16. data/lib/mocha/instance_method.rb +4 -4
  17. data/lib/mocha/integration/minitest/adapter.rb +4 -3
  18. data/lib/mocha/integration/minitest.rb +1 -1
  19. data/lib/mocha/integration/test_unit/adapter.rb +7 -4
  20. data/lib/mocha/integration/test_unit.rb +1 -1
  21. data/lib/mocha/integration.rb +5 -0
  22. data/lib/mocha/mock.rb +8 -4
  23. data/lib/mocha/mockery.rb +20 -12
  24. data/lib/mocha/object_methods.rb +13 -1
  25. data/lib/mocha/parameter_matchers/all_of.rb +24 -22
  26. data/lib/mocha/parameter_matchers/any_of.rb +30 -28
  27. data/lib/mocha/parameter_matchers/any_parameters.rb +22 -20
  28. data/lib/mocha/parameter_matchers/anything.rb +19 -17
  29. data/lib/mocha/parameter_matchers/{base.rb → base_methods.rb} +6 -4
  30. data/lib/mocha/parameter_matchers/equals.rb +25 -23
  31. data/lib/mocha/parameter_matchers/equivalent_uri.rb +28 -24
  32. data/lib/mocha/parameter_matchers/has_entries.rb +25 -23
  33. data/lib/mocha/parameter_matchers/has_entry.rb +66 -66
  34. data/lib/mocha/parameter_matchers/has_key.rb +25 -23
  35. data/lib/mocha/parameter_matchers/has_keys.rb +25 -23
  36. data/lib/mocha/parameter_matchers/has_value.rb +25 -23
  37. data/lib/mocha/parameter_matchers/includes.rb +63 -61
  38. data/lib/mocha/parameter_matchers/instance_methods.rb +2 -2
  39. data/lib/mocha/parameter_matchers/instance_of.rb +25 -23
  40. data/lib/mocha/parameter_matchers/is_a.rb +26 -24
  41. data/lib/mocha/parameter_matchers/kind_of.rb +25 -23
  42. data/lib/mocha/parameter_matchers/not.rb +25 -23
  43. data/lib/mocha/parameter_matchers/optionally.rb +35 -33
  44. data/lib/mocha/parameter_matchers/positional_or_keyword_hash.rb +2 -2
  45. data/lib/mocha/parameter_matchers/regexp_matches.rb +25 -23
  46. data/lib/mocha/parameter_matchers/responds_with.rb +49 -47
  47. data/lib/mocha/parameter_matchers/yaml_equivalent.rb +24 -22
  48. data/lib/mocha/parameter_matchers.rb +5 -2
  49. data/lib/mocha/state_machine.rb +1 -1
  50. data/lib/mocha/stubbed_method.rb +7 -7
  51. data/lib/mocha/version.rb +1 -1
  52. data/lib/mocha.rb +15 -0
  53. metadata +9 -4
@@ -1,64 +1,66 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mocha/parameter_matchers/base'
3
+ require 'mocha/parameter_matchers/base_methods'
4
4
 
5
5
  module Mocha
6
6
  module ParameterMatchers
7
- # Matches +Hash+ containing entry with +key+ and +value+.
8
- #
9
- # @overload def has_entry(key, value)
10
- # @param [Object] key key for entry.
11
- # @param [Object] value value for entry.
12
- # @overload def has_entry(single_entry_hash)
13
- # @param [Hash] single_entry_hash +Hash+ with single entry.
14
- # @raise [ArgumentError] if +single_entry_hash+ does not contain exactly one entry.
15
- #
16
- # @return [HasEntry] parameter matcher.
17
- #
18
- # @see Expectation#with
19
- #
20
- # @example Actual parameter contains expected entry supplied as key and value.
21
- # object = mock()
22
- # object.expects(:method_1).with(has_entry('key_1', 1))
23
- # object.method_1('key_1' => 1, 'key_2' => 2)
24
- # # no error raised
25
- #
26
- # @example Actual parameter contains expected entry supplied as +Hash+ entry.
27
- # object = mock()
28
- # object.expects(:method_1).with(has_entry('key_1' => 1))
29
- # object.method_1('key_1' => 1, 'key_2' => 2)
30
- # # no error raised
31
- #
32
- # @example Actual parameter does not contain expected entry supplied as key and value.
33
- # object = mock()
34
- # object.expects(:method_1).with(has_entry('key_1', 1))
35
- # object.method_1('key_1' => 2, 'key_2' => 1)
36
- # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1
37
- #
38
- # @example Actual parameter does not contain expected entry supplied as +Hash+ entry.
39
- #
40
- # object = mock()
41
- # object.expects(:method_1).with(has_entry('key_1' => 1))
42
- # object.method_1('key_1' => 2, 'key_2' => 1)
43
- # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1
44
- #
45
- def has_entry(*options) # rubocop:disable Naming/PredicateName
46
- case options.length
47
- when 0
48
- raise ArgumentError, 'No arguments. Expecting at least one.'
49
- when 1
50
- key, value = parse_option(options[0])
51
- when 2
52
- key, value = options
53
- else
54
- raise ArgumentError, 'Too many arguments; use either a single argument (must be a Hash) or two arguments (a key and a value).'
7
+ module Methods
8
+ # Matches +Hash+ containing entry with +key+ and +value+.
9
+ #
10
+ # @overload def has_entry(key, value)
11
+ # @param [Object] key key for entry.
12
+ # @param [Object] value value for entry.
13
+ # @overload def has_entry(single_entry_hash)
14
+ # @param [Hash] single_entry_hash +Hash+ with single entry.
15
+ # @raise [ArgumentError] if +single_entry_hash+ does not contain exactly one entry.
16
+ #
17
+ # @return [HasEntry] parameter matcher.
18
+ #
19
+ # @see Expectation#with
20
+ #
21
+ # @example Actual parameter contains expected entry supplied as key and value.
22
+ # object = mock()
23
+ # object.expects(:method_1).with(has_entry('key_1', 1))
24
+ # object.method_1('key_1' => 1, 'key_2' => 2)
25
+ # # no error raised
26
+ #
27
+ # @example Actual parameter contains expected entry supplied as +Hash+ entry.
28
+ # object = mock()
29
+ # object.expects(:method_1).with(has_entry('key_1' => 1))
30
+ # object.method_1('key_1' => 1, 'key_2' => 2)
31
+ # # no error raised
32
+ #
33
+ # @example Actual parameter does not contain expected entry supplied as key and value.
34
+ # object = mock()
35
+ # object.expects(:method_1).with(has_entry('key_1', 1))
36
+ # object.method_1('key_1' => 2, 'key_2' => 1)
37
+ # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1
38
+ #
39
+ # @example Actual parameter does not contain expected entry supplied as +Hash+ entry.
40
+ #
41
+ # object = mock()
42
+ # object.expects(:method_1).with(has_entry('key_1' => 1))
43
+ # object.method_1('key_1' => 2, 'key_2' => 1)
44
+ # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1
45
+ #
46
+ def has_entry(*options) # rubocop:disable Naming/PredicatePrefix
47
+ case options.length
48
+ when 0
49
+ raise ArgumentError, 'No arguments. Expecting at least one.'
50
+ when 1
51
+ key, value = HasEntry.parse_option(options[0])
52
+ when 2
53
+ key, value = options
54
+ else
55
+ raise ArgumentError, 'Too many arguments; use either a single argument (must be a Hash) or two arguments (a key and a value).'
56
+ end
57
+ HasEntry.new(key, value)
55
58
  end
56
- HasEntry.new(key, value)
57
59
  end
58
60
 
59
61
  # Parameter matcher which matches when actual parameter contains expected +Hash+ entry.
60
62
  class HasEntry
61
- include Base
63
+ include BaseMethods
62
64
 
63
65
  # @private
64
66
  def initialize(key, value)
@@ -79,24 +81,22 @@ module Mocha
79
81
  def mocha_inspect
80
82
  "has_entry(#{@key.mocha_inspect} => #{@value.mocha_inspect})"
81
83
  end
82
- end
83
84
 
84
- private
85
-
86
- # @private
87
- def parse_option(option)
88
- case option
89
- when Hash
90
- case option.length
91
- when 0
92
- raise ArgumentError, 'Argument has no entries.'
93
- when 1
94
- option.first
85
+ # @private
86
+ def self.parse_option(option)
87
+ case option
88
+ when Hash
89
+ case option.length
90
+ when 0
91
+ raise ArgumentError, 'Argument has no entries.'
92
+ when 1
93
+ option.first
94
+ else
95
+ raise ArgumentError, 'Argument has multiple entries. Use Mocha::ParameterMatchers#has_entries instead.'
96
+ end
95
97
  else
96
- raise ArgumentError, 'Argument has multiple entries. Use Mocha::ParameterMatchers#has_entries instead.'
98
+ raise ArgumentError, 'Argument is not a Hash.'
97
99
  end
98
- else
99
- raise ArgumentError, 'Argument is not a Hash.'
100
100
  end
101
101
  end
102
102
  end
@@ -1,35 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mocha/parameter_matchers/base'
3
+ require 'mocha/parameter_matchers/base_methods'
4
4
 
5
5
  module Mocha
6
6
  module ParameterMatchers
7
- # Matches +Hash+ containing +key+.
8
- #
9
- # @param [Object] key expected key.
10
- # @return [HasKey] parameter matcher.
11
- #
12
- # @see Expectation#with
13
- #
14
- # @example Actual parameter contains entry with expected key.
15
- # object = mock()
16
- # object.expects(:method_1).with(has_key('key_1'))
17
- # object.method_1('key_1' => 1, 'key_2' => 2)
18
- # # no error raised
19
- #
20
- # @example Actual parameter does not contain entry with expected key.
21
- # object = mock()
22
- # object.expects(:method_1).with(has_key('key_1'))
23
- # object.method_1('key_2' => 2)
24
- # # error raised, because method_1 was not called with Hash containing key: 'key_1'
25
- #
26
- def has_key(key) # rubocop:disable Naming/PredicateName
27
- HasKey.new(key)
7
+ module Methods
8
+ # Matches +Hash+ containing +key+.
9
+ #
10
+ # @param [Object] key expected key.
11
+ # @return [HasKey] parameter matcher.
12
+ #
13
+ # @see Expectation#with
14
+ #
15
+ # @example Actual parameter contains entry with expected key.
16
+ # object = mock()
17
+ # object.expects(:method_1).with(has_key('key_1'))
18
+ # object.method_1('key_1' => 1, 'key_2' => 2)
19
+ # # no error raised
20
+ #
21
+ # @example Actual parameter does not contain entry with expected key.
22
+ # object = mock()
23
+ # object.expects(:method_1).with(has_key('key_1'))
24
+ # object.method_1('key_2' => 2)
25
+ # # error raised, because method_1 was not called with Hash containing key: 'key_1'
26
+ #
27
+ def has_key(key) # rubocop:disable Naming/PredicatePrefix
28
+ HasKey.new(key)
29
+ end
28
30
  end
29
31
 
30
32
  # Parameter matcher which matches when actual parameter contains +Hash+ entry with expected key.
31
33
  class HasKey
32
- include Base
34
+ include BaseMethods
33
35
 
34
36
  # @private
35
37
  def initialize(key)
@@ -1,35 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mocha/parameter_matchers/base'
3
+ require 'mocha/parameter_matchers/base_methods'
4
4
 
5
5
  module Mocha
6
6
  module ParameterMatchers
7
- # Matches +Hash+ containing +keys+.
8
- #
9
- # @param [*Array<Object>] keys expected keys.
10
- # @return [HasKeys] parameter matcher.
11
- #
12
- # @see Expectation#with
13
- #
14
- # @example Actual parameter contains entry with expected keys.
15
- # object = mock()
16
- # object.expects(:method_1).with(has_keys(:key_1, :key_2))
17
- # object.method_1(:key_1 => 1, :key_2 => 2, :key_3 => 3)
18
- # # no error raised
19
- #
20
- # @example Actual parameter does not contain all expected keys.
21
- # object = mock()
22
- # object.expects(:method_1).with(has_keys(:key_1, :key_2))
23
- # object.method_1(:key_2 => 2)
24
- # # error raised, because method_1 was not called with Hash containing key: :key_1
25
- #
26
- def has_keys(*keys) # rubocop:disable Naming/PredicateName
27
- HasKeys.new(*keys)
7
+ module Methods
8
+ # Matches +Hash+ containing +keys+.
9
+ #
10
+ # @param [*Array<Object>] keys expected keys.
11
+ # @return [HasKeys] parameter matcher.
12
+ #
13
+ # @see Expectation#with
14
+ #
15
+ # @example Actual parameter contains entry with expected keys.
16
+ # object = mock()
17
+ # object.expects(:method_1).with(has_keys(:key_1, :key_2))
18
+ # object.method_1(:key_1 => 1, :key_2 => 2, :key_3 => 3)
19
+ # # no error raised
20
+ #
21
+ # @example Actual parameter does not contain all expected keys.
22
+ # object = mock()
23
+ # object.expects(:method_1).with(has_keys(:key_1, :key_2))
24
+ # object.method_1(:key_2 => 2)
25
+ # # error raised, because method_1 was not called with Hash containing key: :key_1
26
+ #
27
+ def has_keys(*keys) # rubocop:disable Naming/PredicatePrefix
28
+ HasKeys.new(*keys)
29
+ end
28
30
  end
29
31
 
30
32
  # Parameter matcher which matches when actual parameter contains +Hash+ with all expected keys.
31
33
  class HasKeys
32
- include Base
34
+ include BaseMethods
33
35
 
34
36
  # @private
35
37
  def initialize(*keys)
@@ -1,35 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mocha/parameter_matchers/base'
3
+ require 'mocha/parameter_matchers/base_methods'
4
4
 
5
5
  module Mocha
6
6
  module ParameterMatchers
7
- # Matches +Hash+ containing +value+.
8
- #
9
- # @param [Object] value expected value.
10
- # @return [HasValue] parameter matcher.
11
- #
12
- # @see Expectation#with
13
- #
14
- # @example Actual parameter contains entry with expected value.
15
- # object = mock()
16
- # object.expects(:method_1).with(has_value(1))
17
- # object.method_1('key_1' => 1, 'key_2' => 2)
18
- # # no error raised
19
- #
20
- # @example Actual parameter does not contain entry with expected value.
21
- # object = mock()
22
- # object.expects(:method_1).with(has_value(1))
23
- # object.method_1('key_2' => 2)
24
- # # error raised, because method_1 was not called with Hash containing value: 1
25
- #
26
- def has_value(value) # rubocop:disable Naming/PredicateName
27
- HasValue.new(value)
7
+ module Methods
8
+ # Matches +Hash+ containing +value+.
9
+ #
10
+ # @param [Object] value expected value.
11
+ # @return [HasValue] parameter matcher.
12
+ #
13
+ # @see Expectation#with
14
+ #
15
+ # @example Actual parameter contains entry with expected value.
16
+ # object = mock()
17
+ # object.expects(:method_1).with(has_value(1))
18
+ # object.method_1('key_1' => 1, 'key_2' => 2)
19
+ # # no error raised
20
+ #
21
+ # @example Actual parameter does not contain entry with expected value.
22
+ # object = mock()
23
+ # object.expects(:method_1).with(has_value(1))
24
+ # object.method_1('key_2' => 2)
25
+ # # error raised, because method_1 was not called with Hash containing value: 1
26
+ #
27
+ def has_value(value) # rubocop:disable Naming/PredicatePrefix
28
+ HasValue.new(value)
29
+ end
28
30
  end
29
31
 
30
32
  # Parameter matcher which matches when actual parameter contains +Hash+ entry with expected value.
31
33
  class HasValue
32
- include Base
34
+ include BaseMethods
33
35
 
34
36
  # @private
35
37
  def initialize(value)
@@ -1,74 +1,76 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'mocha/parameter_matchers/all_of'
4
- require 'mocha/parameter_matchers/base'
4
+ require 'mocha/parameter_matchers/base_methods'
5
5
 
6
6
  module Mocha
7
7
  module ParameterMatchers
8
- # Matches any object that responds with +true+ to +include?(item)+
9
- # for all items.
10
- #
11
- # @param [*Array] items expected items.
12
- # @return [Includes] parameter matcher.
13
- #
14
- # @see Expectation#with
15
- #
16
- # @example Actual parameter includes all items.
17
- # object = mock()
18
- # object.expects(:method_1).with(includes('foo', 'bar'))
19
- # object.method_1(['foo', 'bar', 'baz'])
20
- # # no error raised
21
- #
22
- # @example Actual parameter does not include all items.
23
- # object.method_1(['foo', 'baz'])
24
- # # error raised, because ['foo', 'baz'] does not include 'bar'.
25
- #
26
- # @example Actual parameter includes item which matches nested matcher.
27
- # object = mock()
28
- # object.expects(:method_1).with(includes(has_key(:key)))
29
- # object.method_1(['foo', 'bar', {key: 'baz'}])
30
- # # no error raised
31
- #
32
- # @example Actual parameter does not include item matching nested matcher.
33
- # object.method_1(['foo', 'bar', {:other_key => 'baz'}])
34
- # # error raised, because no element matches `has_key(:key)` matcher
35
- #
36
- # @example Actual parameter is a String including substring.
37
- # object = mock()
38
- # object.expects(:method_1).with(includes('bar'))
39
- # object.method_1('foobarbaz')
40
- # # no error raised
41
- #
42
- # @example Actual parameter is a String not including substring.
43
- # object.method_1('foobaz')
44
- # # error raised, because 'foobaz' does not include 'bar'
45
- #
46
- # @example Actual parameter is a Hash including the given key.
47
- # object = mock()
48
- # object.expects(:method_1).with(includes(:bar))
49
- # object.method_1({foo: 1, bar: 2})
50
- # # no error raised
51
- #
52
- # @example Actual parameter is a Hash without the given key.
53
- # object.method_1({foo: 1, baz: 2})
54
- # # error raised, because hash does not include key 'bar'
55
- #
56
- # @example Actual parameter is a Hash with a key matching the given matcher.
57
- # object = mock()
58
- # object.expects(:method_1).with(includes(regexp_matches(/ar/)))
59
- # object.method_1({'foo' => 1, 'bar' => 2})
60
- # # no error raised
61
- #
62
- # @example Actual parameter is a Hash no key matching the given matcher.
63
- # object.method_1({'foo' => 1, 'baz' => 3})
64
- # # error raised, because hash does not include a key matching /ar/
65
- def includes(*items)
66
- Includes.new(*items)
8
+ module Methods
9
+ # Matches any object that responds with +true+ to +include?(item)+
10
+ # for all items.
11
+ #
12
+ # @param [*Array] items expected items.
13
+ # @return [Includes] parameter matcher.
14
+ #
15
+ # @see Expectation#with
16
+ #
17
+ # @example Actual parameter includes all items.
18
+ # object = mock()
19
+ # object.expects(:method_1).with(includes('foo', 'bar'))
20
+ # object.method_1(['foo', 'bar', 'baz'])
21
+ # # no error raised
22
+ #
23
+ # @example Actual parameter does not include all items.
24
+ # object.method_1(['foo', 'baz'])
25
+ # # error raised, because ['foo', 'baz'] does not include 'bar'.
26
+ #
27
+ # @example Actual parameter includes item which matches nested matcher.
28
+ # object = mock()
29
+ # object.expects(:method_1).with(includes(has_key(:key)))
30
+ # object.method_1(['foo', 'bar', {key: 'baz'}])
31
+ # # no error raised
32
+ #
33
+ # @example Actual parameter does not include item matching nested matcher.
34
+ # object.method_1(['foo', 'bar', {:other_key => 'baz'}])
35
+ # # error raised, because no element matches `has_key(:key)` matcher
36
+ #
37
+ # @example Actual parameter is a String including substring.
38
+ # object = mock()
39
+ # object.expects(:method_1).with(includes('bar'))
40
+ # object.method_1('foobarbaz')
41
+ # # no error raised
42
+ #
43
+ # @example Actual parameter is a String not including substring.
44
+ # object.method_1('foobaz')
45
+ # # error raised, because 'foobaz' does not include 'bar'
46
+ #
47
+ # @example Actual parameter is a Hash including the given key.
48
+ # object = mock()
49
+ # object.expects(:method_1).with(includes(:bar))
50
+ # object.method_1({foo: 1, bar: 2})
51
+ # # no error raised
52
+ #
53
+ # @example Actual parameter is a Hash without the given key.
54
+ # object.method_1({foo: 1, baz: 2})
55
+ # # error raised, because hash does not include key 'bar'
56
+ #
57
+ # @example Actual parameter is a Hash with a key matching the given matcher.
58
+ # object = mock()
59
+ # object.expects(:method_1).with(includes(regexp_matches(/ar/)))
60
+ # object.method_1({'foo' => 1, 'bar' => 2})
61
+ # # no error raised
62
+ #
63
+ # @example Actual parameter is a Hash no key matching the given matcher.
64
+ # object.method_1({'foo' => 1, 'baz' => 3})
65
+ # # error raised, because hash does not include a key matching /ar/
66
+ def includes(*items)
67
+ Includes.new(*items)
68
+ end
67
69
  end
68
70
 
69
71
  # Parameter matcher which matches when actual parameter includes expected values.
70
72
  class Includes
71
- include Base
73
+ include BaseMethods
72
74
 
73
75
  # @private
74
76
  def initialize(*items)
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mocha/parameter_matchers/base'
3
+ require 'mocha/parameter_matchers/base_methods'
4
4
  require 'mocha/parameter_matchers/equals'
5
5
  require 'mocha/parameter_matchers/positional_or_keyword_hash'
6
6
 
@@ -10,7 +10,7 @@ module Mocha
10
10
  module InstanceMethods
11
11
  # @private
12
12
  def to_matcher(expectation: nil, top_level: false, last: false)
13
- if Base === self
13
+ if is_a?(BaseMethods)
14
14
  self
15
15
  elsif Hash === self && top_level
16
16
  Mocha::ParameterMatchers::PositionalOrKeywordHash.new(self, expectation, last)
@@ -1,35 +1,37 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mocha/parameter_matchers/base'
3
+ require 'mocha/parameter_matchers/base_methods'
4
4
 
5
5
  module Mocha
6
6
  module ParameterMatchers
7
- # Matches any object that is an instance of +klass+
8
- #
9
- # @param [Class] klass expected class.
10
- # @return [InstanceOf] parameter matcher.
11
- #
12
- # @see Expectation#with
13
- # @see Kernel#instance_of?
14
- #
15
- # @example Actual parameter is an instance of +String+.
16
- # object = mock()
17
- # object.expects(:method_1).with(instance_of(String))
18
- # object.method_1('string')
19
- # # no error raised
20
- #
21
- # @example Actual parameter is not an instance of +String+.
22
- # object = mock()
23
- # object.expects(:method_1).with(instance_of(String))
24
- # object.method_1(99)
25
- # # error raised, because method_1 was not called with an instance of String
26
- def instance_of(klass)
27
- InstanceOf.new(klass)
7
+ module Methods
8
+ # Matches any object that is an instance of +klass+
9
+ #
10
+ # @param [Class] klass expected class.
11
+ # @return [InstanceOf] parameter matcher.
12
+ #
13
+ # @see Expectation#with
14
+ # @see Kernel#instance_of?
15
+ #
16
+ # @example Actual parameter is an instance of +String+.
17
+ # object = mock()
18
+ # object.expects(:method_1).with(instance_of(String))
19
+ # object.method_1('string')
20
+ # # no error raised
21
+ #
22
+ # @example Actual parameter is not an instance of +String+.
23
+ # object = mock()
24
+ # object.expects(:method_1).with(instance_of(String))
25
+ # object.method_1(99)
26
+ # # error raised, because method_1 was not called with an instance of String
27
+ def instance_of(klass)
28
+ InstanceOf.new(klass)
29
+ end
28
30
  end
29
31
 
30
32
  # Parameter matcher which matches when actual parameter is an instance of the specified class.
31
33
  class InstanceOf
32
- include Base
34
+ include BaseMethods
33
35
 
34
36
  # @private
35
37
  def initialize(klass)
@@ -1,36 +1,38 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'mocha/parameter_matchers/base'
3
+ require 'mocha/parameter_matchers/base_methods'
4
4
 
5
5
  module Mocha
6
6
  module ParameterMatchers
7
- # Matches any object that is a +klass+.
8
- #
9
- # @param [Class] klass expected class.
10
- # @return [IsA] parameter matcher.
11
- #
12
- # @see Expectation#with
13
- # @see Kernel#is_a?
14
- #
15
- # @example Actual parameter is a +Integer+.
16
- # object = mock()
17
- # object.expects(:method_1).with(is_a(Integer))
18
- # object.method_1(99)
19
- # # no error raised
20
- #
21
- # @example Actual parameter is not a +Integer+.
22
- # object = mock()
23
- # object.expects(:method_1).with(is_a(Integer))
24
- # object.method_1('string')
25
- # # error raised, because method_1 was not called with an Integer
26
- #
27
- def is_a(klass) # rubocop:disable Naming/PredicateName
28
- IsA.new(klass)
7
+ module Methods
8
+ # Matches any object that is a +klass+.
9
+ #
10
+ # @param [Class] klass expected class.
11
+ # @return [IsA] parameter matcher.
12
+ #
13
+ # @see Expectation#with
14
+ # @see Kernel#is_a?
15
+ #
16
+ # @example Actual parameter is a +Integer+.
17
+ # object = mock()
18
+ # object.expects(:method_1).with(is_a(Integer))
19
+ # object.method_1(99)
20
+ # # no error raised
21
+ #
22
+ # @example Actual parameter is not a +Integer+.
23
+ # object = mock()
24
+ # object.expects(:method_1).with(is_a(Integer))
25
+ # object.method_1('string')
26
+ # # error raised, because method_1 was not called with an Integer
27
+ #
28
+ def is_a(klass) # rubocop:disable Naming/PredicatePrefix
29
+ IsA.new(klass)
30
+ end
29
31
  end
30
32
 
31
33
  # Parameter matcher which matches when actual parameter is a specific class.
32
34
  class IsA
33
- include Base
35
+ include BaseMethods
34
36
 
35
37
  # @private
36
38
  def initialize(klass)