mocha-macruby 0.9.8.20100129120100 → 0.9.9.20101102121900

Sign up to get free protection for your applications and to get access to all the features.
Files changed (113) hide show
  1. data/COPYING.rdoc +3 -0
  2. data/{MIT-LICENSE → MIT-LICENSE.rdoc} +0 -0
  3. data/{README → README.rdoc} +7 -7
  4. data/{RELEASE → RELEASE.rdoc} +18 -0
  5. data/Rakefile +44 -28
  6. data/lib/mocha.rb +1 -0
  7. data/lib/mocha/class_method.rb +1 -3
  8. data/lib/mocha/expectation.rb +37 -34
  9. data/lib/mocha/integration/mini_test.rb +32 -4
  10. data/lib/mocha/integration/mini_test/exception_translation.rb +20 -0
  11. data/lib/mocha/integration/mini_test/{version_131_and_above.rb → version_13.rb} +7 -13
  12. data/lib/mocha/integration/mini_test/version_140.rb +52 -0
  13. data/lib/mocha/integration/mini_test/version_141.rb +56 -0
  14. data/lib/mocha/integration/mini_test/version_142_and_above.rb +47 -0
  15. data/lib/mocha/integration/test_unit.rb +23 -8
  16. data/lib/mocha/integration/test_unit/gem_version_200.rb +3 -0
  17. data/lib/mocha/integration/test_unit/{gem_version_201_and_above.rb → gem_version_201_to_202.rb} +4 -1
  18. data/lib/mocha/integration/test_unit/gem_version_203_to_209.rb +52 -0
  19. data/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb +3 -0
  20. data/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb +3 -0
  21. data/lib/mocha/mock.rb +33 -18
  22. data/lib/mocha/module_method.rb +1 -1
  23. data/lib/mocha/object.rb +144 -160
  24. data/lib/mocha/options.rb +1 -0
  25. data/lib/mocha/parameter_matchers/base.rb +50 -2
  26. data/test/acceptance/acceptance_test_helper.rb +1 -1
  27. data/test/acceptance/api_test.rb +1 -1
  28. data/test/acceptance/bug_18914_test.rb +1 -1
  29. data/test/acceptance/bug_21465_test.rb +1 -1
  30. data/test/acceptance/bug_21563_test.rb +1 -1
  31. data/test/acceptance/expected_invocation_count_test.rb +1 -1
  32. data/test/acceptance/failure_messages_test.rb +1 -1
  33. data/test/acceptance/minitest_test.rb +128 -124
  34. data/test/acceptance/mocha_example_test.rb +1 -1
  35. data/test/acceptance/mocha_test_result_test.rb +1 -1
  36. data/test/acceptance/mock_test.rb +1 -1
  37. data/test/acceptance/mock_with_initializer_block_test.rb +1 -1
  38. data/test/acceptance/mocked_methods_dispatch_test.rb +1 -1
  39. data/test/acceptance/optional_parameters_test.rb +1 -1
  40. data/test/acceptance/parameter_matcher_test.rb +38 -1
  41. data/test/acceptance/partial_mocks_test.rb +1 -1
  42. data/test/acceptance/return_value_test.rb +1 -1
  43. data/test/acceptance/sequence_test.rb +1 -1
  44. data/test/acceptance/states_test.rb +1 -1
  45. data/test/acceptance/stub_any_instance_method_test.rb +5 -2
  46. data/test/acceptance/stub_class_method_test.rb +5 -2
  47. data/test/acceptance/stub_everything_test.rb +1 -1
  48. data/test/acceptance/stub_instance_method_test.rb +5 -2
  49. data/test/acceptance/stub_module_method_test.rb +3 -3
  50. data/test/acceptance/stub_test.rb +1 -1
  51. data/test/acceptance/stubba_example_test.rb +1 -1
  52. data/test/acceptance/stubba_test.rb +1 -1
  53. data/test/acceptance/stubba_test_result_test.rb +1 -1
  54. data/test/acceptance/stubbing_error_backtrace_test.rb +1 -1
  55. data/test/acceptance/stubbing_method_unnecessarily_test.rb +1 -1
  56. data/test/acceptance/stubbing_non_existent_any_instance_method_test.rb +5 -5
  57. data/test/acceptance/stubbing_non_existent_class_method_test.rb +5 -5
  58. data/test/acceptance/stubbing_non_existent_instance_method_test.rb +5 -5
  59. data/test/acceptance/stubbing_non_public_any_instance_method_test.rb +9 -9
  60. data/test/acceptance/stubbing_non_public_class_method_test.rb +9 -9
  61. data/test/acceptance/stubbing_non_public_instance_method_test.rb +9 -9
  62. data/test/acceptance/stubbing_on_non_mock_object_test.rb +5 -5
  63. data/test/mini_test_result.rb +74 -0
  64. data/test/test_helper.rb +3 -1
  65. data/test/test_runner.rb +25 -11
  66. data/test/unit/any_instance_method_test.rb +1 -1
  67. data/test/unit/array_inspect_test.rb +1 -1
  68. data/test/unit/backtrace_filter_test.rb +1 -1
  69. data/test/unit/cardinality_test.rb +1 -1
  70. data/test/unit/central_test.rb +1 -1
  71. data/test/unit/change_state_side_effect_test.rb +1 -1
  72. data/test/unit/class_method_test.rb +2 -2
  73. data/test/unit/configuration_test.rb +1 -1
  74. data/test/unit/date_time_inspect_test.rb +1 -1
  75. data/test/unit/exception_raiser_test.rb +1 -1
  76. data/test/unit/expectation_list_test.rb +1 -1
  77. data/test/unit/expectation_test.rb +1 -1
  78. data/test/unit/hash_inspect_test.rb +1 -1
  79. data/test/unit/in_state_ordering_constraint_test.rb +1 -1
  80. data/test/unit/metaclass_test.rb +1 -1
  81. data/test/unit/method_matcher_test.rb +1 -1
  82. data/test/unit/mock_test.rb +16 -14
  83. data/test/unit/mockery_test.rb +1 -1
  84. data/test/unit/multiple_yields_test.rb +1 -1
  85. data/test/unit/no_yields_test.rb +1 -1
  86. data/test/unit/object_inspect_test.rb +10 -9
  87. data/test/unit/object_test.rb +11 -10
  88. data/test/unit/parameter_matchers/all_of_test.rb +1 -1
  89. data/test/unit/parameter_matchers/any_of_test.rb +1 -1
  90. data/test/unit/parameter_matchers/anything_test.rb +1 -1
  91. data/test/unit/parameter_matchers/equals_test.rb +1 -1
  92. data/test/unit/parameter_matchers/has_entries_test.rb +1 -1
  93. data/test/unit/parameter_matchers/has_entry_test.rb +1 -1
  94. data/test/unit/parameter_matchers/has_key_test.rb +1 -1
  95. data/test/unit/parameter_matchers/has_value_test.rb +1 -1
  96. data/test/unit/parameter_matchers/includes_test.rb +5 -5
  97. data/test/unit/parameter_matchers/instance_of_test.rb +2 -2
  98. data/test/unit/parameter_matchers/is_a_test.rb +1 -1
  99. data/test/unit/parameter_matchers/kind_of_test.rb +1 -1
  100. data/test/unit/parameter_matchers/not_test.rb +1 -1
  101. data/test/unit/parameter_matchers/regexp_matches_test.rb +1 -1
  102. data/test/unit/parameter_matchers/responds_with_test.rb +1 -1
  103. data/test/unit/parameter_matchers/yaml_equivalent_test.rb +1 -1
  104. data/test/unit/parameters_matcher_test.rb +1 -1
  105. data/test/unit/return_values_test.rb +1 -1
  106. data/test/unit/sequence_test.rb +1 -1
  107. data/test/unit/single_return_value_test.rb +1 -1
  108. data/test/unit/single_yield_test.rb +1 -1
  109. data/test/unit/state_machine_test.rb +1 -1
  110. data/test/unit/string_inspect_test.rb +1 -1
  111. data/test/unit/yield_parameters_test.rb +1 -1
  112. metadata +43 -19
  113. data/COPYING +0 -3
data/COPYING.rdoc ADDED
@@ -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
 
@@ -26,9 +26,9 @@ Or download Mocha...
26
26
 
27
27
  == Examples
28
28
 
29
- * Quick Start - {Usage Examples}[link:examples/misc.html]
30
- * Traditional mocking - {Star Trek Example}[link:examples/mocha.html]
31
- * Setting expectations on real classes - {Order Example}[link:examples/stubba.html]
29
+ * Quick Start - {Usage Examples}[http://mocha.rubyforge.org/examples/misc.html]
30
+ * Traditional mocking - {Star Trek Example}[http://mocha.rubyforge.org/examples/mocha.html]
31
+ * Setting expectations on real classes - {Order Example}[http://mocha.rubyforge.org/examples/stubba.html]
32
32
  * More examples on {Floehopper's Blog}[http://blog.floehopper.org]
33
33
  * {Mailing List Archives}[http://groups.google.com/group/mocha-developer]
34
34
 
@@ -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,31 +3,45 @@ 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"
10
- task 'default' => ['test:units', 'test:acceptance', 'test:performance']
10
+ task 'default' => 'test'
11
+
12
+ desc "Run all tests"
13
+ task 'test' => ['test:units', 'test:acceptance', 'test:performance']
11
14
 
12
15
  namespace 'test' do
13
16
 
14
17
  unit_tests = FileList['test/unit/**/*_test.rb']
15
18
  acceptance_tests = FileList['test/acceptance/*_test.rb']
16
19
 
20
+ # This is just a quick workaround a problem with the testtask in MacRuby
21
+ def macruby_run_tests(tests)
22
+ sh "macruby -I test -r #{tests.join(" -r ")} -e ''"
23
+ end
24
+
17
25
  desc "Run unit tests"
18
- Rake::TestTask.new('units') do |t|
19
- t.libs << 'test'
20
- t.test_files = unit_tests
21
- t.verbose = true
22
- t.warning = true
26
+ # Rake::TestTask.new('units') do |t|
27
+ # t.libs << 'test'
28
+ # t.test_files = unit_tests
29
+ # t.verbose = true
30
+ # t.warning = true
31
+ # end
32
+ task :units do
33
+ macruby_run_tests unit_tests
23
34
  end
24
35
 
25
36
  desc "Run acceptance tests"
26
- Rake::TestTask.new('acceptance') do |t|
27
- t.libs << 'test'
28
- t.test_files = acceptance_tests
29
- t.verbose = true
30
- t.warning = true
37
+ # Rake::TestTask.new('acceptance') do |t|
38
+ # t.libs << 'test'
39
+ # t.test_files = acceptance_tests
40
+ # t.verbose = true
41
+ # t.warning = true
42
+ # end
43
+ task :acceptance do
44
+ macruby_run_tests acceptance_tests
31
45
  end
32
46
 
33
47
  # require 'rcov/rcovtask'
@@ -42,8 +56,8 @@ namespace 'test' do
42
56
 
43
57
  desc "Run performance tests"
44
58
  task 'performance' do
45
- require 'test/acceptance/stubba_example_test'
46
- require 'test/acceptance/mocha_example_test'
59
+ require File.join(File.dirname(__FILE__), 'test', 'acceptance', 'stubba_example_test')
60
+ require File.join(File.dirname(__FILE__), 'test', 'acceptance', 'mocha_example_test')
47
61
  iterations = 1000
48
62
  puts "\nBenchmarking with #{iterations} iterations..."
49
63
  [MochaExampleTest, StubbaExampleTest].each do |test_case|
@@ -55,19 +69,21 @@ end
55
69
 
56
70
  def benchmark_test_case(klass, iterations)
57
71
  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
72
+ load 'test/unit/ui/console/testrunner.rb' unless defined?(Test::Unit::UI::Console::TestRunner)
73
+ unless $silent_option
74
+ begin
75
+ load 'test/unit/ui/console/outputlevel.rb' unless defined?(Test::Unit::UI::Console::OutputLevel::SILENT)
76
+ $silent_option = { :output_level => Test::Unit::UI::Console::OutputLevel::SILENT }
77
+ rescue LoadError
78
+ $silent_option = Test::Unit::UI::SILENT
79
+ end
64
80
  end
65
- time = Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, silent_option) } }
81
+ time = Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, $silent_option) } }
66
82
  end
67
83
 
68
84
  desc 'Generate RDoc'
69
85
  Rake::RDocTask.new('rdoc') do |task|
70
- task.main = 'README'
86
+ task.main = 'README.rdoc'
71
87
  task.title = "Mocha #{Mocha::VERSION}"
72
88
  task.rdoc_dir = 'doc'
73
89
  template = File.expand_path(File.join(File.dirname(__FILE__), "templates", "html_with_google_analytics.rb"))
@@ -76,10 +92,10 @@ Rake::RDocTask.new('rdoc') do |task|
76
92
  task.template = template
77
93
  end
78
94
  task.rdoc_files.include(
79
- 'README',
80
- 'RELEASE',
81
- 'COPYING',
82
- 'MIT-LICENSE',
95
+ 'README.rdoc',
96
+ 'RELEASE.rdoc',
97
+ 'COPYING.rdoc',
98
+ 'MIT-LICENSE.rdoc',
83
99
  'agiledox.txt',
84
100
  'lib/mocha/api.rb',
85
101
  'lib/mocha/mock.rb',
@@ -156,8 +172,8 @@ def build_specification(version = Mocha::VERSION)
156
172
  s.rubyforge_project = 'mocha'
157
173
 
158
174
  s.has_rdoc = true
159
- s.extra_rdoc_files = ['README', 'COPYING']
160
- s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README' << '--line-numbers'
175
+ s.extra_rdoc_files = ['README.rdoc', 'COPYING.rdoc']
176
+ s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README.rdoc' << '--line-numbers'
161
177
 
162
178
  s.add_dependency('rake')
163
179
  s.files = FileList['{lib,test,examples}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a
data/lib/mocha.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require 'mocha/options'
1
2
  require 'mocha_standalone'
2
3
  require 'mocha/configuration'
3
4
  require 'mocha/integration'
@@ -86,9 +86,7 @@ module Mocha
86
86
  end
87
87
 
88
88
  def method_exists?(method)
89
- symbol = method.to_sym
90
- metaclass = stubbee.__metaclass__
91
- metaclass.public_method_defined?(symbol) || metaclass.protected_method_defined?(symbol) || metaclass.private_method_defined?(symbol)
89
+ stubbee.respond_to?(method, true)
92
90
  end
93
91
 
94
92
  def macruby_method?
@@ -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