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
@@ -42,4 +42,4 @@ class ThrowTest < Test::Unit::TestCase
42
42
  assert_passed(test_result)
43
43
  end
44
44
 
45
- end
45
+ end
@@ -12,4 +12,4 @@ module DeprecationDisabler
12
12
  end
13
13
  end
14
14
 
15
- end
15
+ end
@@ -1,20 +1,20 @@
1
1
  class ExecutionPoint
2
-
2
+
3
3
  attr_reader :backtrace
4
4
 
5
5
  def self.current
6
6
  new(caller)
7
7
  end
8
-
8
+
9
9
  def initialize(backtrace)
10
10
  @backtrace = backtrace
11
11
  end
12
-
12
+
13
13
  def file_name
14
14
  return "unknown" unless @backtrace && @backtrace.first
15
15
  /\A(.*?):\d+/.match(@backtrace.first)[1]
16
16
  end
17
-
17
+
18
18
  def line_number
19
19
  return "unknown" unless @backtrace && @backtrace.first
20
20
  Integer(/\A.*?:(\d+)/.match(@backtrace.first)[1])
@@ -24,13 +24,13 @@ class ExecutionPoint
24
24
  return false unless other.is_a?(ExecutionPoint)
25
25
  (file_name == other.file_name) and (line_number == other.line_number)
26
26
  end
27
-
27
+
28
28
  def to_s
29
29
  "file: #{file_name}; line: #{line_number}"
30
30
  end
31
-
31
+
32
32
  def inspect
33
33
  to_s
34
34
  end
35
-
35
+
36
36
  end
@@ -21,4 +21,4 @@ end
21
21
 
22
22
  class Object
23
23
  include Mocha::ObjectMethods
24
- end
24
+ end
@@ -3,30 +3,30 @@ require 'test/unit/testcase'
3
3
  require 'minitest/unit'
4
4
 
5
5
  class MiniTestResult
6
-
6
+
7
7
  FAILURE_PATTERN = %r{(Failure)\:\n([^\(]+)\(([^\)]+)\) \[([^\]]+)\]\:\n(.*)\n}m
8
8
  ERROR_PATTERN = %r{(Error)\:\n([^\(]+)\(([^\)]+)\)\:\n(.+?)\n}m
9
-
9
+
10
10
  def self.parse_failure(raw)
11
11
  matches = FAILURE_PATTERN.match(raw)
12
12
  return nil unless matches
13
13
  Failure.new(matches[2], matches[3], [matches[4]], matches[5])
14
14
  end
15
-
15
+
16
16
  def self.parse_error(raw)
17
17
  matches = ERROR_PATTERN.match(raw)
18
18
  return nil unless matches
19
19
  backtrace = raw.gsub(ERROR_PATTERN, '').split("\n").map(&:strip)
20
20
  Error.new(matches[2], matches[3], matches[4], backtrace)
21
21
  end
22
-
22
+
23
23
  class Failure
24
24
  attr_reader :method, :test_case, :location, :message
25
25
  def initialize(method, test_case, location, message)
26
26
  @method, @test_case, @location, @message = method, test_case, location, message
27
27
  end
28
28
  end
29
-
29
+
30
30
  class Error
31
31
  class Exception
32
32
  attr_reader :message, :backtrace
@@ -34,50 +34,50 @@ class MiniTestResult
34
34
  @message, @backtrace = message, location
35
35
  end
36
36
  end
37
-
37
+
38
38
  attr_reader :method, :test_case, :exception
39
39
  def initialize(method, test_case, message, backtrace)
40
40
  @method, @test_case, @exception = method, test_case, Exception.new(message, backtrace)
41
41
  end
42
42
  end
43
-
44
- def initialize(runner, test)
45
- @runner, @test = runner, test
43
+
44
+ def initialize(runner, tests)
45
+ @runner, @tests = runner, tests
46
46
  end
47
-
47
+
48
48
  def failure_count
49
49
  @runner.failures
50
50
  end
51
-
51
+
52
52
  def assertion_count
53
- @test._assertions
53
+ @tests.inject(0) { |total, test| total + test._assertions }
54
54
  end
55
-
55
+
56
56
  def error_count
57
57
  @runner.errors
58
58
  end
59
-
59
+
60
60
  def passed?
61
- @test.passed?
61
+ @tests.all?(&:passed?)
62
62
  end
63
-
63
+
64
64
  def failures
65
65
  @runner.report.map { |puked| MiniTestResult.parse_failure(puked) }.compact
66
66
  end
67
-
67
+
68
68
  def errors
69
69
  @runner.report.map { |puked| MiniTestResult.parse_error(puked) }.compact
70
70
  end
71
-
71
+
72
72
  def failure_messages
73
73
  failures.map(&:message)
74
74
  end
75
-
75
+
76
76
  def failure_message_lines
77
77
  failure_messages.map { |message| message.split("\n") }.flatten
78
78
  end
79
-
79
+
80
80
  def error_messages
81
81
  errors.map { |e| e.exception.message }
82
82
  end
83
- end
83
+ end
@@ -1,13 +1,13 @@
1
1
  class SimpleCounter
2
-
2
+
3
3
  attr_reader :count
4
-
4
+
5
5
  def initialize
6
6
  @count = 0
7
7
  end
8
-
8
+
9
9
  def increment
10
10
  @count += 1
11
11
  end
12
-
13
- end
12
+
13
+ end
@@ -8,4 +8,4 @@ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit'))
8
8
  $:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'unit', 'parameter_matchers'))
9
9
  $:.unshift File.expand_path(File.join(File.dirname(__FILE__), 'acceptance'))
10
10
 
11
- require 'test/unit'
11
+ require 'test/unit'
@@ -4,40 +4,38 @@ if defined?(MiniTest)
4
4
  require 'mocha/integration/mini_test'
5
5
  require File.expand_path('../mini_test_result', __FILE__)
6
6
  else
7
- require 'test/unit/testresult'
7
+ require File.expand_path('../test_unit_result', __FILE__)
8
8
  end
9
9
 
10
10
  module TestRunner
11
- def run_as_test(test_result = nil, &block)
12
- test_class = Class.new(Test::Unit::TestCase) do
13
- define_method(:test_me, &block)
11
+ def run_as_test(&block)
12
+ run_as_tests(block)
13
+ end
14
+
15
+ def run_as_tests(*procs)
16
+ tests = procs.map do |proc|
17
+ test_class = Class.new(Test::Unit::TestCase) do
18
+ define_method(:test_me, proc)
19
+ end
20
+ test_class.new(:test_me)
14
21
  end
15
- test = test_class.new(:test_me)
16
-
22
+
17
23
  if defined?(Test::Unit::TestResult)
18
- test_result ||= Test::Unit::TestResult.new
19
- test.run(test_result) {}
20
- class << test_result
21
- attr_reader :failures, :errors
22
- def failure_messages
23
- failures.map { |failure| failure.message }
24
- end
25
- def failure_message_lines
26
- failure_messages.map { |message| message.split("\n") }.flatten
27
- end
28
- def error_messages
29
- errors.map { |error| error.message }
30
- end
24
+ test_result = TestUnitResult.build_test_result
25
+ tests.each do |test|
26
+ test.run(test_result) {}
31
27
  end
32
28
  else
33
29
  runner = MiniTest::Unit.new
34
- test.run(runner)
35
- test_result = MiniTestResult.new(runner, test)
30
+ tests.each do |test|
31
+ test.run(runner)
32
+ end
33
+ test_result = MiniTestResult.new(runner, tests)
36
34
  end
37
-
35
+
38
36
  test_result
39
37
  end
40
-
38
+
41
39
  def assert_passed(test_result)
42
40
  flunk "Test failed unexpectedly with message: #{test_result.failures}" if test_result.failure_count > 0
43
41
  flunk "Test failed unexpectedly with message: #{test_result.errors}" if test_result.error_count > 0
@@ -47,4 +45,4 @@ module TestRunner
47
45
  flunk "Test passed unexpectedly" if test_result.passed?
48
46
  end
49
47
 
50
- end
48
+ end
@@ -0,0 +1,20 @@
1
+ require 'test/unit/testresult'
2
+
3
+ class TestUnitResult
4
+ def self.build_test_result
5
+ test_result = Test::Unit::TestResult.new
6
+ class << test_result
7
+ attr_reader :failures, :errors
8
+ def failure_messages
9
+ failures.map { |failure| failure.message }
10
+ end
11
+ def failure_message_lines
12
+ failure_messages.map { |message| message.split("\n") }.flatten
13
+ end
14
+ def error_messages
15
+ errors.map { |error| error.message }
16
+ end
17
+ end
18
+ test_result
19
+ end
20
+ end
@@ -4,70 +4,66 @@ require 'mocha/mock'
4
4
  require 'mocha/any_instance_method'
5
5
 
6
6
  class AnyInstanceMethodTest < Test::Unit::TestCase
7
-
7
+
8
8
  include Mocha
9
-
9
+
10
10
  def test_should_hide_original_method
11
11
  klass = Class.new { def method_x; end }
12
12
  method = AnyInstanceMethod.new(klass, :method_x)
13
- hidden_method_x = method.hidden_method.to_sym
14
-
13
+
15
14
  method.hide_original_method
16
-
17
- assert klass.method_defined?(hidden_method_x)
15
+
16
+ assert_equal false, klass.method_defined?(:method_x)
18
17
  end
19
-
20
- def test_should_not_hide_original_method_if_it_is_not_defined
18
+
19
+ def test_should_not_raise_error_hiding_method_that_isnt_defined
21
20
  klass = Class.new
22
21
  method = AnyInstanceMethod.new(klass, :method_x)
23
- hidden_method_x = method.hidden_method.to_sym
24
-
25
- method.hide_original_method
26
-
27
- assert_equal false, klass.method_defined?(hidden_method_x)
22
+
23
+ assert_nothing_raised { method.hide_original_method }
28
24
  end
29
-
25
+
30
26
  def test_should_define_a_new_method
31
- klass = Class.new { def method_x; end }
27
+ klass = Class.new { def method_x; end }
32
28
  method = AnyInstanceMethod.new(klass, :method_x)
33
29
  mocha = build_mock
34
30
  mocha.expects(:method_x).with(:param1, :param2).returns(:result)
35
31
  any_instance = Object.new
36
32
  any_instance.define_instance_method(:mocha) { mocha }
37
33
  klass.define_instance_method(:any_instance) { any_instance }
38
-
34
+
39
35
  method.hide_original_method
40
36
  method.define_new_method
41
37
 
42
38
  instance = klass.new
43
39
  result = instance.method_x(:param1, :param2)
44
-
40
+
45
41
  assert_equal :result, result
46
42
  assert mocha.__verified__?
47
43
  end
48
44
 
49
45
  def test_should_restore_original_method
50
- klass = Class.new { def method_x; end }
46
+ klass = Class.new { def method_x; :original_result; end }
51
47
  method = AnyInstanceMethod.new(klass, :method_x)
52
- hidden_method_x = method.hidden_method.to_sym
53
- klass.send(:define_method, hidden_method_x, Proc.new { :original_result })
54
-
48
+
49
+ method.hide_original_method
50
+ method.define_new_method
55
51
  method.remove_new_method
56
52
  method.restore_original_method
57
-
53
+
58
54
  instance = klass.new
59
- assert_equal :original_result, instance.method_x
60
- assert !klass.method_defined?(hidden_method_x)
55
+ assert instance.respond_to?(:method_x)
56
+ assert_equal :original_result, instance.method_x
61
57
  end
62
58
 
63
- def test_should_not_restore_original_method_if_hidden_method_not_defined
59
+ def test_should_not_restore_original_method_if_none_was_defined_in_first_place
64
60
  klass = Class.new { def method_x; :new_result; end }
65
61
  method = AnyInstanceMethod.new(klass, :method_x)
66
-
62
+
67
63
  method.restore_original_method
68
-
64
+
69
65
  instance = klass.new
70
- assert_equal :new_result, instance.method_x
66
+ assert_equal :new_result, instance.method_x
71
67
  end
72
68
 
73
69
  def test_should_call_remove_new_method
@@ -80,9 +76,9 @@ class AnyInstanceMethodTest < Test::Unit::TestCase
80
76
  method.replace_instance_method(:restore_original_method) { }
81
77
  method.define_instance_accessor(:remove_called)
82
78
  method.replace_instance_method(:remove_new_method) { self.remove_called = true }
83
-
79
+
84
80
  method.unstub
85
-
81
+
86
82
  assert method.remove_called
87
83
  end
88
84
 
@@ -96,9 +92,9 @@ class AnyInstanceMethodTest < Test::Unit::TestCase
96
92
  method.replace_instance_method(:remove_new_method) { }
97
93
  method.define_instance_accessor(:restore_called)
98
94
  method.replace_instance_method(:restore_original_method) { self.restore_called = true }
99
-
95
+
100
96
  method.unstub
101
-
97
+
102
98
  assert method.restore_called
103
99
  end
104
100
 
@@ -2,15 +2,15 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
  require 'mocha/inspect'
3
3
 
4
4
  class ArrayInspectTest < Test::Unit::TestCase
5
-
5
+
6
6
  def test_should_use_inspect
7
7
  array = [1, 2]
8
8
  assert_equal array.inspect, array.mocha_inspect
9
9
  end
10
-
10
+
11
11
  def test_should_use_mocha_inspect_on_each_item
12
12
  array = [1, 2, "chris"]
13
13
  assert_equal "[1, 2, 'chris']", array.mocha_inspect
14
14
  end
15
-
15
+
16
16
  end
@@ -2,9 +2,9 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
  require 'mocha/backtrace_filter'
3
3
 
4
4
  class BacktraceFilterTest < Test::Unit::TestCase
5
-
5
+
6
6
  include Mocha
7
-
7
+
8
8
  def test_should_exclude_mocha_locations_from_backtrace
9
9
  mocha_lib = "/username/workspace/mocha_wibble/lib/"
10
10
  backtrace = [ mocha_lib + 'exclude/me/1', mocha_lib + 'exclude/me/2', '/keep/me', mocha_lib + 'exclude/me/3']
@@ -15,5 +15,5 @@ class BacktraceFilterTest < Test::Unit::TestCase
15
15
  def test_should_determine_path_for_mocha_lib_directory
16
16
  assert_match Regexp.new("/lib/$"), BacktraceFilter::LIB_DIRECTORY
17
17
  end
18
-
18
+
19
19
  end
@@ -2,9 +2,9 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
  require 'mocha/cardinality'
3
3
 
4
4
  class CardinalityTest < Test::Unit::TestCase
5
-
5
+
6
6
  include Mocha
7
-
7
+
8
8
  def test_should_allow_invocations_if_invocation_count_has_not_yet_reached_maximum
9
9
  cardinality = Cardinality.new(2, 3)
10
10
  assert cardinality.invocations_allowed?(0)
@@ -12,7 +12,7 @@ class CardinalityTest < Test::Unit::TestCase
12
12
  assert cardinality.invocations_allowed?(2)
13
13
  assert !cardinality.invocations_allowed?(3)
14
14
  end
15
-
15
+
16
16
  def test_should_be_satisfied_if_invocations_so_far_have_reached_required_threshold
17
17
  cardinality = Cardinality.new(2, 3)
18
18
  assert !cardinality.satisfied?(0)
@@ -20,27 +20,27 @@ class CardinalityTest < Test::Unit::TestCase
20
20
  assert cardinality.satisfied?(2)
21
21
  assert cardinality.satisfied?(3)
22
22
  end
23
-
23
+
24
24
  def test_should_describe_cardinality
25
25
  assert_equal 'allowed any number of times', Cardinality.at_least(0).mocha_inspect
26
-
26
+
27
27
  assert_equal 'expected at most once', Cardinality.at_most(1).mocha_inspect
28
28
  assert_equal 'expected at most twice', Cardinality.at_most(2).mocha_inspect
29
29
  assert_equal 'expected at most 3 times', Cardinality.at_most(3).mocha_inspect
30
-
30
+
31
31
  assert_equal 'expected at least once', Cardinality.at_least(1).mocha_inspect
32
32
  assert_equal 'expected at least twice', Cardinality.at_least(2).mocha_inspect
33
33
  assert_equal 'expected at least 3 times', Cardinality.at_least(3).mocha_inspect
34
-
34
+
35
35
  assert_equal 'expected never', Cardinality.exactly(0).mocha_inspect
36
36
  assert_equal 'expected exactly once', Cardinality.exactly(1).mocha_inspect
37
37
  assert_equal 'expected exactly twice', Cardinality.exactly(2).mocha_inspect
38
38
  assert_equal 'expected exactly 3 times', Cardinality.times(3).mocha_inspect
39
-
39
+
40
40
  assert_equal 'expected between 2 and 4 times', Cardinality.times(2..4).mocha_inspect
41
41
  assert_equal 'expected between 1 and 3 times', Cardinality.times(1..3).mocha_inspect
42
42
  end
43
-
43
+
44
44
  def test_should_need_verifying
45
45
  assert Cardinality.exactly(2).needs_verifying?
46
46
  assert Cardinality.at_least(3).needs_verifying?
@@ -48,9 +48,9 @@ class CardinalityTest < Test::Unit::TestCase
48
48
  assert Cardinality.times(4).needs_verifying?
49
49
  assert Cardinality.times(2..4).needs_verifying?
50
50
  end
51
-
51
+
52
52
  def test_should_not_need_verifying
53
53
  assert_equal false, Cardinality.at_least(0).needs_verifying?
54
54
  end
55
-
56
- end
55
+
56
+ end