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
@@ -5,47 +5,47 @@ require 'mocha/mock'
5
5
  require 'method_definer'
6
6
 
7
7
  class CentralTest < Test::Unit::TestCase
8
-
8
+
9
9
  include Mocha
10
-
10
+
11
11
  def test_should_start_with_empty_stubba_methods
12
12
  stubba = Central.new
13
-
13
+
14
14
  assert_equal [], stubba.stubba_methods
15
15
  end
16
-
16
+
17
17
  def test_should_stub_method_if_not_already_stubbed
18
18
  method = build_mock
19
19
  method.expects(:stub)
20
20
  stubba = Central.new
21
-
21
+
22
22
  stubba.stub(method)
23
-
23
+
24
24
  assert method.__verified__?
25
25
  end
26
-
26
+
27
27
  def test_should_not_stub_method_if_already_stubbed
28
28
  method = build_mock
29
29
  method.stubs(:matches?).returns(true)
30
30
  method.expects(:stub).times(0)
31
31
  stubba = Central.new
32
32
  stubba.stubba_methods = [method]
33
-
33
+
34
34
  stubba.stub(method)
35
-
35
+
36
36
  assert method.__verified__?
37
37
  end
38
-
38
+
39
39
  def test_should_record_method
40
40
  method = build_mock
41
41
  method.expects(:stub)
42
42
  stubba = Central.new
43
-
43
+
44
44
  stubba.stub(method)
45
-
45
+
46
46
  assert_equal [method], stubba.stubba_methods
47
47
  end
48
-
48
+
49
49
  def test_should_unstub_specified_method
50
50
  stubba = Central.new
51
51
  method_1 = build_mock
@@ -56,11 +56,11 @@ class CentralTest < Test::Unit::TestCase
56
56
  stubba.stubba_methods = [method_1, method_2]
57
57
 
58
58
  stubba.unstub(method_2)
59
-
59
+
60
60
  assert_equal [method_1], stubba.stubba_methods
61
61
  assert method_2.__verified__?
62
62
  end
63
-
63
+
64
64
  def test_should_not_unstub_specified_method_if_not_already_stubbed
65
65
  stubba = Central.new
66
66
  method_1 = build_mock
@@ -70,11 +70,11 @@ class CentralTest < Test::Unit::TestCase
70
70
  stubba.stubba_methods = [method_1]
71
71
 
72
72
  stubba.unstub(method_2)
73
-
73
+
74
74
  assert_equal [method_1], stubba.stubba_methods
75
75
  assert method_2.__verified__?
76
76
  end
77
-
77
+
78
78
  def test_should_unstub_all_methods
79
79
  stubba = Central.new
80
80
  method_1 = build_mock
@@ -86,7 +86,7 @@ class CentralTest < Test::Unit::TestCase
86
86
  stubba.stubba_methods = [method_1, method_2]
87
87
 
88
88
  stubba.unstub_all
89
-
89
+
90
90
  assert_equal [], stubba.stubba_methods
91
91
  assert method_1.__verified__?
92
92
  assert method_2.__verified__?
@@ -3,39 +3,39 @@ require File.expand_path('../../test_helper', __FILE__)
3
3
  require 'mocha/change_state_side_effect'
4
4
 
5
5
  class ChangeStateSideEffectTest < Test::Unit::TestCase
6
-
6
+
7
7
  include Mocha
8
-
8
+
9
9
  class FakeState
10
-
10
+
11
11
  attr_reader :active
12
12
  attr_writer :description
13
-
13
+
14
14
  def activate
15
15
  @active = true
16
16
  end
17
-
17
+
18
18
  def mocha_inspect
19
19
  @description
20
20
  end
21
-
21
+
22
22
  end
23
-
23
+
24
24
  def test_should_activate_the_given_state
25
25
  state = FakeState.new
26
26
  side_effect = ChangeStateSideEffect.new(state)
27
-
27
+
28
28
  side_effect.perform
29
-
29
+
30
30
  assert state.active
31
31
  end
32
-
32
+
33
33
  def test_should_describe_itself_in_terms_of_the_activated_state
34
34
  state = FakeState.new
35
35
  state.description = 'the-new-state'
36
36
  side_effect = ChangeStateSideEffect.new(state)
37
-
37
+
38
38
  assert_equal 'then the-new-state', side_effect.mocha_inspect
39
39
  end
40
-
40
+
41
41
  end
@@ -5,126 +5,68 @@ require 'mocha/mock'
5
5
  require 'mocha/class_method'
6
6
 
7
7
  class ClassMethodTest < Test::Unit::TestCase
8
-
9
- include Mocha
10
8
 
11
- def test_should_provide_hidden_version_of_method_name_starting_with_prefix
12
- method = ClassMethod.new(nil, :original_method_name)
13
- assert_match(/^__stubba__/, method.hidden_method.to_s)
14
- end
15
-
16
- def test_should_provide_hidden_version_of_method_name_ending_with_suffix
17
- method = ClassMethod.new(nil, :original_method_name)
18
- assert_match(/__stubba__$/, method.hidden_method.to_s)
19
- end
20
-
21
- def test_should_provide_hidden_version_of_method_name_including_original_method_name
22
- method = ClassMethod.new(nil, :original_method_name)
23
- assert_match(/original_method_name/, method.hidden_method.to_s)
24
- end
25
-
26
- def test_should_provide_hidden_version_of_method_name_substituting_question_mark
27
- method = ClassMethod.new(nil, :question_mark?)
28
- assert_no_match(/\?/, method.hidden_method.to_s)
29
- assert_match(/question_mark_substituted_character_63/, method.hidden_method.to_s)
30
- end
31
-
32
- def test_should_provide_hidden_version_of_method_name_substituting_exclamation_mark
33
- method = ClassMethod.new(nil, :exclamation_mark!)
34
- assert_no_match(/!/, method.hidden_method.to_s)
35
- assert_match(/exclamation_mark_substituted_character_33/, method.hidden_method.to_s)
36
- end
37
-
38
- def test_should_provide_hidden_version_of_method_name_substituting_equals_sign
39
- method = ClassMethod.new(nil, :equals_sign=)
40
- assert_no_match(/\=/, method.hidden_method.to_s)
41
- assert_match(/equals_sign_substituted_character_61/, method.hidden_method.to_s)
42
- end
9
+ include Mocha
43
10
 
44
- def test_should_provide_hidden_version_of_method_name_substituting_brackets
45
- method = ClassMethod.new(nil, :[])
46
- assert_no_match(/\[\]/, method.hidden_method.to_s)
47
- assert_match(/substituted_character_91__substituted_character_93/, method.hidden_method.to_s)
48
- end
49
-
50
- def test_should_provide_hidden_version_of_method_name_substituting_plus_sign
51
- method = ClassMethod.new(nil, :+)
52
- assert_no_match(/\+/, method.hidden_method.to_s)
53
- assert_match(/substituted_character_43/, method.hidden_method.to_s)
54
- end
55
-
56
11
  def test_should_hide_original_method
57
12
  klass = Class.new { def self.method_x; end }
58
13
  method = ClassMethod.new(klass, :method_x)
59
- hidden_method_x = method.hidden_method
60
-
61
- method.hide_original_method
62
14
 
63
- assert klass.respond_to?(hidden_method_x)
64
- end
65
-
66
- def test_should_respond_to_original_method_name_after_original_method_has_been_hidden
67
- klass = Class.new { def self.original_method_name; end }
68
- method = ClassMethod.new(klass, :original_method_name)
69
-
70
15
  method.hide_original_method
71
16
 
72
- assert klass.respond_to?(:original_method_name)
17
+ assert_equal false, klass.respond_to?(:method_x)
73
18
  end
74
-
75
- def test_should_not_hide_original_method_if_method_not_defined
19
+
20
+ def test_should_not_raise_error_hiding_method_that_isnt_defined
76
21
  klass = Class.new
77
22
  method = ClassMethod.new(klass, :method_x)
78
- hidden_method_x = method.hidden_method
79
-
80
- method.hide_original_method
81
23
 
82
- assert_equal false, klass.respond_to?(hidden_method_x)
24
+ assert_nothing_raised { method.hide_original_method }
83
25
  end
84
-
26
+
85
27
  def test_should_define_a_new_method_which_should_call_mocha_method_missing
86
28
  klass = Class.new { def self.method_x; end }
87
29
  mocha = build_mock
88
30
  klass.define_instance_method(:mocha) { mocha }
89
31
  mocha.expects(:method_x).with(:param1, :param2).returns(:result)
90
32
  method = ClassMethod.new(klass, :method_x)
91
-
33
+
92
34
  method.hide_original_method
93
35
  method.define_new_method
94
36
  result = klass.method_x(:param1, :param2)
95
-
37
+
96
38
  assert_equal :result, result
97
39
  assert mocha.__verified__?
98
40
  end
99
-
41
+
100
42
  def test_should_remove_new_method
101
43
  klass = Class.new { def self.method_x; end }
102
44
  method = ClassMethod.new(klass, :method_x)
103
-
45
+
104
46
  method.remove_new_method
105
-
47
+
106
48
  assert_equal false, klass.respond_to?(:method_x)
107
49
  end
108
50
 
109
51
  def test_should_restore_original_method
110
- klass = Class.new { def self.method_x; end }
52
+ klass = Class.new { def self.method_x; :original_result; end }
111
53
  method = ClassMethod.new(klass, :method_x)
112
- hidden_method_x = method.hidden_method.to_sym
113
- klass.define_instance_method(hidden_method_x) { :original_result }
114
54
 
55
+ method.hide_original_method
56
+ method.define_new_method
115
57
  method.remove_new_method
116
58
  method.restore_original_method
117
-
118
- assert_equal :original_result, klass.method_x
119
- assert_equal false, klass.respond_to?(hidden_method_x)
59
+
60
+ assert klass.respond_to?(:method_x)
61
+ assert_equal :original_result, klass.method_x
120
62
  end
121
63
 
122
- def test_should_not_restore_original_method_if_hidden_method_is_not_defined
64
+ def test_should_not_restore_original_method_if_none_was_defined_in_first_place
123
65
  klass = Class.new { def self.method_x; :new_result; end }
124
66
  method = ClassMethod.new(klass, :method_x)
125
67
 
126
68
  method.restore_original_method
127
-
69
+
128
70
  assert_equal :new_result, klass.method_x
129
71
  end
130
72
 
@@ -134,9 +76,9 @@ class ClassMethodTest < Test::Unit::TestCase
134
76
  method.hide_original_method
135
77
  method.define_instance_accessor(:hide_called)
136
78
  method.replace_instance_method(:hide_original_method) { self.hide_called = true }
137
-
79
+
138
80
  method.stub
139
-
81
+
140
82
  assert method.hide_called
141
83
  end
142
84
 
@@ -145,12 +87,12 @@ class ClassMethodTest < Test::Unit::TestCase
145
87
  method = ClassMethod.new(klass, :method_x)
146
88
  method.define_instance_accessor(:define_called)
147
89
  method.replace_instance_method(:define_new_method) { self.define_called = true }
148
-
90
+
149
91
  method.stub
150
-
92
+
151
93
  assert method.define_called
152
94
  end
153
-
95
+
154
96
  def test_should_call_remove_new_method
155
97
  klass = Class.new { def self.method_x; end }
156
98
  method = ClassMethod.new(klass, :method_x)
@@ -158,9 +100,9 @@ class ClassMethodTest < Test::Unit::TestCase
158
100
  klass.define_instance_method(:mocha) { mocha }
159
101
  method.define_instance_accessor(:remove_called)
160
102
  method.replace_instance_method(:remove_new_method) { self.remove_called = true }
161
-
103
+
162
104
  method.unstub
163
-
105
+
164
106
  assert method.remove_called
165
107
  end
166
108
 
@@ -171,9 +113,9 @@ class ClassMethodTest < Test::Unit::TestCase
171
113
  method = ClassMethod.new(klass, :method_x)
172
114
  method.define_instance_accessor(:restore_called)
173
115
  method.replace_instance_method(:restore_original_method) { self.restore_called = true }
174
-
116
+
175
117
  method.unstub
176
-
118
+
177
119
  assert method.restore_called
178
120
  end
179
121
 
@@ -184,7 +126,7 @@ class ClassMethodTest < Test::Unit::TestCase
184
126
  mocha = Class.new { class << self; attr_accessor :unstub_method; end; def self.unstub(method); self.unstub_method = method; end; }
185
127
  mocha.define_instance_method(:any_expectations?) { true }
186
128
  method.replace_instance_method(:mock) { mocha }
187
-
129
+
188
130
  method.unstub
189
131
  assert_equal mocha.unstub_method, :method_x
190
132
  end
@@ -214,7 +156,7 @@ class ClassMethodTest < Test::Unit::TestCase
214
156
  method = ClassMethod.new(stubbee, :method_name)
215
157
  assert_equal stubbee.mocha, method.mock
216
158
  end
217
-
159
+
218
160
  def test_should_not_match_if_other_object_has_a_different_class
219
161
  class_method = ClassMethod.new(Object.new, :method)
220
162
  other_object = Object.new
@@ -228,21 +170,21 @@ class ClassMethodTest < Test::Unit::TestCase
228
170
  class_method_2 = ClassMethod.new(stubbee_2, :method)
229
171
  assert !class_method_1.matches?(class_method_2)
230
172
  end
231
-
173
+
232
174
  def test_should_not_match_if_other_class_method_has_different_method
233
175
  stubbee = Object.new
234
176
  class_method_1 = ClassMethod.new(stubbee, :method_1)
235
177
  class_method_2 = ClassMethod.new(stubbee, :method_2)
236
178
  assert !class_method_1.matches?(class_method_2)
237
179
  end
238
-
180
+
239
181
  def test_should_match_if_other_class_method_has_same_stubbee_and_same_method_so_no_attempt_is_made_to_stub_a_method_twice
240
182
  stubbee = Object.new
241
183
  class_method_1 = ClassMethod.new(stubbee, :method)
242
184
  class_method_2 = ClassMethod.new(stubbee, :method)
243
185
  assert class_method_1.matches?(class_method_2)
244
186
  end
245
-
187
+
246
188
  def test_should_match_if_other_class_method_has_same_stubbee_and_same_method_but_stubbee_equal_method_lies_like_active_record_association_proxy
247
189
  stubbee = Class.new do
248
190
  def equal?(other); false; end
@@ -2,20 +2,20 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
  require 'mocha/inspect'
3
3
 
4
4
  class DateTimeInspectTest < Test::Unit::TestCase
5
-
5
+
6
6
  def test_should_use_include_date_in_seconds
7
7
  time = Time.now
8
8
  assert_equal "#{time.inspect} (#{time.to_f} secs)", time.mocha_inspect
9
9
  end
10
-
10
+
11
11
  def test_should_use_to_s_for_date
12
12
  date = Date.new(2006, 1, 1)
13
13
  assert_equal date.to_s, date.mocha_inspect
14
14
  end
15
-
15
+
16
16
  def test_should_use_to_s_for_datetime
17
17
  datetime = DateTime.new(2006, 1, 1)
18
18
  assert_equal datetime.to_s, datetime.mocha_inspect
19
19
  end
20
-
20
+
21
21
  end
@@ -4,9 +4,9 @@ require 'mocha/exception_raiser'
4
4
  require 'timeout'
5
5
 
6
6
  class ExceptionRaiserTest < Test::Unit::TestCase
7
-
7
+
8
8
  include Mocha
9
-
9
+
10
10
  def test_should_raise_exception_with_specified_class_and_default_message
11
11
  exception_class = Class.new(StandardError)
12
12
  raiser = ExceptionRaiser.new(exception_class, nil)
@@ -20,14 +20,14 @@ class ExceptionRaiserTest < Test::Unit::TestCase
20
20
  exception = assert_raises(exception_class) { raiser.evaluate }
21
21
  assert_equal 'message', exception.message
22
22
  end
23
-
23
+
24
24
  def test_should_raise_exception_instance
25
25
  exception_class = Class.new(StandardError)
26
26
  raiser = ExceptionRaiser.new(exception_class.new('message'), nil)
27
27
  exception = assert_raises(exception_class) { raiser.evaluate }
28
28
  assert_equal 'message', exception.message
29
29
  end
30
-
30
+
31
31
  def test_should_raise_interrupt_exception_with_default_message_so_it_works_in_ruby_1_8_6
32
32
  raiser = ExceptionRaiser.new(Interrupt, nil)
33
33
  assert_raises(Interrupt) { raiser.evaluate }
@@ -39,4 +39,4 @@ class ExceptionRaiserTest < Test::Unit::TestCase
39
39
  assert_raises(exception_class) { raiser.evaluate }
40
40
  end
41
41
 
42
- end
42
+ end
@@ -5,15 +5,15 @@ require 'set'
5
5
  require 'method_definer'
6
6
 
7
7
  class ExpectationListTest < Test::Unit::TestCase
8
-
8
+
9
9
  include Mocha
10
-
10
+
11
11
  def test_should_return_added_expectation
12
12
  expectation_list = ExpectationList.new
13
13
  expectation = Expectation.new(nil, :my_method)
14
14
  assert_same expectation, expectation_list.add(expectation)
15
15
  end
16
-
16
+
17
17
  def test_should_find_matching_expectation
18
18
  expectation_list = ExpectationList.new
19
19
  expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
@@ -36,7 +36,7 @@ class ExpectationListTest < Test::Unit::TestCase
36
36
  assert_nil expectation_list.match(:method_one, :argument3, :argument4)
37
37
  assert_same expectation3, expectation_list.match(:method_two)
38
38
  end
39
-
39
+
40
40
  def test_should_find_most_recent_matching_expectation
41
41
  expectation_list = ExpectationList.new
42
42
  expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
@@ -45,7 +45,7 @@ class ExpectationListTest < Test::Unit::TestCase
45
45
  expectation_list.add(expectation2)
46
46
  assert_same expectation2, expectation_list.match(:my_method, :argument1, :argument2)
47
47
  end
48
-
48
+
49
49
  def test_should_find_matching_expectation_allowing_invocation
50
50
  expectation_list = ExpectationList.new
51
51
  expectation1 = Expectation.new(nil, :my_method).with(:argument1, :argument2)
@@ -56,7 +56,7 @@ class ExpectationListTest < Test::Unit::TestCase
56
56
  expectation_list.add(expectation2)
57
57
  assert_same expectation1, expectation_list.match_allowing_invocation(:my_method, :argument1, :argument2)
58
58
  end
59
-
59
+
60
60
  def test_should_find_most_recent_matching_expectation_allowing_invocation
61
61
  expectation_list = ExpectationList.new
62
62
  expectation1 = Expectation.new(nil, :my_method)
@@ -67,5 +67,5 @@ class ExpectationListTest < Test::Unit::TestCase
67
67
  expectation_list.add(expectation2)
68
68
  assert_same expectation1, expectation_list.match_allowing_invocation(:my_method)
69
69
  end
70
-
70
+
71
71
  end