mocha 0.10.5 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (229) hide show
  1. data/COPYING.rdoc +1 -1
  2. data/README.rdoc +6 -4
  3. data/RELEASE.rdoc +12 -0
  4. data/Rakefile +29 -60
  5. data/doc/Mocha.html +112 -0
  6. data/doc/Mocha/API.html +898 -0
  7. data/doc/Mocha/ClassMethods.html +246 -0
  8. data/doc/Mocha/Configuration.html +471 -0
  9. data/doc/Mocha/Expectation.html +2570 -0
  10. data/doc/Mocha/Mock.html +830 -0
  11. data/doc/Mocha/ObjectMethods.html +668 -0
  12. data/doc/Mocha/ParameterMatchers.html +2715 -0
  13. data/doc/Mocha/ParameterMatchers/AllOf.html +137 -0
  14. data/doc/Mocha/ParameterMatchers/AnyOf.html +137 -0
  15. data/doc/Mocha/ParameterMatchers/AnyParameters.html +136 -0
  16. data/doc/Mocha/ParameterMatchers/Anything.html +136 -0
  17. data/doc/Mocha/ParameterMatchers/Base.html +419 -0
  18. data/doc/Mocha/ParameterMatchers/Equals.html +137 -0
  19. data/doc/Mocha/ParameterMatchers/HasEntries.html +137 -0
  20. data/doc/Mocha/ParameterMatchers/HasEntry.html +137 -0
  21. data/doc/Mocha/ParameterMatchers/HasKey.html +137 -0
  22. data/doc/Mocha/ParameterMatchers/HasValue.html +137 -0
  23. data/doc/Mocha/ParameterMatchers/Includes.html +137 -0
  24. data/doc/Mocha/ParameterMatchers/InstanceOf.html +137 -0
  25. data/doc/Mocha/ParameterMatchers/IsA.html +136 -0
  26. data/doc/Mocha/ParameterMatchers/KindOf.html +137 -0
  27. data/doc/Mocha/ParameterMatchers/Not.html +137 -0
  28. data/doc/Mocha/ParameterMatchers/Optionally.html +136 -0
  29. data/doc/Mocha/ParameterMatchers/QueryStringMatches.html +136 -0
  30. data/doc/Mocha/ParameterMatchers/RegexpMatches.html +137 -0
  31. data/doc/Mocha/ParameterMatchers/RespondsWith.html +137 -0
  32. data/doc/Mocha/ParameterMatchers/YamlEquivalent.html +137 -0
  33. data/doc/Mocha/Sequence.html +133 -0
  34. data/doc/Mocha/StateMachine.html +510 -0
  35. data/doc/Mocha/StateMachine/State.html +125 -0
  36. data/doc/Mocha/StateMachine/StatePredicate.html +125 -0
  37. data/doc/Mocha/StubbingError.html +134 -0
  38. data/doc/Mocha/UnexpectedInvocation.html +124 -0
  39. data/doc/_index.html +481 -0
  40. data/doc/class_list.html +47 -0
  41. data/doc/css/common.css +1 -0
  42. data/doc/css/full_list.css +55 -0
  43. data/doc/css/style.css +322 -0
  44. data/doc/file.COPYING.html +72 -0
  45. data/doc/file.MIT-LICENSE.html +86 -0
  46. data/doc/file.README.html +153 -0
  47. data/doc/file.RELEASE.html +933 -0
  48. data/doc/file.misc.html +108 -0
  49. data/doc/file.mocha.html +90 -0
  50. data/doc/file.stubba.html +129 -0
  51. data/doc/file_list.html +67 -0
  52. data/doc/frames.html +13 -0
  53. data/doc/index.html +153 -0
  54. data/doc/js/app.js +205 -0
  55. data/doc/js/full_list.js +173 -0
  56. data/doc/js/jquery.js +16 -0
  57. data/doc/method_list.html +510 -0
  58. data/doc/top-level-namespace.html +105 -0
  59. data/lib/mocha/any_instance_method.rb +16 -11
  60. data/lib/mocha/api.rb +120 -106
  61. data/lib/mocha/argument_iterator.rb +6 -6
  62. data/lib/mocha/backtrace_filter.rb +1 -1
  63. data/lib/mocha/cardinality.rb +21 -21
  64. data/lib/mocha/central.rb +8 -8
  65. data/lib/mocha/change_state_side_effect.rb +5 -5
  66. data/lib/mocha/class_method.rb +14 -19
  67. data/lib/mocha/configuration.rb +47 -37
  68. data/lib/mocha/deprecation.rb +8 -8
  69. data/lib/mocha/exception_raiser.rb +7 -7
  70. data/lib/mocha/expectation.rb +173 -77
  71. data/lib/mocha/expectation_error.rb +2 -2
  72. data/lib/mocha/expectation_list.rb +11 -11
  73. data/lib/mocha/in_state_ordering_constraint.rb +5 -5
  74. data/lib/mocha/inspect.rb +8 -8
  75. data/lib/mocha/instance_method.rb +1 -17
  76. data/lib/mocha/integration.rb +9 -9
  77. data/lib/mocha/integration/mini_test/assertion_counter.rb +9 -9
  78. data/lib/mocha/integration/mini_test/exception_translation.rb +6 -6
  79. data/lib/mocha/integration/mini_test/version_13.rb +6 -6
  80. data/lib/mocha/integration/mini_test/version_140.rb +6 -6
  81. data/lib/mocha/integration/mini_test/version_141.rb +6 -6
  82. data/lib/mocha/integration/mini_test/version_142_to_172.rb +7 -7
  83. data/lib/mocha/integration/mini_test/version_200.rb +7 -7
  84. data/lib/mocha/integration/test_unit/assertion_counter.rb +10 -10
  85. data/lib/mocha/integration/test_unit/gem_version_200.rb +6 -6
  86. data/lib/mocha/integration/test_unit/gem_version_201_to_202.rb +6 -6
  87. data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +6 -6
  88. data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +6 -6
  89. data/lib/mocha/is_a.rb +1 -1
  90. data/lib/mocha/logger.rb +6 -6
  91. data/lib/mocha/method_matcher.rb +7 -7
  92. data/lib/mocha/mock.rb +85 -48
  93. data/lib/mocha/mockery.rb +47 -33
  94. data/lib/mocha/module_method.rb +2 -2
  95. data/lib/mocha/multiple_yields.rb +9 -9
  96. data/lib/mocha/names.rb +18 -18
  97. data/lib/mocha/no_yields.rb +7 -7
  98. data/lib/mocha/object.rb +104 -75
  99. data/lib/mocha/parameter_matchers.rb +3 -3
  100. data/lib/mocha/parameter_matchers/all_of.rb +22 -12
  101. data/lib/mocha/parameter_matchers/any_of.rb +23 -12
  102. data/lib/mocha/parameter_matchers/any_parameters.rb +15 -8
  103. data/lib/mocha/parameter_matchers/anything.rb +20 -11
  104. data/lib/mocha/parameter_matchers/base.rb +35 -27
  105. data/lib/mocha/parameter_matchers/equals.rb +23 -12
  106. data/lib/mocha/parameter_matchers/has_entries.rb +22 -12
  107. data/lib/mocha/parameter_matchers/has_entry.rb +31 -13
  108. data/lib/mocha/parameter_matchers/has_key.rb +21 -11
  109. data/lib/mocha/parameter_matchers/has_value.rb +21 -11
  110. data/lib/mocha/parameter_matchers/includes.rb +15 -5
  111. data/lib/mocha/parameter_matchers/instance_of.rb +23 -12
  112. data/lib/mocha/parameter_matchers/is_a.rb +23 -12
  113. data/lib/mocha/parameter_matchers/kind_of.rb +23 -12
  114. data/lib/mocha/parameter_matchers/not.rb +22 -12
  115. data/lib/mocha/parameter_matchers/object.rb +5 -3
  116. data/lib/mocha/parameter_matchers/optionally.rb +24 -12
  117. data/lib/mocha/parameter_matchers/query_string.rb +14 -3
  118. data/lib/mocha/parameter_matchers/regexp_matches.rb +21 -11
  119. data/lib/mocha/parameter_matchers/responds_with.rb +17 -6
  120. data/lib/mocha/parameter_matchers/yaml_equivalent.rb +16 -6
  121. data/lib/mocha/parameters_matcher.rb +8 -8
  122. data/lib/mocha/pretty_parameters.rb +7 -7
  123. data/lib/mocha/return_values.rb +11 -11
  124. data/lib/mocha/sequence.rb +23 -14
  125. data/lib/mocha/single_return_value.rb +7 -7
  126. data/lib/mocha/single_yield.rb +9 -9
  127. data/lib/mocha/standalone.rb +1 -1
  128. data/lib/mocha/state_machine.rb +61 -46
  129. data/lib/mocha/stubbing_error.rb +8 -5
  130. data/lib/mocha/thrower.rb +2 -2
  131. data/lib/mocha/unexpected_invocation.rb +9 -6
  132. data/lib/mocha/version.rb +1 -1
  133. data/lib/mocha/yield_parameters.rb +10 -10
  134. data/lib/mocha_standalone.rb +1 -1
  135. data/mocha.gemspec +4 -7
  136. data/test/acceptance/acceptance_test_helper.rb +10 -10
  137. data/test/acceptance/api_test.rb +20 -20
  138. data/test/acceptance/bug_18914_test.rb +12 -12
  139. data/test/acceptance/bug_21465_test.rb +6 -6
  140. data/test/acceptance/bug_21563_test.rb +5 -5
  141. data/test/acceptance/exception_rescue_test.rb +1 -1
  142. data/test/acceptance/expected_invocation_count_test.rb +17 -17
  143. data/test/acceptance/failure_messages_test.rb +13 -13
  144. data/test/acceptance/minitest_test.rb +39 -39
  145. data/test/acceptance/mocha_example_test.rb +26 -26
  146. data/test/acceptance/mocha_test_result_test.rb +13 -13
  147. data/test/acceptance/mock_test.rb +5 -5
  148. data/test/acceptance/mock_with_initializer_block_test.rb +5 -5
  149. data/test/acceptance/mocked_methods_dispatch_test.rb +4 -4
  150. data/test/acceptance/multiple_expectations_failure_message_test.rb +2 -2
  151. data/test/acceptance/optional_parameters_test.rb +5 -5
  152. data/test/acceptance/parameter_matcher_test.rb +18 -18
  153. data/test/acceptance/partial_mocks_test.rb +9 -9
  154. data/test/acceptance/raise_exception_test.rb +1 -1
  155. data/test/acceptance/return_value_test.rb +5 -5
  156. data/test/acceptance/sequence_test.rb +29 -29
  157. data/test/acceptance/states_test.rb +17 -17
  158. data/test/acceptance/stub_any_instance_method_test.rb +13 -13
  159. data/test/acceptance/stub_class_method_defined_on_active_record_association_proxy_test.rb +7 -7
  160. data/test/acceptance/stub_everything_test.rb +5 -5
  161. data/test/acceptance/stub_instance_method_defined_on_singleton_class_test.rb +1 -1
  162. data/test/acceptance/stub_module_method_test.rb +17 -17
  163. data/test/acceptance/stub_test.rb +5 -5
  164. data/test/acceptance/stubba_example_test.rb +24 -24
  165. data/test/acceptance/stubba_test_result_test.rb +11 -11
  166. data/test/acceptance/stubbing_error_backtrace_test.rb +6 -6
  167. data/test/acceptance/stubbing_frozen_object_test.rb +88 -0
  168. data/test/acceptance/stubbing_method_unnecessarily_test.rb +9 -9
  169. data/test/acceptance/stubbing_nil_test.rb +59 -0
  170. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +13 -13
  171. data/test/acceptance/stubbing_non_existent_class_method_test.rb +15 -15
  172. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +14 -14
  173. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +13 -13
  174. data/test/acceptance/stubbing_non_public_class_method_test.rb +12 -12
  175. data/test/acceptance/stubbing_non_public_instance_method_test.rb +12 -12
  176. data/test/acceptance/stubbing_on_non_mock_object_test.rb +9 -9
  177. data/test/acceptance/stubbing_same_class_method_on_parent_and_child_classes_test.rb +35 -0
  178. data/test/acceptance/throw_test.rb +1 -1
  179. data/test/deprecation_disabler.rb +1 -1
  180. data/test/execution_point.rb +7 -7
  181. data/test/method_definer.rb +1 -1
  182. data/test/mini_test_result.rb +21 -21
  183. data/test/simple_counter.rb +5 -5
  184. data/test/test_helper.rb +1 -1
  185. data/test/test_runner.rb +22 -24
  186. data/test/test_unit_result.rb +20 -0
  187. data/test/unit/any_instance_method_test.rb +28 -32
  188. data/test/unit/array_inspect_test.rb +3 -3
  189. data/test/unit/backtrace_filter_test.rb +3 -3
  190. data/test/unit/cardinality_test.rb +12 -12
  191. data/test/unit/central_test.rb +18 -18
  192. data/test/unit/change_state_side_effect_test.rb +12 -12
  193. data/test/unit/class_method_test.rb +33 -91
  194. data/test/unit/date_time_inspect_test.rb +4 -4
  195. data/test/unit/exception_raiser_test.rb +5 -5
  196. data/test/unit/expectation_list_test.rb +7 -7
  197. data/test/unit/expectation_test.rb +66 -66
  198. data/test/unit/hash_inspect_test.rb +4 -4
  199. data/test/unit/in_state_ordering_constraint_test.rb +13 -13
  200. data/test/unit/method_matcher_test.rb +3 -3
  201. data/test/unit/mock_test.rb +40 -40
  202. data/test/unit/mockery_test.rb +25 -25
  203. data/test/unit/multiple_yields_test.rb +2 -2
  204. data/test/unit/no_yields_test.rb +2 -2
  205. data/test/unit/object_inspect_test.rb +4 -4
  206. data/test/unit/object_test.rb +15 -15
  207. data/test/unit/parameter_matchers/all_of_test.rb +6 -6
  208. data/test/unit/parameter_matchers/any_of_test.rb +6 -6
  209. data/test/unit/parameter_matchers/anything_test.rb +5 -5
  210. data/test/unit/parameter_matchers/has_entries_test.rb +10 -10
  211. data/test/unit/parameter_matchers/has_entry_test.rb +13 -13
  212. data/test/unit/parameter_matchers/has_key_test.rb +11 -11
  213. data/test/unit/parameter_matchers/has_value_test.rb +12 -12
  214. data/test/unit/parameter_matchers/includes_test.rb +4 -4
  215. data/test/unit/parameter_matchers/not_test.rb +6 -6
  216. data/test/unit/parameter_matchers/regexp_matches_test.rb +9 -9
  217. data/test/unit/parameter_matchers/responds_with_test.rb +6 -6
  218. data/test/unit/parameter_matchers/stub_matcher.rb +4 -4
  219. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +6 -6
  220. data/test/unit/parameters_matcher_test.rb +16 -16
  221. data/test/unit/return_values_test.rb +5 -5
  222. data/test/unit/sequence_test.rb +10 -10
  223. data/test/unit/single_return_value_test.rb +3 -3
  224. data/test/unit/single_yield_test.rb +2 -2
  225. data/test/unit/state_machine_test.rb +19 -19
  226. data/test/unit/string_inspect_test.rb +2 -2
  227. data/test/unit/thrower_test.rb +1 -1
  228. data/test/unit/yield_parameters_test.rb +11 -11
  229. metadata +113 -101
@@ -1,17 +1,23 @@
1
1
  require 'mocha/parameter_matchers/base'
2
2
 
3
3
  module Mocha
4
-
4
+
5
5
  module ParameterMatchers
6
6
 
7
- # :call-seq: Not(parameter_matcher) -> parameter_matcher
7
+ # Matches if +matcher+ does *not* match.
8
+ #
9
+ # @param [Base] matcher matcher whose logic to invert.
10
+ # @return [Not] parameter matcher.
11
+ #
12
+ # @see Expectation#with
8
13
  #
9
- # Matches if +parameter_matcher+ does not match.
14
+ # @example Actual parameter does not include the value +1+.
10
15
  # object = mock()
11
16
  # object.expects(:method_1).with(Not(includes(1)))
12
17
  # object.method_1([0, 2, 3])
13
18
  # # no error raised
14
19
  #
20
+ # @example Actual parameter does include the value +1+.
15
21
  # object = mock()
16
22
  # object.expects(:method_1).with(Not(includes(1)))
17
23
  # object.method_1([0, 1, 2, 3])
@@ -19,24 +25,28 @@ module Mocha
19
25
  def Not(matcher)
20
26
  Not.new(matcher)
21
27
  end
22
-
23
- class Not < Base # :nodoc:
24
-
28
+
29
+ # Parameter matcher which inverts the logic of the specified matcher using a logical NOT operation.
30
+ class Not < Base
31
+
32
+ # @private
25
33
  def initialize(matcher)
26
34
  @matcher = matcher
27
35
  end
28
-
36
+
37
+ # @private
29
38
  def matches?(available_parameters)
30
39
  parameter = available_parameters.shift
31
40
  !@matcher.matches?([parameter])
32
41
  end
33
-
42
+
43
+ # @private
34
44
  def mocha_inspect
35
45
  "Not(#{@matcher.mocha_inspect})"
36
46
  end
37
-
47
+
38
48
  end
39
-
49
+
40
50
  end
41
-
42
- end
51
+
52
+ end
@@ -1,15 +1,17 @@
1
1
  require 'mocha/parameter_matchers/equals'
2
2
 
3
3
  module Mocha
4
-
4
+
5
5
  module ObjectMethods
6
- def to_matcher # :nodoc:
6
+ # @private
7
+ def to_matcher
7
8
  Mocha::ParameterMatchers::Equals.new(self)
8
9
  end
9
10
  end
10
-
11
+
11
12
  end
12
13
 
14
+ # @private
13
15
  class Object
14
16
  include Mocha::ObjectMethods
15
17
  end
@@ -1,25 +1,33 @@
1
1
  module Mocha
2
-
2
+
3
3
  module ParameterMatchers
4
4
 
5
- # :call-seq: optionally(*parameter_matchers) -> parameter_matcher
6
- #
7
5
  # Matches optional parameters if available.
6
+ #
7
+ # @param [*Array<Base>] matchers matchers for optional parameters.
8
+ # @return [Optionally] parameter matcher.
9
+ #
10
+ # @see Expectation#with
11
+ #
12
+ # @example Only the two required parameters are supplied and they both match their expected value.
8
13
  # object = mock()
9
14
  # object.expects(:method_1).with(1, 2, optionally(3, 4))
10
15
  # object.method_1(1, 2)
11
16
  # # no error raised
12
17
  #
18
+ # @example Both required parameters and one of the optional parameters are supplied and they all match their expected value.
13
19
  # object = mock()
14
20
  # object.expects(:method_1).with(1, 2, optionally(3, 4))
15
21
  # object.method_1(1, 2, 3)
16
22
  # # no error raised
17
23
  #
24
+ # @example Both required parameters and both of the optional parameters are supplied and they all match their expected value.
18
25
  # object = mock()
19
26
  # object.expects(:method_1).with(1, 2, optionally(3, 4))
20
27
  # object.method_1(1, 2, 3, 4)
21
28
  # # no error raised
22
29
  #
30
+ # @example One of the actual optional parameters does not match the expected value.
23
31
  # object = mock()
24
32
  # object.expects(:method_1).with(1, 2, optionally(3, 4))
25
33
  # object.method_1(1, 2, 3, 5)
@@ -27,13 +35,16 @@ module Mocha
27
35
  def optionally(*matchers)
28
36
  Optionally.new(*matchers)
29
37
  end
30
-
31
- class Optionally < Base # :nodoc:
32
-
38
+
39
+ # Parameter matcher which allows optional parameters to be specified.
40
+ class Optionally < Base
41
+
42
+ # @private
33
43
  def initialize(*parameters)
34
44
  @matchers = parameters.map { |parameter| parameter.to_matcher }
35
45
  end
36
-
46
+
47
+ # @private
37
48
  def matches?(available_parameters)
38
49
  index = 0
39
50
  while (available_parameters.length > 0) && (index < @matchers.length) do
@@ -43,13 +54,14 @@ module Mocha
43
54
  end
44
55
  return true
45
56
  end
46
-
57
+
58
+ # @private
47
59
  def mocha_inspect
48
60
  "optionally(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })"
49
61
  end
50
-
62
+
51
63
  end
52
-
64
+
53
65
  end
54
-
55
- end
66
+
67
+ end
@@ -4,14 +4,20 @@ require 'uri'
4
4
  module Mocha
5
5
  module ParameterMatchers
6
6
 
7
- # :call-seq: has_equivalent_query_string(uri) -> parameter_matcher
7
+ # Matches a URI without regard to the ordering of parameters in the query string.
8
8
  #
9
- # Matches a URI without regard to the ordering of parameters in the query string
9
+ # @param [String] uri URI to match.
10
+ # @return [QueryStringMatches] parameter matcher.
11
+ #
12
+ # @see Expectation#with
13
+ #
14
+ # @example Actual URI has equivalent query string.
10
15
  # object = mock()
11
16
  # object.expects(:method_1).with(has_equivalent_query_string('http://example.com/foo?a=1&b=2))
12
17
  # object.method_1('http://example.com/foo?b=2&a=1')
13
18
  # # no error raised
14
19
  #
20
+ # @example Actual URI does not have equivalent query string.
15
21
  # object = mock()
16
22
  # object.expects(:method_1).with(has_equivalent_query_string('http://example.com/foo?a=1&b=2))
17
23
  # object.method_1('http://example.com/foo?a=1&b=3')
@@ -20,23 +26,28 @@ module Mocha
20
26
  QueryStringMatches.new(uri)
21
27
  end
22
28
 
23
- class QueryStringMatches < Base # :nodoc:
29
+ # Parameter matcher which matches URIs with equivalent query strings.
30
+ class QueryStringMatches < Base
24
31
 
32
+ # @private
25
33
  def initialize(uri)
26
34
  @uri = URI.parse(uri)
27
35
  end
28
36
 
37
+ # @private
29
38
  def matches?(available_parameters)
30
39
  actual = explode(URI.parse(available_parameters.shift))
31
40
  expected = explode(@uri)
32
41
  actual == expected
33
42
  end
34
43
 
44
+ # @private
35
45
  def mocha_inspect
36
46
  "has_equivalent_query_string(#{@uri.mocha_inspect})"
37
47
  end
38
48
 
39
49
  private
50
+ # @private
40
51
  def explode(uri)
41
52
  query_hash = (uri.query || '').split('&').inject({}){ |h, kv| h.merge(Hash[*kv.split('=')]) }
42
53
  URI::Generic::COMPONENT.inject({}){ |h, k| h.merge(k => uri.__send__(k)) }.merge(:query => query_hash)
@@ -1,44 +1,54 @@
1
1
  require 'mocha/parameter_matchers/base'
2
2
 
3
3
  module Mocha
4
-
4
+
5
5
  module ParameterMatchers
6
6
 
7
- # :call-seq: regexp_matches(regular_expression) -> parameter_matcher
7
+ # Matches any object that matches +regexp+.
8
+ #
9
+ # @param [Regexp] regexp regular expression to match.
10
+ # @return [RegexpMatches] parameter matcher.
11
+ #
12
+ # @see Expectation#with
8
13
  #
9
- # Matches any object that matches +regular_expression+.
14
+ # @example Actual parameter is matched by specified regular expression.
10
15
  # object = mock()
11
16
  # object.expects(:method_1).with(regexp_matches(/e/))
12
17
  # object.method_1('hello')
13
18
  # # no error raised
14
19
  #
20
+ # @example Actual parameter is not matched by specified regular expression.
15
21
  # object = mock()
16
22
  # object.expects(:method_1).with(regexp_matches(/a/))
17
23
  # object.method_1('hello')
18
- # # error raised, because method_1 was not called with a parameter that matched the
24
+ # # error raised, because method_1 was not called with a parameter that matched the
19
25
  # # regular expression
20
26
  def regexp_matches(regexp)
21
27
  RegexpMatches.new(regexp)
22
28
  end
23
29
 
24
- class RegexpMatches < Base # :nodoc:
25
-
30
+ # Parameter matcher which matches if specified regular expression matches actual paramter.
31
+ class RegexpMatches < Base
32
+
33
+ # @private
26
34
  def initialize(regexp)
27
35
  @regexp = regexp
28
36
  end
29
-
37
+
38
+ # @private
30
39
  def matches?(available_parameters)
31
40
  parameter = available_parameters.shift
32
41
  return false unless parameter.respond_to?(:=~)
33
42
  parameter =~ @regexp
34
43
  end
35
-
44
+
45
+ # @private
36
46
  def mocha_inspect
37
47
  "regexp_matches(#{@regexp.mocha_inspect})"
38
48
  end
39
-
49
+
40
50
  end
41
-
51
+
42
52
  end
43
-
53
+
44
54
  end
@@ -5,14 +5,21 @@ module Mocha
5
5
 
6
6
  module ParameterMatchers
7
7
 
8
- # :call-seq: responds_with(message, result) -> parameter_matcher
9
- #
10
8
  # Matches any object that responds to +message+ with +result+. To put it another way, it tests the quack, not the duck.
9
+ #
10
+ # @param [Symbol] message method to invoke.
11
+ # @param [Object] result expected result of sending +message+.
12
+ # @return [RespondsWith] parameter matcher.
13
+ #
14
+ # @see Expectation#with
15
+ #
16
+ # @example Actual parameter responds with "FOO" when :upcase is invoked.
11
17
  # object = mock()
12
18
  # object.expects(:method_1).with(responds_with(:upcase, "FOO"))
13
19
  # object.method_1("foo")
14
20
  # # no error raised, because "foo".upcase == "FOO"
15
21
  #
22
+ # @example Actual parameter does not respond with "FOO" when :upcase is invoked.
16
23
  # object = mock()
17
24
  # object.expects(:method_1).with(responds_with(:upcase, "BAR"))
18
25
  # object.method_1("foo")
@@ -21,23 +28,27 @@ module Mocha
21
28
  RespondsWith.new(message, result)
22
29
  end
23
30
 
24
- class RespondsWith < Base # :nodoc:
31
+ # Parameter matcher which matches if actual parameter returns expected result when specified method is invoked.
32
+ class RespondsWith < Base
25
33
 
34
+ # @private
26
35
  def initialize(message, result)
27
36
  @message, @result = message, result
28
37
  end
29
38
 
39
+ # @private
30
40
  def matches?(available_parameters)
31
41
  parameter = available_parameters.shift
32
42
  parameter.__send__(@message) == @result
33
43
  end
34
44
 
45
+ # @private
35
46
  def mocha_inspect
36
47
  "responds_with(#{@message.mocha_inspect}, #{@result.mocha_inspect})"
37
48
  end
38
-
49
+
39
50
  end
40
-
51
+
41
52
  end
42
-
53
+
43
54
  end
@@ -5,14 +5,20 @@ module Mocha
5
5
 
6
6
  module ParameterMatchers
7
7
 
8
- # :call-seq: yaml_equivalent(object) -> parameter_matcher
9
- #
10
8
  # Matches any YAML that represents the specified +object+
9
+ #
10
+ # @param [Object] object object whose YAML to compare.
11
+ # @return [YamlEquivalent] parameter matcher.
12
+ #
13
+ # @see Expectation#with
14
+ #
15
+ # @example Actual parameter is YAML equivalent of specified +object+.
11
16
  # object = mock()
12
17
  # object.expects(:method_1).with(yaml_equivalent(1, 2, 3))
13
18
  # object.method_1("--- \n- 1\n- 2\n- 3\n")
14
19
  # # no error raised
15
20
  #
21
+ # @example Actual parameter is not YAML equivalent of specified +object+.
16
22
  # object = mock()
17
23
  # object.expects(:method_1).with(yaml_equivalent(1, 2, 3))
18
24
  # object.method_1("--- \n- 1\n- 2\n")
@@ -21,23 +27,27 @@ module Mocha
21
27
  YamlEquivalent.new(object)
22
28
  end
23
29
 
24
- class YamlEquivalent < Base # :nodoc:
30
+ # Parameter matcher which matches if actual parameter is YAML equivalent of specified object.
31
+ class YamlEquivalent < Base
25
32
 
33
+ # @private
26
34
  def initialize(object)
27
35
  @object = object
28
36
  end
29
37
 
38
+ # @private
30
39
  def matches?(available_parameters)
31
40
  parameter = available_parameters.shift
32
41
  @object == YAML.load(parameter)
33
42
  end
34
43
 
44
+ # @private
35
45
  def mocha_inspect
36
46
  "yaml_equivalent(#{@object.mocha_inspect})"
37
47
  end
38
-
48
+
39
49
  end
40
-
50
+
41
51
  end
42
-
52
+
43
53
  end
@@ -2,13 +2,13 @@ require 'mocha/inspect'
2
2
  require 'mocha/parameter_matchers'
3
3
 
4
4
  module Mocha
5
-
5
+
6
6
  class ParametersMatcher
7
-
7
+
8
8
  def initialize(expected_parameters = [ParameterMatchers::AnyParameters.new], &matching_block)
9
9
  @expected_parameters, @matching_block = expected_parameters, matching_block
10
10
  end
11
-
11
+
12
12
  def match?(actual_parameters = [])
13
13
  if @matching_block
14
14
  return @matching_block.call(*actual_parameters)
@@ -16,22 +16,22 @@ module Mocha
16
16
  return parameters_match?(actual_parameters)
17
17
  end
18
18
  end
19
-
19
+
20
20
  def parameters_match?(actual_parameters)
21
21
  matchers.all? { |matcher| matcher.matches?(actual_parameters) } && (actual_parameters.length == 0)
22
22
  end
23
-
23
+
24
24
  def mocha_inspect
25
25
  signature = matchers.mocha_inspect
26
26
  signature = signature.gsub(/^\[|\]$/, '')
27
27
  signature = signature.gsub(/^\{|\}$/, '') if matchers.length == 1
28
28
  "(#{signature})"
29
29
  end
30
-
30
+
31
31
  def matchers
32
32
  @expected_parameters.map { |parameter| parameter.to_matcher }
33
33
  end
34
-
34
+
35
35
  end
36
36
 
37
- end
37
+ end
@@ -3,26 +3,26 @@ require 'mocha/inspect'
3
3
  module Mocha
4
4
 
5
5
  class PrettyParameters
6
-
6
+
7
7
  def initialize(params)
8
8
  @params = params
9
9
  @params_string = params.mocha_inspect
10
10
  end
11
-
11
+
12
12
  def pretty
13
13
  remove_outer_array_braces!
14
14
  remove_outer_hash_braces!
15
15
  @params_string
16
16
  end
17
-
17
+
18
18
  def remove_outer_array_braces!
19
19
  @params_string = @params_string.gsub(/^\[|\]$/, '')
20
20
  end
21
-
21
+
22
22
  def remove_outer_hash_braces!
23
23
  @params_string = @params_string.gsub(/^\{|\}$/, '') if @params.length == 1
24
24
  end
25
-
25
+
26
26
  end
27
-
28
- end
27
+
28
+ end