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
@@ -2,69 +2,69 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha'
3
3
 
4
4
  class StatesTest < Test::Unit::TestCase
5
-
5
+
6
6
  include AcceptanceTest
7
-
7
+
8
8
  def setup
9
9
  setup_acceptance_test
10
10
  end
11
-
11
+
12
12
  def teardown
13
13
  teardown_acceptance_test
14
14
  end
15
-
15
+
16
16
  def test_should_constrain_expectations_to_occur_within_a_given_state
17
17
  test_result = run_as_test do
18
18
  mock = mock()
19
19
  readiness = states('readiness')
20
-
20
+
21
21
  mock.stubs(:first).when(readiness.is('ready'))
22
22
  mock.stubs(:second).then(readiness.is('ready'))
23
-
23
+
24
24
  mock.first
25
25
  end
26
26
  assert_failed(test_result)
27
27
  end
28
-
28
+
29
29
  def test_should_allow_expectations_to_occur_in_correct_state
30
30
  test_result = run_as_test do
31
31
  mock = mock()
32
32
  readiness = states('readiness')
33
-
33
+
34
34
  mock.stubs(:first).when(readiness.is('ready'))
35
35
  mock.stubs(:second).then(readiness.is('ready'))
36
-
36
+
37
37
  mock.second
38
38
  mock.first
39
39
  end
40
40
  assert_passed(test_result)
41
41
  end
42
-
42
+
43
43
  def test_should_be_able_to_start_in_a_specific_state
44
44
  test_result = run_as_test do
45
45
  mock = mock()
46
46
  readiness = states('readiness')
47
-
47
+
48
48
  mock.stubs(:first).when(readiness.is('ready'))
49
-
49
+
50
50
  readiness.starts_as('ready')
51
51
  mock.first
52
52
  end
53
53
  assert_passed(test_result)
54
54
  end
55
-
55
+
56
56
  def test_should_switch_state_when_method_raises_an_exception
57
57
  test_result = run_as_test do
58
58
  mock = mock()
59
59
  readiness = states('readiness')
60
-
60
+
61
61
  mock.expects(:first).raises().then(readiness.is('ready'))
62
62
  mock.expects(:second).when(readiness.is('ready'))
63
-
63
+
64
64
  mock.first rescue nil
65
65
  mock.second
66
66
  end
67
67
  assert_passed(test_result)
68
68
  end
69
-
70
- end
69
+
70
+ end
@@ -4,15 +4,15 @@ require 'mocha'
4
4
  class StubAnyInstanceMethodTest < Test::Unit::TestCase
5
5
 
6
6
  include AcceptanceTest
7
-
7
+
8
8
  def setup
9
9
  setup_acceptance_test
10
10
  end
11
-
11
+
12
12
  def teardown
13
13
  teardown_acceptance_test
14
14
  end
15
-
15
+
16
16
  def test_should_stub_method_within_test
17
17
  klass = Class.new do
18
18
  def my_instance_method
@@ -26,7 +26,7 @@ class StubAnyInstanceMethodTest < Test::Unit::TestCase
26
26
  end
27
27
  assert_passed(test_result)
28
28
  end
29
-
29
+
30
30
  def test_should_leave_stubbed_public_method_unchanged_after_test
31
31
  klass = Class.new do
32
32
  def my_instance_method
@@ -40,7 +40,7 @@ class StubAnyInstanceMethodTest < Test::Unit::TestCase
40
40
  assert instance.public_methods(false).any? { |m| m.to_s == 'my_instance_method' }
41
41
  assert_equal :original_return_value, instance.my_instance_method
42
42
  end
43
-
43
+
44
44
  def test_should_leave_stubbed_protected_method_unchanged_after_test
45
45
  klass = Class.new do
46
46
  def my_instance_method
@@ -58,7 +58,7 @@ class StubAnyInstanceMethodTest < Test::Unit::TestCase
58
58
  assert instance.protected_methods(false).any? { |m| m.to_s == 'my_instance_method' }
59
59
  assert_equal :original_return_value, instance.my_unprotected_instance_method
60
60
  end
61
-
61
+
62
62
  def test_should_leave_stubbed_private_method_unchanged_after_test
63
63
  klass = Class.new do
64
64
  def my_instance_method
@@ -73,7 +73,7 @@ class StubAnyInstanceMethodTest < Test::Unit::TestCase
73
73
  assert instance.private_methods(false).any? { |m| m.to_s == 'my_instance_method' }
74
74
  assert_equal :original_return_value, instance.send(:my_instance_method)
75
75
  end
76
-
76
+
77
77
  def test_should_reset_expectations_after_test
78
78
  klass = Class.new do
79
79
  def my_instance_method
@@ -86,7 +86,7 @@ class StubAnyInstanceMethodTest < Test::Unit::TestCase
86
86
 
87
87
  assert_equal 0, klass.any_instance.mocha.__expectations__.length
88
88
  end
89
-
89
+
90
90
  def test_should_be_able_to_stub_a_superclass_method
91
91
  superklass = Class.new do
92
92
  def my_superclass_method
@@ -104,7 +104,7 @@ class StubAnyInstanceMethodTest < Test::Unit::TestCase
104
104
  assert !klass.public_methods(false).any? { |m| m.to_s == 'my_superclass_method' }
105
105
  assert_equal :original_return_value, instance.my_superclass_method
106
106
  end
107
-
107
+
108
108
  def test_should_be_able_to_stub_method_if_ruby18_public_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
109
109
  ruby18_klass = Class.new do
110
110
  class << self
@@ -119,7 +119,7 @@ class StubAnyInstanceMethodTest < Test::Unit::TestCase
119
119
  end
120
120
  assert_passed(test_result)
121
121
  end
122
-
122
+
123
123
  def test_should_be_able_to_stub_method_if_ruby19_public_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
124
124
  ruby19_klass = Class.new do
125
125
  class << self
@@ -134,7 +134,7 @@ class StubAnyInstanceMethodTest < Test::Unit::TestCase
134
134
  end
135
135
  assert_passed(test_result)
136
136
  end
137
-
137
+
138
138
  def test_should_be_able_to_stub_method_if_ruby18_protected_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
139
139
  ruby18_klass = Class.new do
140
140
  class << self
@@ -149,7 +149,7 @@ class StubAnyInstanceMethodTest < Test::Unit::TestCase
149
149
  end
150
150
  assert_passed(test_result)
151
151
  end
152
-
152
+
153
153
  def test_should_be_able_to_stub_method_if_ruby19_protected_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
154
154
  ruby19_klass = Class.new do
155
155
  class << self
@@ -164,7 +164,7 @@ class StubAnyInstanceMethodTest < Test::Unit::TestCase
164
164
  end
165
165
  assert_passed(test_result)
166
166
  end
167
-
167
+
168
168
  def test_should_be_able_to_stub_method_if_ruby18_private_instance_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
169
169
  ruby18_klass = Class.new do
170
170
  class << self
@@ -27,7 +27,7 @@ class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Test::Unit::Tes
27
27
  end
28
28
  assert_passed(test_result)
29
29
  end
30
-
30
+
31
31
  def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
32
32
  ruby19_klass = Class.new do
33
33
  class << self
@@ -42,7 +42,7 @@ class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Test::Unit::Tes
42
42
  end
43
43
  assert_passed(test_result)
44
44
  end
45
-
45
+
46
46
  def test_should_be_able_to_stub_method_if_ruby18_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
47
47
  ruby18_klass = Class.new do
48
48
  class << self
@@ -57,7 +57,7 @@ class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Test::Unit::Tes
57
57
  end
58
58
  assert_passed(test_result)
59
59
  end
60
-
60
+
61
61
  def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
62
62
  ruby19_klass = Class.new do
63
63
  class << self
@@ -72,7 +72,7 @@ class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Test::Unit::Tes
72
72
  end
73
73
  assert_passed(test_result)
74
74
  end
75
-
75
+
76
76
  def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
77
77
  ruby18_klass = Class.new do
78
78
  class << self
@@ -87,7 +87,7 @@ class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Test::Unit::Tes
87
87
  end
88
88
  assert_passed(test_result)
89
89
  end
90
-
90
+
91
91
  def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
92
92
  ruby19_klass = Class.new do
93
93
  class << self
@@ -102,5 +102,5 @@ class StubClassMethodDefinedOnActiveRecordAssociationProxyTest < Test::Unit::Tes
102
102
  end
103
103
  assert_passed(test_result)
104
104
  end
105
-
106
- end
105
+
106
+ end
@@ -2,17 +2,17 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha'
3
3
 
4
4
  class StubEverythingTest < Test::Unit::TestCase
5
-
5
+
6
6
  include AcceptanceTest
7
-
7
+
8
8
  def setup
9
9
  setup_acceptance_test
10
10
  end
11
-
11
+
12
12
  def teardown
13
13
  teardown_acceptance_test
14
14
  end
15
-
15
+
16
16
  def test_should_build_stub_and_explicitly_add_an_expectation
17
17
  test_result = run_as_test do
18
18
  foo = stub_everything()
@@ -53,4 +53,4 @@ class StubEverythingTest < Test::Unit::TestCase
53
53
  assert_passed(test_result)
54
54
  end
55
55
 
56
- end
56
+ end
@@ -67,4 +67,4 @@ class StubInstanceMethodDefinedOnSingletonClassTest < Test::Unit::TestCase
67
67
  assert_equal :original_return_value, instance.send(:my_singleton_method)
68
68
  end
69
69
 
70
- end
70
+ end
@@ -1,18 +1,18 @@
1
1
  require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha'
3
-
3
+
4
4
  class StubModuleMethodTest < Test::Unit::TestCase
5
5
 
6
6
  include AcceptanceTest
7
-
7
+
8
8
  def setup
9
9
  setup_acceptance_test
10
10
  end
11
-
11
+
12
12
  def teardown
13
13
  teardown_acceptance_test
14
14
  end
15
-
15
+
16
16
  def test_should_stub_method_within_test
17
17
  mod = Module.new { def self.my_module_method; :original_return_value; end }
18
18
  test_result = run_as_test do
@@ -21,7 +21,7 @@ class StubModuleMethodTest < Test::Unit::TestCase
21
21
  end
22
22
  assert_passed(test_result)
23
23
  end
24
-
24
+
25
25
  def test_should_leave_stubbed_public_method_unchanged_after_test
26
26
  mod = Module.new { class << self; def my_module_method; :original_return_value; end; public :my_module_method; end }
27
27
  run_as_test do
@@ -30,7 +30,7 @@ class StubModuleMethodTest < Test::Unit::TestCase
30
30
  assert mod.public_methods(false).any? { |m| m.to_s == 'my_module_method' }
31
31
  assert_equal :original_return_value, mod.my_module_method
32
32
  end
33
-
33
+
34
34
  def test_should_leave_stubbed_protected_method_unchanged_after_test
35
35
  mod = Module.new { class << self; def my_module_method; :original_return_value; end; protected :my_module_method; def my_unprotected_module_method; my_module_method; end; end }
36
36
  run_as_test do
@@ -39,7 +39,7 @@ class StubModuleMethodTest < Test::Unit::TestCase
39
39
  assert mod.protected_methods(false).any? { |m| m.to_s == 'my_module_method' }
40
40
  assert_equal :original_return_value, mod.my_unprotected_module_method
41
41
  end
42
-
42
+
43
43
  def test_should_leave_stubbed_private_method_unchanged_after_test
44
44
  mod = Module.new { class << self; def my_module_method; :original_return_value; end; private :my_module_method; end }
45
45
  run_as_test do
@@ -48,15 +48,15 @@ class StubModuleMethodTest < Test::Unit::TestCase
48
48
  assert mod.private_methods(false).any? { |m| m.to_s == 'my_module_method' }
49
49
  assert_equal :original_return_value, mod.send(:my_module_method)
50
50
  end
51
-
51
+
52
52
  def test_should_reset_expectations_after_test
53
53
  mod = Module.new { def self.my_module_method; :original_return_value; end }
54
54
  run_as_test do
55
55
  mod.stubs(:my_module_method)
56
56
  end
57
57
  assert_equal 0, mod.mocha.__expectations__.length
58
- end
59
-
58
+ end
59
+
60
60
  def test_should_be_able_to_stub_a_superclass_method
61
61
  supermod = Module.new { def self.my_superclass_method; :original_return_value; end }
62
62
  mod = Module.new { include supermod }
@@ -69,7 +69,7 @@ class StubModuleMethodTest < Test::Unit::TestCase
69
69
  assert !mod.public_methods(false).any? { |m| m.to_s == 'my_superclass_method' }
70
70
  assert_equal :original_return_value, supermod.my_superclass_method
71
71
  end
72
-
72
+
73
73
  def test_should_be_able_to_stub_method_if_ruby18_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
74
74
  ruby18_mod = Module.new do
75
75
  class << self
@@ -84,7 +84,7 @@ class StubModuleMethodTest < Test::Unit::TestCase
84
84
  end
85
85
  assert_passed(test_result)
86
86
  end
87
-
87
+
88
88
  def test_should_be_able_to_stub_method_if_ruby19_public_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
89
89
  ruby19_mod = Module.new do
90
90
  class << self
@@ -99,7 +99,7 @@ class StubModuleMethodTest < Test::Unit::TestCase
99
99
  end
100
100
  assert_passed(test_result)
101
101
  end
102
-
102
+
103
103
  def test_should_be_able_to_stub_method_if_ruby_18_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
104
104
  ruby18_mod = Module.new do
105
105
  class << self
@@ -114,7 +114,7 @@ class StubModuleMethodTest < Test::Unit::TestCase
114
114
  end
115
115
  assert_passed(test_result)
116
116
  end
117
-
117
+
118
118
  def test_should_be_able_to_stub_method_if_ruby19_protected_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
119
119
  ruby19_mod = Module.new do
120
120
  class << self
@@ -129,7 +129,7 @@ class StubModuleMethodTest < Test::Unit::TestCase
129
129
  end
130
130
  assert_passed(test_result)
131
131
  end
132
-
132
+
133
133
  def test_should_be_able_to_stub_method_if_ruby18_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
134
134
  ruby18_mod = Module.new do
135
135
  class << self
@@ -144,7 +144,7 @@ class StubModuleMethodTest < Test::Unit::TestCase
144
144
  end
145
145
  assert_passed(test_result)
146
146
  end
147
-
147
+
148
148
  def test_should_be_able_to_stub_method_if_ruby19_private_methods_include_method_but_method_does_not_actually_exist_like_active_record_association_proxy
149
149
  ruby19_mod = Module.new do
150
150
  class << self
@@ -159,5 +159,5 @@ class StubModuleMethodTest < Test::Unit::TestCase
159
159
  end
160
160
  assert_passed(test_result)
161
161
  end
162
-
162
+
163
163
  end
@@ -2,17 +2,17 @@ require File.expand_path('../acceptance_test_helper', __FILE__)
2
2
  require 'mocha'
3
3
 
4
4
  class StubTest < Test::Unit::TestCase
5
-
5
+
6
6
  include AcceptanceTest
7
-
7
+
8
8
  def setup
9
9
  setup_acceptance_test
10
10
  end
11
-
11
+
12
12
  def teardown
13
13
  teardown_acceptance_test
14
14
  end
15
-
15
+
16
16
  def test_should_build_stub_and_explicitly_add_an_expectation
17
17
  test_result = run_as_test do
18
18
  foo = stub()
@@ -49,4 +49,4 @@ class StubTest < Test::Unit::TestCase
49
49
  assert_passed(test_result)
50
50
  end
51
51
 
52
- end
52
+ end
@@ -2,86 +2,86 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
  require 'mocha'
3
3
 
4
4
  class Widget
5
-
5
+
6
6
  def model
7
7
  'original_model'
8
8
  end
9
-
9
+
10
10
  class << self
11
-
11
+
12
12
  def find(options)
13
13
  []
14
14
  end
15
-
15
+
16
16
  def create(attributes)
17
17
  Widget.new
18
18
  end
19
-
19
+
20
20
  end
21
-
21
+
22
22
  end
23
23
 
24
24
  module Thingy
25
-
25
+
26
26
  def self.wotsit
27
27
  :hoojamaflip
28
28
  end
29
-
29
+
30
30
  end
31
31
 
32
32
  class StubbaExampleTest < Test::Unit::TestCase
33
-
33
+
34
34
  def test_should_stub_instance_method
35
35
  widget = Widget.new
36
36
  widget.expects(:model).returns('different_model')
37
37
  assert_equal 'different_model', widget.model
38
38
  end
39
-
39
+
40
40
  def test_should_stub_module_method
41
41
  should_stub_module_method
42
42
  end
43
-
43
+
44
44
  def test_should_stub_module_method_again
45
45
  should_stub_module_method
46
46
  end
47
-
47
+
48
48
  def test_should_stub_class_method
49
49
  should_stub_class_method
50
50
  end
51
-
51
+
52
52
  def test_should_stub_class_method_again
53
53
  should_stub_class_method
54
54
  end
55
-
55
+
56
56
  def test_should_stub_instance_method_on_any_instance_of_a_class
57
57
  should_stub_instance_method_on_any_instance_of_a_class
58
58
  end
59
-
59
+
60
60
  def test_should_stub_instance_method_on_any_instance_of_a_class_again
61
61
  should_stub_instance_method_on_any_instance_of_a_class
62
62
  end
63
-
63
+
64
64
  def test_should_stub_two_different_class_methods
65
65
  should_stub_two_different_class_methods
66
66
  end
67
-
67
+
68
68
  def test_should_stub_two_different_class_methods_again
69
69
  should_stub_two_different_class_methods
70
70
  end
71
-
71
+
72
72
  private
73
-
73
+
74
74
  def should_stub_module_method
75
75
  Thingy.expects(:wotsit).returns(:dooda)
76
76
  assert_equal :dooda, Thingy.wotsit
77
77
  end
78
-
78
+
79
79
  def should_stub_class_method
80
80
  widgets = [Widget.new]
81
81
  Widget.expects(:find).with(:all).returns(widgets)
82
82
  assert_equal widgets, Widget.find(:all)
83
- end
84
-
83
+ end
84
+
85
85
  def should_stub_two_different_class_methods
86
86
  found_widgets = [Widget.new]
87
87
  created_widget = Widget.new
@@ -90,7 +90,7 @@ class StubbaExampleTest < Test::Unit::TestCase
90
90
  assert_equal found_widgets, Widget.find(:all)
91
91
  assert_equal created_widget, Widget.create(:model => 'wombat')
92
92
  end
93
-
93
+
94
94
  def should_stub_instance_method_on_any_instance_of_a_class
95
95
  Widget.any_instance.expects(:model).at_least_once.returns('another_model')
96
96
  widget_1 = Widget.new
@@ -99,4 +99,4 @@ class StubbaExampleTest < Test::Unit::TestCase
99
99
  assert_equal 'another_model', widget_2.model
100
100
  end
101
101
 
102
- end
102
+ end