mocha 0.9.8 → 0.9.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (111) hide show
  1. data/COPYING.rdoc +3 -0
  2. data/{MIT-LICENSE → MIT-LICENSE.rdoc} +0 -0
  3. data/{README → README.rdoc} +4 -4
  4. data/{RELEASE → RELEASE.rdoc} +18 -0
  5. data/Rakefile +19 -17
  6. data/lib/mocha.rb +1 -0
  7. data/lib/mocha/expectation.rb +37 -34
  8. data/lib/mocha/integration/mini_test.rb +27 -2
  9. data/lib/mocha/integration/mini_test/exception_translation.rb +20 -0
  10. data/lib/mocha/integration/mini_test/version_13.rb +44 -0
  11. data/lib/mocha/integration/mini_test/{version_131_and_above.rb → version_140.rb} +7 -12
  12. data/lib/mocha/integration/mini_test/version_141.rb +56 -0
  13. data/lib/mocha/integration/mini_test/version_142_and_above.rb +56 -0
  14. data/lib/mocha/integration/test_unit.rb +23 -8
  15. data/lib/mocha/integration/test_unit/gem_version_200.rb +3 -0
  16. data/lib/mocha/integration/test_unit/{gem_version_201_and_above.rb → gem_version_201_to_202.rb} +4 -1
  17. data/lib/mocha/integration/test_unit/gem_version_203_to_209.rb +52 -0
  18. data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +3 -0
  19. data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +3 -0
  20. data/lib/mocha/mock.rb +0 -1
  21. data/lib/mocha/module_method.rb +1 -1
  22. data/lib/mocha/options.rb +1 -0
  23. data/lib/mocha/parameter_matchers/base.rb +50 -2
  24. data/test/acceptance/acceptance_test_helper.rb +1 -1
  25. data/test/acceptance/api_test.rb +1 -1
  26. data/test/acceptance/bug_18914_test.rb +1 -1
  27. data/test/acceptance/bug_21465_test.rb +1 -1
  28. data/test/acceptance/bug_21563_test.rb +1 -1
  29. data/test/acceptance/expected_invocation_count_test.rb +1 -1
  30. data/test/acceptance/failure_messages_test.rb +1 -1
  31. data/test/acceptance/minitest_test.rb +128 -124
  32. data/test/acceptance/mocha_example_test.rb +1 -1
  33. data/test/acceptance/mocha_test_result_test.rb +1 -1
  34. data/test/acceptance/mock_test.rb +1 -1
  35. data/test/acceptance/mock_with_initializer_block_test.rb +1 -1
  36. data/test/acceptance/mocked_methods_dispatch_test.rb +1 -1
  37. data/test/acceptance/optional_parameters_test.rb +1 -1
  38. data/test/acceptance/parameter_matcher_test.rb +38 -1
  39. data/test/acceptance/partial_mocks_test.rb +1 -1
  40. data/test/acceptance/return_value_test.rb +1 -1
  41. data/test/acceptance/sequence_test.rb +1 -1
  42. data/test/acceptance/states_test.rb +1 -1
  43. data/test/acceptance/stub_any_instance_method_test.rb +5 -2
  44. data/test/acceptance/stub_class_method_test.rb +5 -2
  45. data/test/acceptance/stub_everything_test.rb +1 -1
  46. data/test/acceptance/stub_instance_method_test.rb +5 -2
  47. data/test/acceptance/stub_module_method_test.rb +3 -3
  48. data/test/acceptance/stub_test.rb +1 -1
  49. data/test/acceptance/stubba_example_test.rb +1 -1
  50. data/test/acceptance/stubba_test.rb +1 -1
  51. data/test/acceptance/stubba_test_result_test.rb +1 -1
  52. data/test/acceptance/stubbing_error_backtrace_test.rb +1 -1
  53. data/test/acceptance/stubbing_method_unnecessarily_test.rb +1 -1
  54. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +5 -5
  55. data/test/acceptance/stubbing_non_existent_class_method_test.rb +5 -5
  56. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +5 -5
  57. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +9 -9
  58. data/test/acceptance/stubbing_non_public_class_method_test.rb +9 -9
  59. data/test/acceptance/stubbing_non_public_instance_method_test.rb +9 -9
  60. data/test/acceptance/stubbing_on_non_mock_object_test.rb +5 -5
  61. data/test/mini_test_result.rb +74 -0
  62. data/test/test_helper.rb +3 -1
  63. data/test/test_runner.rb +25 -11
  64. data/test/unit/any_instance_method_test.rb +1 -1
  65. data/test/unit/array_inspect_test.rb +1 -1
  66. data/test/unit/backtrace_filter_test.rb +1 -1
  67. data/test/unit/cardinality_test.rb +1 -1
  68. data/test/unit/central_test.rb +1 -1
  69. data/test/unit/change_state_side_effect_test.rb +1 -1
  70. data/test/unit/class_method_test.rb +1 -1
  71. data/test/unit/configuration_test.rb +1 -1
  72. data/test/unit/date_time_inspect_test.rb +1 -1
  73. data/test/unit/exception_raiser_test.rb +1 -1
  74. data/test/unit/expectation_list_test.rb +1 -1
  75. data/test/unit/expectation_test.rb +1 -1
  76. data/test/unit/hash_inspect_test.rb +1 -1
  77. data/test/unit/in_state_ordering_constraint_test.rb +1 -1
  78. data/test/unit/metaclass_test.rb +1 -1
  79. data/test/unit/method_matcher_test.rb +1 -1
  80. data/test/unit/mock_test.rb +1 -1
  81. data/test/unit/mockery_test.rb +1 -1
  82. data/test/unit/multiple_yields_test.rb +1 -1
  83. data/test/unit/no_yields_test.rb +1 -1
  84. data/test/unit/object_inspect_test.rb +9 -8
  85. data/test/unit/object_test.rb +1 -1
  86. data/test/unit/parameter_matchers/all_of_test.rb +1 -1
  87. data/test/unit/parameter_matchers/any_of_test.rb +1 -1
  88. data/test/unit/parameter_matchers/anything_test.rb +1 -1
  89. data/test/unit/parameter_matchers/equals_test.rb +1 -1
  90. data/test/unit/parameter_matchers/has_entries_test.rb +1 -1
  91. data/test/unit/parameter_matchers/has_entry_test.rb +1 -1
  92. data/test/unit/parameter_matchers/has_key_test.rb +1 -1
  93. data/test/unit/parameter_matchers/has_value_test.rb +1 -1
  94. data/test/unit/parameter_matchers/includes_test.rb +1 -1
  95. data/test/unit/parameter_matchers/instance_of_test.rb +1 -1
  96. data/test/unit/parameter_matchers/is_a_test.rb +1 -1
  97. data/test/unit/parameter_matchers/kind_of_test.rb +1 -1
  98. data/test/unit/parameter_matchers/not_test.rb +1 -1
  99. data/test/unit/parameter_matchers/regexp_matches_test.rb +1 -1
  100. data/test/unit/parameter_matchers/responds_with_test.rb +1 -1
  101. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +1 -1
  102. data/test/unit/parameters_matcher_test.rb +1 -1
  103. data/test/unit/return_values_test.rb +1 -1
  104. data/test/unit/sequence_test.rb +1 -1
  105. data/test/unit/single_return_value_test.rb +1 -1
  106. data/test/unit/single_yield_test.rb +1 -1
  107. data/test/unit/state_machine_test.rb +1 -1
  108. data/test/unit/string_inspect_test.rb +1 -1
  109. data/test/unit/yield_parameters_test.rb +1 -1
  110. metadata +41 -18
  111. data/COPYING +0 -3
@@ -0,0 +1,3 @@
1
+ Copyright Revieworld Ltd. 2006
2
+
3
+ You may use, copy and redistribute this library under the same terms as {Ruby itself}[http://www.ruby-lang.org/en/LICENSE.txt] or under the {MIT license}[http://mocha.rubyforge.org/files/MIT-LICENSE.html].
File without changes
@@ -1,12 +1,12 @@
1
1
  = Mocha
2
2
 
3
- Mocha is a library for mocking and stubbing using a syntax like that of JMock[http://www.jmock.org].
3
+ Mocha is a library for mocking and stubbing using a syntax like that of {JMock}[http://www.jmock.org].
4
4
 
5
- It can be used with many testing frameworks e.g. Test::Unit[http://www.ruby-doc.org/core/classes/Test/Unit.html], RSpec[http://rspec.info/], test/spec[http://chneukirchen.org/repos/testspec/README], expectations[http://expectations.rubyforge.org/], Dust[http://dust.rubyforge.org/], MiniTest[http://rubyforge.org/projects/bfts] and even JtestR[http://jtestr.codehaus.org/].
5
+ It can be used with many testing frameworks e.g. {Test::Unit}[http://www.ruby-doc.org/core/classes/Test/Unit.html], {RSpec}[http://rspec.info/], {test/spec}[http://chneukirchen.org/repos/testspec/README], {expectations}[http://expectations.rubyforge.org/], {Dust}[http://dust.rubyforge.org/], {MiniTest}[http://rubyforge.org/projects/bfts] and even {JtestR}[http://jtestr.codehaus.org/].
6
6
 
7
7
  Mocha provides a unified, simple and readable syntax for both traditional mocking and partial mocking.
8
8
 
9
- Mocha was harvested from projects at Reevoo[http://www.reevoo.com] by me (James[http://blog.floehopper.org]) and my (then) colleagues Ben[http://www.techbelly.com/], Chris[http://chrisroos.co.uk] and Paul[http://po-ru.com].
9
+ Mocha was harvested from projects at {Reevoo}[http://www.reevoo.com] by me ({James}[http://blog.floehopper.org]) and my (then) colleagues {Ben}[http://www.techbelly.com/], {Chris}[http://chrisroos.co.uk] and {Paul}[http://po-ru.com].
10
10
 
11
11
  == Download and Installation
12
12
 
@@ -14,7 +14,7 @@ Install the gem with the following command...
14
14
 
15
15
  $ gem install mocha
16
16
 
17
- Or install the Rails[http://www.rubyonrails.org] plugin...
17
+ Or install the {Rails}[http://www.rubyonrails.org] plugin...
18
18
 
19
19
  $ script/plugin install git://github.com/floehopper/mocha.git
20
20
 
@@ -1,3 +1,21 @@
1
+ = 0.9.9 (ee3a79db4d52c3339e8acf07505e01236a2b4810)
2
+ * Avoid loading bits of the test-unit gem by accident. This is an attempt at a fix for the problem that James Adam reported [1]. By using 'load' instead of 'require' to detect the version of Test::Unit, we can avoid rubygems trying to load bits of the test-unit gem when it's not wanted. [1] http://floehopper.lighthouseapp.com/projects/22289-mocha/tickets/50#ticket-50-13
3
+ * Fix exception when running rake without test-unit gem. When test-unit gem >=v2.0.0 was installed but the "use_test_unit_gem" MOCHA_OPTIONS was not specified, a "comparison of Fixnum with Hash failed" exception was being raised when running the performance tests. This was because bits of the test-unit gem were being loaded accidentally and a Hash was being incorrectly supplied to the TestRunner.run method.
4
+ * Explicitly require rubygems for running tests via rake using test-unit gem.
5
+ * Handle newer versions of test-unit gem (v2.0.2 to v2.0.9)
6
+ * Handle newer versions of minitest gem (v1.4.0 to v1.6.0)
7
+ * Added warnings about monkey-patching test-unit and minitest to aid debugging. These are enabled by including "debug" in the MOCHA_OPTIONS environment variable. This is now a comma-separated list, so that we can specify multiple options e.g. MOCHA_OPTIONS=debug,use_test_unit_gem
8
+ * Eloy Duran (alloy) made the unit tests run on 1.9.2dev r25249.
9
+ * Eloy Duran (alloy) also improved some MiniTest TestResult code I'd written and got the acceptance tests running on Ruby 1.9 HEAD. There are still 4 failures because for some reason the backtrace line numbers are off by one. And the minitest_test test case does not run when the whole suite is run with MiniTest. These issues still need investigation.
10
+ * Fixed some acceptance tests to run in Ruby 1.9.2 - it's no longer possible to subvert the protection of a method by calling it via Object#send.
11
+ * Fixed "test:performance" rake task so it runs in Ruby 1.9.2.
12
+ * Fix test incorrectly failing under Rubinius 1.0. This test imposed too many constraints. It appears that Object#inspect legitimately calls Object#object_id in Rubinius. But we're only interested in what 'id' methods Mocha::ObjectMethods#mocha_inspect calls. By stubbing Object#inspect we can relax the constraints imposed by the test.
13
+ * Luke Redpath (lukeredpath) added new shorthand "any" and "all" composite parameter matchers using "&" and "|". This provides an alternative syntax for expecting any or all matchers to pass, e.g. foo.expects(:bar).with(equals(1) | equals(2)).
14
+ * Improved documentation for Expectation#raises. A number of people have suggested an extension to the API to cope with custom exceptions that have extra constructor parameters. However, since the arguments supplied to Expectation#raises are just passed on to Kernel#raise, it's possible to pass in an instance of an exception. Thus no change to the API is required, but it does seem worthwhile pointing this out in the docs.
15
+ * Corrected RDoc example for Expectation#never thanks to Red David (reddavis).
16
+ * Improved RDoc including a change suggested by Rohit Arondekar (rohit).
17
+ * Updated gemspec as requested by Sam Woodard (shwoodard).
18
+
1
19
  = 0.9.8 (645024765b2d92018efc511652e1174163844e39)
2
20
  * Fixed bug "NameError raised when using Mocha as a Rails plug-in" - http://floehopper.lighthouseapp.com/projects/22289/tickets/53. Since 0.9.6 the Rails plugin has been broken. See bug report for details. You will need to explicitly load Mocha *after* the test framework has been loaded, e.g. by adding "require 'mocha'" at the bottom of test/test_helper.rb.
3
21
  * Make Mocha::ParameterMatchers#regexp_matches, #includes, #has_value, #has_key more robust. Thanks to Sander Hartlage.
data/Rakefile CHANGED
@@ -3,7 +3,7 @@ require 'rake/gempackagetask'
3
3
  require 'rake/testtask'
4
4
 
5
5
  module Mocha
6
- VERSION = "0.9.8"
6
+ VERSION = "0.9.9"
7
7
  end
8
8
 
9
9
  desc "Run all tests"
@@ -42,8 +42,8 @@ namespace 'test' do
42
42
 
43
43
  desc "Run performance tests"
44
44
  task 'performance' do
45
- require 'test/acceptance/stubba_example_test'
46
- require 'test/acceptance/mocha_example_test'
45
+ require File.join(File.dirname(__FILE__), 'test', 'acceptance', 'stubba_example_test')
46
+ require File.join(File.dirname(__FILE__), 'test', 'acceptance', 'mocha_example_test')
47
47
  iterations = 1000
48
48
  puts "\nBenchmarking with #{iterations} iterations..."
49
49
  [MochaExampleTest, StubbaExampleTest].each do |test_case|
@@ -55,19 +55,21 @@ end
55
55
 
56
56
  def benchmark_test_case(klass, iterations)
57
57
  require 'benchmark'
58
- require 'test/unit/ui/console/testrunner'
59
- begin
60
- require 'test/unit/ui/console/outputlevel'
61
- silent_option = { :output_level => Test::Unit::UI::Console::OutputLevel::SILENT }
62
- rescue LoadError
63
- silent_option = Test::Unit::UI::SILENT
58
+ load 'test/unit/ui/console/testrunner.rb' unless defined?(Test::Unit::UI::Console::TestRunner)
59
+ unless $silent_option
60
+ begin
61
+ load 'test/unit/ui/console/outputlevel.rb' unless defined?(Test::Unit::UI::Console::OutputLevel::SILENT)
62
+ $silent_option = { :output_level => Test::Unit::UI::Console::OutputLevel::SILENT }
63
+ rescue LoadError
64
+ $silent_option = Test::Unit::UI::SILENT
65
+ end
64
66
  end
65
- time = Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, silent_option) } }
67
+ time = Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, $silent_option) } }
66
68
  end
67
69
 
68
70
  desc 'Generate RDoc'
69
71
  Rake::RDocTask.new('rdoc') do |task|
70
- task.main = 'README'
72
+ task.main = 'README.rdoc'
71
73
  task.title = "Mocha #{Mocha::VERSION}"
72
74
  task.rdoc_dir = 'doc'
73
75
  template = File.expand_path(File.join(File.dirname(__FILE__), "templates", "html_with_google_analytics.rb"))
@@ -76,10 +78,10 @@ Rake::RDocTask.new('rdoc') do |task|
76
78
  task.template = template
77
79
  end
78
80
  task.rdoc_files.include(
79
- 'README',
80
- 'RELEASE',
81
- 'COPYING',
82
- 'MIT-LICENSE',
81
+ 'README.rdoc',
82
+ 'RELEASE.rdoc',
83
+ 'COPYING.rdoc',
84
+ 'MIT-LICENSE.rdoc',
83
85
  'agiledox.txt',
84
86
  'lib/mocha/api.rb',
85
87
  'lib/mocha/mock.rb',
@@ -156,8 +158,8 @@ def build_specification(version = Mocha::VERSION)
156
158
  s.rubyforge_project = 'mocha'
157
159
 
158
160
  s.has_rdoc = true
159
- s.extra_rdoc_files = ['README', 'COPYING']
160
- s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README' << '--line-numbers'
161
+ s.extra_rdoc_files = ['README.rdoc', 'COPYING.rdoc']
162
+ s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README.rdoc' << '--line-numbers'
161
163
 
162
164
  s.add_dependency('rake')
163
165
  s.files = FileList['{lib,test,examples}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a
@@ -1,3 +1,4 @@
1
+ require 'mocha/options'
1
2
  require 'mocha_standalone'
2
3
  require 'mocha/configuration'
3
4
  require 'mocha/integration'
@@ -10,10 +10,10 @@ require 'mocha/change_state_side_effect'
10
10
  require 'mocha/cardinality'
11
11
 
12
12
  module Mocha # :nodoc:
13
-
13
+
14
14
  # Methods on expectations returned from Mock#expects, Mock#stubs, Object#expects and Object#stubs.
15
15
  class Expectation
16
-
16
+
17
17
  # :call-seq: times(range) -> expectation
18
18
  #
19
19
  # Modifies expectation so that the number of calls to the expected method must be within a specific +range+.
@@ -42,7 +42,7 @@ module Mocha # :nodoc:
42
42
  @cardinality = Cardinality.times(range)
43
43
  self
44
44
  end
45
-
45
+
46
46
  # :call-seq: twice() -> expectation
47
47
  #
48
48
  # Modifies expectation so that the expected method must be called exactly twice.
@@ -67,7 +67,7 @@ module Mocha # :nodoc:
67
67
  @cardinality = Cardinality.exactly(2)
68
68
  self
69
69
  end
70
-
70
+
71
71
  # :call-seq: once() -> expectation
72
72
  #
73
73
  # Modifies expectation so that the expected method must be called exactly once.
@@ -90,7 +90,7 @@ module Mocha # :nodoc:
90
90
  @cardinality = Cardinality.exactly(1)
91
91
  self
92
92
  end
93
-
93
+
94
94
  # :call-seq: never() -> expectation
95
95
  #
96
96
  # Modifies expectation so that the expected method must never be called.
@@ -101,13 +101,12 @@ module Mocha # :nodoc:
101
101
  #
102
102
  # object = mock()
103
103
  # object.expects(:expected_method).never
104
- # object.expected_method
105
104
  # # => verify succeeds
106
105
  def never
107
106
  @cardinality = Cardinality.exactly(0)
108
107
  self
109
108
  end
110
-
109
+
111
110
  # :call-seq: at_least(minimum_number_of_times) -> expectation
112
111
  #
113
112
  # Modifies expectation so that the expected method must be called at least a +minimum_number_of_times+.
@@ -124,7 +123,7 @@ module Mocha # :nodoc:
124
123
  @cardinality = Cardinality.at_least(minimum_number_of_times)
125
124
  self
126
125
  end
127
-
126
+
128
127
  # :call-seq: at_least_once() -> expectation
129
128
  #
130
129
  # Modifies expectation so that the expected method must be called at least once.
@@ -140,7 +139,7 @@ module Mocha # :nodoc:
140
139
  at_least(1)
141
140
  self
142
141
  end
143
-
142
+
144
143
  # :call-seq: at_most(maximum_number_of_times) -> expectation
145
144
  #
146
145
  # Modifies expectation so that the expected method must be called at most a +maximum_number_of_times+.
@@ -157,7 +156,7 @@ module Mocha # :nodoc:
157
156
  @cardinality = Cardinality.at_most(maximum_number_of_times)
158
157
  self
159
158
  end
160
-
159
+
161
160
  # :call-seq: at_most_once() -> expectation
162
161
  #
163
162
  # Modifies expectation so that the expected method must be called at most once.
@@ -174,7 +173,7 @@ module Mocha # :nodoc:
174
173
  at_most(1)
175
174
  self
176
175
  end
177
-
176
+
178
177
  # :call-seq: with(*expected_parameters, &matching_block) -> expectation
179
178
  #
180
179
  # Modifies expectation so that the expected method must be called with +expected_parameters+.
@@ -204,7 +203,7 @@ module Mocha # :nodoc:
204
203
  @parameters_matcher = ParametersMatcher.new(expected_parameters, &matching_block)
205
204
  self
206
205
  end
207
-
206
+
208
207
  # :call-seq: yields(*parameters) -> expectation
209
208
  #
210
209
  # Modifies expectation so that when the expected method is called, it yields with the specified +parameters+.
@@ -226,7 +225,7 @@ module Mocha # :nodoc:
226
225
  @yield_parameters.add(*parameters)
227
226
  self
228
227
  end
229
-
228
+
230
229
  # :call-seq: multiple_yields(*parameter_groups) -> expectation
231
230
  #
232
231
  # Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified +parameter_groups+.
@@ -248,7 +247,7 @@ module Mocha # :nodoc:
248
247
  @yield_parameters.multiple_add(*parameter_groups)
249
248
  self
250
249
  end
251
-
250
+
252
251
  # :call-seq: returns(value) -> expectation
253
252
  # returns(*values) -> expectation
254
253
  #
@@ -284,13 +283,17 @@ module Mocha # :nodoc:
284
283
  @return_values += ReturnValues.build(*values)
285
284
  self
286
285
  end
287
-
286
+
288
287
  # :call-seq: raises(exception = RuntimeError, message = nil) -> expectation
289
288
  #
290
- # Modifies expectation so that when the expected method is called, it raises the specified +exception+ with the specified +message+.
289
+ # Modifies expectation so that when the expected method is called, it raises the specified +exception+ with the specified +message+ i.e. calls Kernel#raise(exception, message).
291
290
  # object = mock()
292
291
  # object.expects(:expected_method).raises(Exception, 'message')
293
292
  # object.expected_method # => raises exception of class Exception and with message 'message'
293
+ # Note that if you have a custom exception class with extra constructor parameters, you can pass in an instance of the exception (just as you can for Kernel#raise).
294
+ # object = mock()
295
+ # object.expects(:expected_method).raises(MyException.new('message', 1, 2, 3))
296
+ # object.expected_method # => raises the specified instance of MyException
294
297
  # May be called multiple times on the same expectation. Also see Expectation#then.
295
298
  # object = mock()
296
299
  # object.stubs(:expected_method).raises(Exception1).then.raises(Exception2)
@@ -337,7 +340,7 @@ module Mocha # :nodoc:
337
340
  end
338
341
  self
339
342
  end
340
-
343
+
341
344
  # :call-seq: when(state_machine.is(state)) -> exception
342
345
  #
343
346
  # Constrains the expectation to occur only when the +state_machine+ is in the named +state+.
@@ -356,7 +359,7 @@ module Mocha # :nodoc:
356
359
  add_ordering_constraint(InStateOrderingConstraint.new(state_predicate))
357
360
  self
358
361
  end
359
-
362
+
360
363
  # :call-seq: in_sequence(*sequences) -> expectation
361
364
  #
362
365
  # Constrains this expectation so that it must be invoked at the current point in the sequence.
@@ -378,9 +381,9 @@ module Mocha # :nodoc:
378
381
  sequences.each { |sequence| add_in_sequence_ordering_constraint(sequence) }
379
382
  self
380
383
  end
381
-
384
+
382
385
  # :stopdoc:
383
-
386
+
384
387
  attr_reader :backtrace
385
388
 
386
389
  def initialize(mock, expected_method_name, backtrace = nil)
@@ -394,35 +397,35 @@ module Mocha # :nodoc:
394
397
  @yield_parameters = YieldParameters.new
395
398
  @backtrace = backtrace || caller
396
399
  end
397
-
400
+
398
401
  def add_ordering_constraint(ordering_constraint)
399
402
  @ordering_constraints << ordering_constraint
400
403
  end
401
-
404
+
402
405
  def add_in_sequence_ordering_constraint(sequence)
403
406
  sequence.constrain_as_next_in_sequence(self)
404
407
  end
405
-
408
+
406
409
  def add_side_effect(side_effect)
407
410
  @side_effects << side_effect
408
411
  end
409
-
412
+
410
413
  def perform_side_effects
411
414
  @side_effects.each { |side_effect| side_effect.perform }
412
415
  end
413
-
416
+
414
417
  def in_correct_order?
415
418
  @ordering_constraints.all? { |ordering_constraint| ordering_constraint.allows_invocation_now? }
416
419
  end
417
-
420
+
418
421
  def matches_method?(method_name)
419
422
  @method_matcher.match?(method_name)
420
423
  end
421
-
424
+
422
425
  def match?(actual_method_name, *actual_parameters)
423
426
  @method_matcher.match?(actual_method_name) && @parameters_matcher.match?(actual_parameters) && in_correct_order?
424
427
  end
425
-
428
+
426
429
  def invocations_allowed?
427
430
  @cardinality.invocations_allowed?(@invocation_count)
428
431
  end
@@ -430,7 +433,7 @@ module Mocha # :nodoc:
430
433
  def satisfied?
431
434
  @cardinality.satisfied?(@invocation_count)
432
435
  end
433
-
436
+
434
437
  def invoke
435
438
  @invocation_count += 1
436
439
  perform_side_effects()
@@ -446,11 +449,11 @@ module Mocha # :nodoc:
446
449
  assertion_counter.increment if assertion_counter && @cardinality.needs_verifying?
447
450
  @cardinality.verified?(@invocation_count)
448
451
  end
449
-
452
+
450
453
  def used?
451
454
  @cardinality.used?(@invocation_count)
452
455
  end
453
-
456
+
454
457
  def mocha_inspect
455
458
  message = "#{@cardinality.mocha_inspect}, "
456
459
  message << case @invocation_count
@@ -464,13 +467,13 @@ module Mocha # :nodoc:
464
467
  message << "; #{@ordering_constraints.map { |oc| oc.mocha_inspect }.join("; ")}" unless @ordering_constraints.empty?
465
468
  message
466
469
  end
467
-
470
+
468
471
  def method_signature
469
472
  "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}"
470
473
  end
471
-
474
+
472
475
  # :startdoc:
473
-
476
+
474
477
  end
475
478
 
476
479
  end
@@ -2,7 +2,11 @@ require 'mocha/api'
2
2
 
3
3
  if !MiniTest::Unit::TestCase.ancestors.include?(Mocha::API)
4
4
 
5
- require 'mocha/integration/mini_test/version_131_and_above'
5
+ require 'mocha/integration/mini_test/exception_translation'
6
+ require 'mocha/integration/mini_test/version_13'
7
+ require 'mocha/integration/mini_test/version_140'
8
+ require 'mocha/integration/mini_test/version_141'
9
+ require 'mocha/integration/mini_test/version_142_and_above'
6
10
 
7
11
  module MiniTest
8
12
  class Unit
@@ -13,7 +17,28 @@ if !MiniTest::Unit::TestCase.ancestors.include?(Mocha::API)
13
17
  alias_method :run_before_mocha, :run
14
18
  remove_method :run
15
19
 
16
- include Mocha::Integration::MiniTest::Version131AndAbove
20
+ mini_test_version = begin
21
+ MiniTest::Unit::VERSION
22
+ rescue LoadError
23
+ 'unknown'
24
+ end
25
+
26
+ $stderr.puts "Detected MiniTest version: #{mini_test_version}" if $options['debug']
27
+
28
+ if (mini_test_version >= '1.3.0') && (mini_test_version <= '1.3.1')
29
+ include Mocha::Integration::MiniTest::Version13
30
+ elsif (mini_test_version == '1.4.0')
31
+ include Mocha::Integration::MiniTest::Version140
32
+ elsif (mini_test_version == '1.4.1')
33
+ include Mocha::Integration::MiniTest::Version141
34
+ elsif (mini_test_version >= '1.4.2') && (mini_test_version <= '1.6.0')
35
+ include Mocha::Integration::MiniTest::Version142AndAbove
36
+ elsif (mini_test_version > '1.6.0')
37
+ $stderr.puts "*** MiniTest integration has not been verified but patching anyway ***" if $options['debug']
38
+ include Mocha::Integration::MiniTest::Version142AndAbove
39
+ else
40
+ $stderr.puts "*** No Mocha integration for MiniTest version ***" if $options['debug']
41
+ end
17
42
 
18
43
  end
19
44
  end
@@ -0,0 +1,20 @@
1
+ require 'mocha/expectation_error'
2
+
3
+ module Mocha
4
+
5
+ module Integration
6
+
7
+ module MiniTest
8
+
9
+ def self.translate(exception)
10
+ return exception unless exception.kind_of?(::Mocha::ExpectationError)
11
+ translated_exception = ::MiniTest::Assertion.new(exception.message)
12
+ translated_exception.set_backtrace(exception.backtrace)
13
+ translated_exception
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+
20
+ end
@@ -0,0 +1,44 @@
1
+ require 'mocha/integration/mini_test/assertion_counter'
2
+
3
+ module Mocha
4
+
5
+ module Integration
6
+
7
+ module MiniTest
8
+
9
+ module Version13
10
+ def self.included(mod)
11
+ $stderr.puts "Monkey patching MiniTest v1.3" if $options['debug']
12
+ end
13
+ def run runner
14
+ assertion_counter = AssertionCounter.new(self)
15
+ result = '.'
16
+ begin
17
+ begin
18
+ @passed = nil
19
+ self.setup
20
+ self.__send__ self.name
21
+ mocha_verify(assertion_counter)
22
+ @passed = true
23
+ rescue Exception => e
24
+ @passed = false
25
+ result = runner.puke(self.class, self.name, Mocha::Integration::MiniTest.translate(e))
26
+ ensure
27
+ begin
28
+ self.teardown
29
+ rescue Exception => e
30
+ result = runner.puke(self.class, self.name, Mocha::Integration::MiniTest.translate(e))
31
+ end
32
+ end
33
+ ensure
34
+ mocha_teardown
35
+ end
36
+ result
37
+ end
38
+ end
39
+
40
+ end
41
+
42
+ end
43
+
44
+ end