mocha 2.7.1 → 2.8.0

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