Commit 2c6fa43dde19512f1440424fe7a7173b479e37de
1 parent
90becc4b
Exists in
master
and in
1 other branch
unpacking test gems
Showing
380 changed files
with
23236 additions
and
0 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 380 files displayed.
vendor/gems/jferris-mocha-0.9.5.0.1241126838/MIT-LICENSE
0 → 100644
@@ -0,0 +1,7 @@ | @@ -0,0 +1,7 @@ | ||
1 | +Copyright (c) 2006 Revieworld Ltd. | ||
2 | + | ||
3 | +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: | ||
4 | + | ||
5 | +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
6 | + | ||
7 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
0 | \ No newline at end of file | 8 | \ No newline at end of file |
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | += Mocha | ||
2 | + | ||
3 | +Mocha is a library for mocking and stubbing using a syntax like that of JMock[http://www.jmock.org]. | ||
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/]. | ||
6 | + | ||
7 | +Mocha provides a unified, simple and readable syntax for both traditional mocking and partial mocking. | ||
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]. | ||
10 | + | ||
11 | +== Download and Installation | ||
12 | + | ||
13 | +Install the gem with the following command... | ||
14 | + | ||
15 | + $ gem install mocha | ||
16 | + | ||
17 | +Or install the Rails[http://www.rubyonrails.org] plugin... | ||
18 | + | ||
19 | + $ script/plugin install git://github.com/floehopper/mocha.git | ||
20 | + | ||
21 | +Or download Mocha... | ||
22 | + | ||
23 | + http://rubyforge.org/frs/?group_id=1917 | ||
24 | + | ||
25 | +== Examples | ||
26 | + | ||
27 | +* Quick Start - {Usage Examples}[link:examples/misc.html] | ||
28 | +* Traditional mocking - {Star Trek Example}[link:examples/mocha.html] | ||
29 | +* Setting expectations on real classes - {Order Example}[link:examples/stubba.html] | ||
30 | +* More examples on {Floehopper's Blog}[http://blog.floehopper.org] | ||
31 | +* {Mailing List Archives}[http://groups.google.com/group/mocha-developer] | ||
32 | + | ||
33 | +== License | ||
34 | + | ||
35 | +Copyright Revieworld Ltd. 2006 | ||
36 | + | ||
37 | +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]. | ||
0 | \ No newline at end of file | 38 | \ No newline at end of file |
@@ -0,0 +1,269 @@ | @@ -0,0 +1,269 @@ | ||
1 | += 0.9.5 (93cad010345ce5d68f31422cfc32ed9dd6de13ec) | ||
2 | +* Fixed Lighthouse bug #32 - stub_everything should mean mock responds to anything. | ||
3 | +* Added Expectation#twice to improve readability. Thanks to pull request from Celestino Gomes. | ||
4 | +* In Ruby 1.9.1, requiring 'test/unit' loads a thin wrapper around MiniTest and Test::Unit::TestCase ends up inheriting from MiniTest::Unit::TestCase. So we need to avoid including the Mocha modules more than once to avoid nasty consequences. Thanks to Matthias Hennemeyer for help with this. | ||
5 | +* Ruby 1.9 includes rake, but not rake/contrib. For the moment I've moved the sshpublisher require into the only rake task that needs it, so that I can at least run the tests in Ruby 1.9. It looks like I will need to build a rake/contrib gem or similar to get this working properly - http://intertwingly.net/blog/2008/01/07/Rake-Contrib-for-1-9 | ||
6 | + | ||
7 | += 0.9.4 (8a59c6ff0f99f34b02bd99f19536a7893be2b340) | ||
8 | +* Added mocha.gemspec file generated with Chad Woolley's new rake task, so that a floehopper-mocha gem will get built on GitHub. | ||
9 | +* Add rake task to update mocha.gemspec with unique version, which will cause gem to be auto-built on github | ||
10 | +* As Tobias Crawley correctly pointed out in feature request #23055 "stubs(with_hash) not working with existing object" [1], following the principle of least surprise, it should be possible to call ObjectMethods#expects & ObjectMethods#stubs with a Hash of method_names vs return_values like you can with Mock#expects & Mock#stubs. I've also updated & improved the docs to reflect the changes. [1] http://rubyforge.org/tracker/index.php?func=detail&aid=23055&group_id=1917&atid=7480 | ||
11 | +* Removed deprecated gem autorequire. | ||
12 | + | ||
13 | += 0.9.3 (8219bb2d2881c8529c93fc21e97a11d01203c759) | ||
14 | +* Added support for MiniTest thanks to Jeff Smick. | ||
15 | +* Fixed a possible bug with some of the non-default Configuration options relating to the argument to Object#respond_to? | ||
16 | +* As per Jay Fields recommendations [1] and with further impetus from a talk at Ruby Manor, any methods added to core classes are now added by including a module. This means that Mocha is a better citizen of the Ruby world and it's behaviour is more easily extended. [1] http://blog.jayfields.com/2008/07/ruby-underuse-of-modules.html & http://blog.jayfields.com/2008/07/ruby-redefine-method-behavior.html | ||
17 | +* Removed deprecated gem autorequire. | ||
18 | + | ||
19 | += 0.9.2 (r355) | ||
20 | +* Improved documentation to address [#22530] 'Mock methods with multiple return values not possible?' | ||
21 | +* respond_with parameter matcher was not available in tests. | ||
22 | +* Patch [#22630] Fix for a bug in running Rails tests with Ruby 1.8.7. Array#flatten was being called which in turn was checking whether each element responded to #to_ary. This check was using the two parameter version of #respond_to?, but Mock was only defining a one parameter version. | ||
23 | + | ||
24 | += 0.9.1 (r349) | ||
25 | + | ||
26 | +* Fixed bug #21465 - expects & stubs should support method names as strings (as well as symbols) or fail fast. Convert all expectation method names to a symbol in case they were supplied as a string. | ||
27 | +* By removing Mock#unexpected_method_called we reduce the number of methods vulnerable to the problem that surfaced in bug #21563. | ||
28 | +* Fix bug #21563 - stubbing 'verified?' method is unsafe. Instance method names on the Mock class should be more obscure. | ||
29 | +* Performance improvement. StubbaExampleTest goes twice as fast on my local machine. | ||
30 | +* Added primitive performance test to default rake task. | ||
31 | +* Fix format of case statements which don't work in Ruby 1.9 and make others consistent. | ||
32 | +* There is no point in running (potentially expensive) checks if configuration is set to allow such checks to fail. This is a relatively quick fix in response to Chris McGrath's performance problems. | ||
33 | +* Fix for bug #21161 - 'uninitialized constant Deprecation in stubba.rb'. | ||
34 | +* It's more readable to talk about 'once' and 'twice' rather than '1 time' and '2 times'. | ||
35 | +* Fix bug #20883 - never should raise when called to prevent follow up errors. Fail fast when there are no matching invokable expectations and handle the stub_everything case sensibly. This might not be entirely backwards compatible, but I think the benefits outweigh the risks. The most likely change is that a test that was already failing will now fail faster, which doesn't seem so awful. | ||
36 | + | ||
37 | += 0.9.0 (r316) | ||
38 | + | ||
39 | +* Configurable warnings or errors | ||
40 | + * when a method on a non-public method is stubbed | ||
41 | + * when a method on a non-existent method is stubbed | ||
42 | + * when a method on a non-mock object is stubbed | ||
43 | + * when a method is stubbed unnecessarily (i.e. the stubbed method is not called during the test) | ||
44 | + | ||
45 | +* Improved error messages | ||
46 | + * User-friendly list of unsatisfied expectations, satisfied expectations and state machines. | ||
47 | + * Improved readability of cardinality description. | ||
48 | + * Display sensible failure message for any_instance expectations e.g. "#<AnyInstance:Foo>.bar - expected calls: 1, actual calls: 0" | ||
49 | + | ||
50 | +* Parameter matchers | ||
51 | + * New to this release | ||
52 | + * optionally (allows matching of optional parameters if available) | ||
53 | + * yaml_equivalent (allows matching of YAML that represents the specified object) | ||
54 | + * responds_with (tests the quack not the duck) | ||
55 | + * Nesting of parameter matchers is now supported. | ||
56 | + | ||
57 | +* Optional block passed into mock initializer is evaluated in the context of the new mock instance and can be used as a shortcut to set up expectations. | ||
58 | + | ||
59 | +* Added JMock-style sequences for constraining the order of expected invocations. See Standalone#sequence and Expectation#in_sequence. | ||
60 | + | ||
61 | +* Added JMock-style states for constraining the order of expected invocations. See Standalone#states, Expectation#then, Expectation#when and StateMachine. | ||
62 | + | ||
63 | +* Compatibility with versions of Ruby | ||
64 | + * Compatibility with Ruby v1.9. All test errors and warnings fixed. | ||
65 | + * Nasty fix so that TestCaseAdaptor works consistently with earlier versions of Test::Unit as well as more recent versions. | ||
66 | + * Added platform to gem specification to avoid bug in rubygems 0.9.5 - see http://www.dcmanges.com/blog/rubygems-0-9-5-platform-bug and http://rubygems.org/read/chapter/20#platform. | ||
67 | + * Make ExpectationRaiser deal with subclasses of Interrupt which seem to need a message supplied in the raise statement in Ruby 1.8.6 (but not 1.8.4 or 1.9). Not sure this is really Mocha's responsibility. | ||
68 | + | ||
69 | +* Added deprecation warning in stubba.rb which is no longer needed and will be removed. | ||
70 | + | ||
71 | +* Supply positioning information to evals to improve any error messages. See http://ola-bini.blogspot.com/2008/01/ruby-antipattern-using-eval-without.html | ||
72 | + | ||
73 | +* Bug fixes | ||
74 | + * 18914 in revision 296 - http://rubyforge.org/tracker/index.php?func=detail&aid=18914&group_id=1917&atid=7477 | ||
75 | + * 18917 in revision 295 - http://rubyforge.org/tracker/index.php?func=detail&aid=18917&group_id=1917&atid=7477 | ||
76 | + * 18336 in revision 287 - http://rubyforge.org/tracker/index.php?func=detail&aid=18336&group_id=1917&atid=7477 | ||
77 | + * 17835 in revision 255 - http://rubyforge.org/tracker/index.php?func=detail&aid=17835&group_id=1917&atid=7477 | ||
78 | + * 17412 in revision 242 - http://rubyforge.org/tracker/index.php?func=detail&aid=17412&group_id=1917&atid=7477 | ||
79 | + * 15977 in revision 198 - http://rubyforge.org/tracker/index.php?func=detail&aid=15977&group_id=1917&atid=7477 | ||
80 | + * 11885 in revision 156 - http://rubyforge.org/tracker/index.php?func=detail&aid=11885&group_id=1917&atid=7477 | ||
81 | + | ||
82 | += 0.5.5 (r167) | ||
83 | + | ||
84 | +- Renamed Matches parameter matcher to RegexpMatches for clarity. | ||
85 | +- Added noframes tag to rdoc index to assist Google. | ||
86 | + | ||
87 | += 0.5.4 (r166) | ||
88 | + | ||
89 | +- Added matches parameter matcher for matching regular expressions. | ||
90 | + | ||
91 | += 0.5.3 (r165) | ||
92 | + | ||
93 | +- Attempt to fix packaging problems by switching to newer version (1.15.1) of gnutar and setting COPY_EXTENDED_ATTRIBUTES_DISABLE environment variable. | ||
94 | +- Removed unused ExpectationSequenceError exception. | ||
95 | +- Added instance_of and kind_of parameter matchers. | ||
96 | +- Added Google Webmaster meta tag to rdoc template header. | ||
97 | +- Put Google Webmaster meta tag in the right header i.e. the one for the index page. | ||
98 | + | ||
99 | += 0.5.2 (r159) | ||
100 | + | ||
101 | +- Fix bug 11885 - "never doesn't work with stub_everything" submitted by Alexander Lang. In fixing this bug, also fixed undiscoverd bug where expected & actual invocation counts were being incorrectly reported which seems to have been introduced when fixes were added for invocation dispatch (see MockedMethodDispatchAcceptanceTest). | ||
102 | +- Previously when an expectation did not allow more invocations, it was treated as not matching. Now we prefer matching expectations which allow more invocations, but still match expectations which cannot allow more invocations. I think this may be overcomplicating things, but let's see how it goes. | ||
103 | + | ||
104 | += 0.5.1 (r149) | ||
105 | + | ||
106 | +- Fixed bug #11583 "Mocha 0.5.0 throwing unexpected warnings". Also switched on ruby warning for all rake test tasks. Fixed majority of warnings, but some left to fix. | ||
107 | + | ||
108 | += 0.5.0 (r147) | ||
109 | + | ||
110 | +- Parameter Matchers - I’ve added a few Hamcrest-style parameter matchers which are designed to be used inside Expectation#with. The following matchers are currently available: anything(), includes(), has_key(), has_value(), has_entry(), all_of() & any_of(). More to follow soon. The idea is eventually to get rid of the nasty parameter_block option on Expectation#with. | ||
111 | + | ||
112 | + object = mock() | ||
113 | + object.expects(:method).with(has_key('key_1')) | ||
114 | + object.method('key_1' => 1, 'key_2' => 2) | ||
115 | + # no verification error raised | ||
116 | + | ||
117 | + object = mock() | ||
118 | + object.expects(:method).with(has_key('key_1')) | ||
119 | + object.method('key_2' => 2) | ||
120 | + # verification error raised, because method was not called with Hash containing key: 'key_1' | ||
121 | + | ||
122 | +- Values Returned and Exceptions Raised on Consecutive Invocations - Allow multiple calls to Expectation#returns and Expectation#raises to build up a sequence of responses to invocations on the mock. Added syntactic sugar method Expectation#then to allow more readable expectations. | ||
123 | + | ||
124 | + object = mock() | ||
125 | + object.stubs(:method).returns(1, 2).then.raises(Exception).then.returns(4) | ||
126 | + object.method # => 1 | ||
127 | + object.method # => 2 | ||
128 | + object.method # => raises exception of class Exception | ||
129 | + object.method # => 4 | ||
130 | + | ||
131 | +- Yields on Consecutive Invocations - Allow multiple calls to yields on single expectation to allow yield parameters to be specified for consecutive invocations. | ||
132 | + | ||
133 | + object = mock() | ||
134 | + object.stubs(:method).yields(1, 2).then.yields(3) | ||
135 | + object.method { |*values| p values } # => [1, 2] | ||
136 | + object.method { |*values| p values } # => [3] | ||
137 | + | ||
138 | +- Multiple Yields on Single Invocation - Added Expectation#multiple_yields to allow a mocked or stubbed method to yield multiple times for a single invocation. | ||
139 | + | ||
140 | + object = mock() | ||
141 | + object.stubs(:method).multiple_yields([1, 2], [3]) | ||
142 | + object.method { |*values| p values } # => [1, 2] # => [3] | ||
143 | + | ||
144 | +- Invocation Dispatch - Expectations were already being matched in reverse order i.e. the most recently defined one was being found first. This is still the case, but we now stop matching an expectation when its maximum number of expected invocations is reached. c.f. JMock v1. A stub will never stop matching by default. Hopefully this means we can soon get rid of the need to pass a Proc to Expectation#returns. | ||
145 | + | ||
146 | + object = mock() | ||
147 | + object.stubs(:method).returns(2) | ||
148 | + object.expects(:method).once.returns(1) | ||
149 | + object.method # => 1 | ||
150 | + object.method # => 2 | ||
151 | + object.method # => 2 | ||
152 | + # no verification error raised | ||
153 | + | ||
154 | + # The following should still work... | ||
155 | + | ||
156 | + Time.stubs(:now).returns(Time.parse('Mon Jan 01 00:00:00 UTC 2007')) | ||
157 | + Time.now # => Mon Jan 01 00:00:00 UTC 2007 | ||
158 | + Time.stubs(:now).returns(Time.parse('Thu Feb 01 00:00:00 UTC 2007')) | ||
159 | + Time.now # => Thu Feb 01 00:00:00 UTC 2007 | ||
160 | + | ||
161 | +- Deprecate passing an instance of Proc to Expectation#returns. | ||
162 | +- Explicitly include all Rakefile dependencies in project. | ||
163 | +- Fixed old Stubba example. | ||
164 | +- Fix so that it is possible for a stubbed method to raise an Interrupt exception without a message in Ruby 1.8.6 | ||
165 | +- Added responds_like and quacks_like. | ||
166 | +- Capture standard object methods before Mocha adds any. | ||
167 | +- Added Expectation#once method to make interface less surprising. | ||
168 | +- Use Rake::TestTask to run tests. Created three separate tasks to run unit, integration & acceptance tests. Split inspect_test into one file per TestCase. Deleted superfluous all_tests file. | ||
169 | +- Fiddled with mocha_inspect and tests to give more sensible results on x86 platform. | ||
170 | +- Fixed bug #7834 "infinite_range.rb makes incorrect assumption about to_f" logged by James Moore. | ||
171 | + | ||
172 | += 0.4.0 (r92) | ||
173 | + | ||
174 | +- Allow naming of mocks (patch from Chris Roos). | ||
175 | +- Specify multiple return values for consecutive calls. | ||
176 | +- Improved consistency of expectation error messages. | ||
177 | +- Allow mocking of Object instance methods e.g. kind_of?, type. | ||
178 | +- Provide aliased versions of #expects and #stubs to allow mocking of these methods. | ||
179 | +- Added at_least, at_most, at_most_once methods to expectation. | ||
180 | +- Allow expects and stubs to take a hash of method and return values. | ||
181 | +- Eliminate warning: "instance variable @yield not initialized" (patch from Xavier Shay). | ||
182 | +- Restore instance methods on partial mocks (patch from Chris Roos). | ||
183 | +- Allow stubbing of a method with non-word characters in its name (patch from Paul Battley). | ||
184 | +- Removed coupling to Test::Unit. | ||
185 | +- Allow specified exception instance to be raised (patch from Chris Roos). | ||
186 | +- Make mock object_id appear in hex like normal Ruby inspect (patch from Paul Battley). | ||
187 | +- Fix path to object.rb in rdoc rake task (patch from Tomas Pospisek). | ||
188 | +- Reverse order in which expectations are matched, so that last expectation is matched first. This allows e.g. a call to #stubs to be effectively overridden by a call to #expects (patch from Tobias Lutke). | ||
189 | +- Stubba & SmartTestCase modules incorporated into Mocha module so only need to require 'mocha' - no longer need to require 'stubba'. | ||
190 | +- AutoMocha removed. | ||
191 | + | ||
192 | += 0.3.3 | ||
193 | + | ||
194 | +- Quick bug fix to restore instance methods on partial mocks (for Kevin Clark). | ||
195 | + | ||
196 | += 0.3.2 | ||
197 | + | ||
198 | +- Examples added. | ||
199 | + | ||
200 | += 0.3.1 | ||
201 | + | ||
202 | +- Dual licensing with MIT license added. | ||
203 | + | ||
204 | += 0.3.0 | ||
205 | + | ||
206 | +* Rails plugin. | ||
207 | +* Auto-verify for expectations on concrete classes. | ||
208 | +* Include each expectation verification in the test result assertion count. | ||
209 | +* Filter out noise from assertion backtraces. | ||
210 | +* Point assertion backtrace to line where failing expectation was created. | ||
211 | +* New yields method for expectations. | ||
212 | +* Create stubs which stub all method calls. | ||
213 | +* Mocks now respond_to? expected methods. | ||
214 | + | ||
215 | += 0.2.1 | ||
216 | + | ||
217 | +* Rename MochaAcceptanceTest::Rover#move method to avoid conflict with Rake (in Ruby 1.8.4 only?) | ||
218 | + | ||
219 | += 0.2.0 | ||
220 | + | ||
221 | +* Small change to SetupAndTeardown#teardown_stubs suggested by Luke Redpath (http://www.lukeredpath.co.uk) to allow use of Stubba with RSpec (http://rspec.rubyforge.org). | ||
222 | +* Reorganized directory structure and extracted addition of setup and teardown methods into SmartTestCase mini-library. | ||
223 | +* Addition of auto-verify for Mocha (but not Stubba). This means there is more significance in the choice of expects or stubs in that any expects on a mock will automatically get verified. | ||
224 | + | ||
225 | +So instead of... | ||
226 | + | ||
227 | + wotsit = Mocha.new | ||
228 | + wotsit.expects(:thingummy).with(5).returns(10) | ||
229 | + doobrey = Doobrey.new(wotsit) | ||
230 | + doobrey.hoojamaflip | ||
231 | + wotsit.verify | ||
232 | + | ||
233 | +you need to do... | ||
234 | + | ||
235 | + wotsit = mock() | ||
236 | + wotsit.expects(:thingummy).with(5).returns(10) | ||
237 | + doobrey = Doobrey.new(wotsit) | ||
238 | + doobrey.hoojamaflip | ||
239 | + # no need to verify | ||
240 | + | ||
241 | +There are also shortcuts as follows... | ||
242 | + | ||
243 | +instead of... | ||
244 | + | ||
245 | + wotsit = Mocha.new | ||
246 | + wotsit.expects(:thingummy).returns(10) | ||
247 | + wotsit.expects(:summat).returns(25) | ||
248 | + | ||
249 | +you can have... | ||
250 | + | ||
251 | + wotsit = mock(:thingummy => 5, :summat => 25) | ||
252 | + | ||
253 | +and instead of... | ||
254 | + | ||
255 | + wotsit = Mocha.new | ||
256 | + wotsit.stubs(:thingummy).returns(10) | ||
257 | + wotsit.stubs(:summat).returns(25) | ||
258 | + | ||
259 | +you can have... | ||
260 | + | ||
261 | + wotsit = stub(:thingummy => 5, :summat => 25) | ||
262 | + | ||
263 | += 0.1.2 | ||
264 | + | ||
265 | +* Minor tweaks | ||
266 | + | ||
267 | += 0.1.1 | ||
268 | + | ||
269 | +* Initial release. |
@@ -0,0 +1,217 @@ | @@ -0,0 +1,217 @@ | ||
1 | +require 'rake/rdoctask' | ||
2 | +require 'rake/gempackagetask' | ||
3 | +require 'rake/testtask' | ||
4 | + | ||
5 | +module Mocha | ||
6 | + VERSION = "0.9.5" | ||
7 | +end | ||
8 | + | ||
9 | +desc "Run all tests" | ||
10 | +task 'default' => ['test:units', 'test:acceptance', 'test:performance'] | ||
11 | + | ||
12 | +namespace 'test' do | ||
13 | + | ||
14 | + unit_tests = FileList['test/unit/**/*_test.rb'] | ||
15 | + acceptance_tests = FileList['test/acceptance/*_test.rb'] | ||
16 | + | ||
17 | + 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 | ||
23 | + end | ||
24 | + | ||
25 | + 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 | ||
31 | + end | ||
32 | + | ||
33 | + # require 'rcov/rcovtask' | ||
34 | + # Rcov::RcovTask.new('coverage') do |t| | ||
35 | + # t.libs << 'test' | ||
36 | + # t.test_files = unit_tests + acceptance_tests | ||
37 | + # t.verbose = true | ||
38 | + # t.warning = true | ||
39 | + # t.rcov_opts << '--sort coverage' | ||
40 | + # t.rcov_opts << '--xref' | ||
41 | + # end | ||
42 | + | ||
43 | + desc "Run performance tests" | ||
44 | + task 'performance' do | ||
45 | + require 'test/acceptance/stubba_example_test' | ||
46 | + require 'test/acceptance/mocha_example_test' | ||
47 | + iterations = 1000 | ||
48 | + puts "\nBenchmarking with #{iterations} iterations..." | ||
49 | + [MochaExampleTest, StubbaExampleTest].each do |test_case| | ||
50 | + puts "#{test_case}: #{benchmark_test_case(test_case, iterations)} seconds." | ||
51 | + end | ||
52 | + end | ||
53 | + | ||
54 | +end | ||
55 | + | ||
56 | +def benchmark_test_case(klass, iterations) | ||
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 | ||
64 | + end | ||
65 | + time = Benchmark.realtime { iterations.times { Test::Unit::UI::Console::TestRunner.run(klass, silent_option) } } | ||
66 | +end | ||
67 | + | ||
68 | +desc 'Generate RDoc' | ||
69 | +Rake::RDocTask.new('rdoc') do |task| | ||
70 | + task.main = 'README' | ||
71 | + task.title = "Mocha #{Mocha::VERSION}" | ||
72 | + task.rdoc_dir = 'doc' | ||
73 | + task.template = File.expand_path(File.join(File.dirname(__FILE__), "templates", "html_with_google_analytics")) | ||
74 | + task.rdoc_files.include( | ||
75 | + 'README', | ||
76 | + 'RELEASE', | ||
77 | + 'COPYING', | ||
78 | + 'MIT-LICENSE', | ||
79 | + 'agiledox.txt', | ||
80 | + 'lib/mocha/api.rb', | ||
81 | + 'lib/mocha/mock.rb', | ||
82 | + 'lib/mocha/expectation.rb', | ||
83 | + 'lib/mocha/object.rb', | ||
84 | + 'lib/mocha/parameter_matchers.rb', | ||
85 | + 'lib/mocha/parameter_matchers', | ||
86 | + 'lib/mocha/state_machine.rb', | ||
87 | + 'lib/mocha/configuration.rb', | ||
88 | + 'lib/mocha/stubbing_error.rb' | ||
89 | + ) | ||
90 | +end | ||
91 | + | ||
92 | +desc "Generate all documentation" | ||
93 | +task 'generate_docs' => ['clobber_rdoc', 'rdoc', 'examples', 'agiledox.txt'] | ||
94 | + | ||
95 | +desc "Upload RDoc to RubyForge" | ||
96 | +task 'publish_docs' do | ||
97 | + require 'rake/contrib/sshpublisher' | ||
98 | + Rake::SshDirPublisher.new("jamesmead@rubyforge.org", "/var/www/gforge-projects/mocha", "doc").upload | ||
99 | +end | ||
100 | + | ||
101 | +desc "Generate agiledox-like documentation for tests" | ||
102 | +file 'agiledox.txt' do | ||
103 | + File.open('agiledox.txt', 'w') do |output| | ||
104 | + tests = FileList['test/**/*_test.rb'] | ||
105 | + tests.each do |file| | ||
106 | + m = %r".*/([^/].*)_test.rb".match(file) | ||
107 | + output << m[1]+" should:\n" | ||
108 | + test_definitions = File::readlines(file).select {|line| line =~ /.*def test.*/} | ||
109 | + test_definitions.sort.each do |definition| | ||
110 | + m = %r"test_(should_)?(.*)".match(definition) | ||
111 | + output << " - "+m[2].gsub(/_/," ") << "\n" | ||
112 | + end | ||
113 | + end | ||
114 | + end | ||
115 | +end | ||
116 | + | ||
117 | +desc "Convert example ruby files to syntax-highlighted html" | ||
118 | +task 'examples' do | ||
119 | + require 'coderay' | ||
120 | + mkdir_p 'doc/examples' | ||
121 | + File.open('doc/examples/coderay.css', 'w') do |output| | ||
122 | + output << CodeRay::Encoders[:html]::CSS.new.stylesheet | ||
123 | + end | ||
124 | + ['mocha', 'stubba', 'misc'].each do |filename| | ||
125 | + File.open("doc/examples/#{filename}.html", 'w') do |file| | ||
126 | + file << "<html>" | ||
127 | + file << "<head>" | ||
128 | + file << %q(<link rel="stylesheet" media="screen" href="coderay.css" type="text/css">) | ||
129 | + file << "</head>" | ||
130 | + file << "<body>" | ||
131 | + file << CodeRay.scan_file("examples/#{filename}.rb").html.div | ||
132 | + file << "</body>" | ||
133 | + file << "</html>" | ||
134 | + end | ||
135 | + end | ||
136 | +end | ||
137 | + | ||
138 | +Gem.manage_gems if Gem::RubyGemsVersion < '1.2.0' | ||
139 | + | ||
140 | +def build_specification(version = Mocha::VERSION) | ||
141 | + Gem::Specification.new do |s| | ||
142 | + s.name = "mocha" | ||
143 | + s.summary = "Mocking and stubbing library" | ||
144 | + s.version = "#{version}.0.#{Time.now.to_i}" | ||
145 | + s.platform = Gem::Platform::RUBY | ||
146 | + s.author = 'James Mead' | ||
147 | + s.description = <<-EOF | ||
148 | + Mocking and stubbing library with JMock/SchMock syntax, which allows mocking and stubbing of methods on real (non-mock) classes. | ||
149 | + EOF | ||
150 | + s.email = 'mocha-developer@googlegroups.com' | ||
151 | + s.homepage = 'http://mocha.rubyforge.org' | ||
152 | + s.rubyforge_project = 'mocha' | ||
153 | + | ||
154 | + s.has_rdoc = true | ||
155 | + s.extra_rdoc_files = ['README', 'COPYING'] | ||
156 | + s.rdoc_options << '--title' << 'Mocha' << '--main' << 'README' << '--line-numbers' | ||
157 | + | ||
158 | + s.add_dependency('rake') | ||
159 | + s.files = FileList['{lib,test,examples}/**/*.rb', '[A-Z]*'].exclude('TODO').to_a | ||
160 | + end | ||
161 | +end | ||
162 | + | ||
163 | +specification = build_specification | ||
164 | + | ||
165 | +Rake::GemPackageTask.new(specification) do |package| | ||
166 | + package.need_zip = true | ||
167 | + package.need_tar = true | ||
168 | +end | ||
169 | + | ||
170 | +desc 'Generate updated gemspec with unique version, which will cause gem to be auto-built on github.' | ||
171 | +task :update_gemspec do | ||
172 | + File.open('mocha.gemspec', 'w') do |output| | ||
173 | + output << build_specification(Mocha::VERSION + '.' + Time.now.strftime('%Y%m%d%H%M%S')).to_ruby | ||
174 | + end | ||
175 | +end | ||
176 | + | ||
177 | +task 'verify_user' do | ||
178 | + raise "RUBYFORGE_USER environment variable not set!" unless ENV['RUBYFORGE_USER'] | ||
179 | +end | ||
180 | + | ||
181 | +task 'verify_password' do | ||
182 | + raise "RUBYFORGE_PASSWORD environment variable not set!" unless ENV['RUBYFORGE_PASSWORD'] | ||
183 | +end | ||
184 | + | ||
185 | +desc "Publish package files on RubyForge." | ||
186 | +task 'publish_packages' => ['verify_user', 'verify_password', 'clobber_package', 'package'] do | ||
187 | + require 'meta_project' | ||
188 | + require 'rake/contrib/xforge' | ||
189 | + release_files = FileList[ | ||
190 | + "pkg/mocha-#{Mocha::VERSION}.gem", | ||
191 | + "pkg/mocha-#{Mocha::VERSION}.tgz", | ||
192 | + "pkg/mocha-#{Mocha::VERSION}.zip" | ||
193 | + ] | ||
194 | + | ||
195 | + Rake::XForge::Release.new(MetaProject::Project::XForge::RubyForge.new('mocha')) do |release| | ||
196 | + release.user_name = ENV['RUBYFORGE_USER'] | ||
197 | + release.password = ENV['RUBYFORGE_PASSWORD'] | ||
198 | + release.files = release_files.to_a | ||
199 | + release.release_name = "Mocha #{Mocha::VERSION}" | ||
200 | + release.release_changes = '' | ||
201 | + release.release_notes = '' | ||
202 | + end | ||
203 | +end | ||
204 | + | ||
205 | +desc "Do a full release." | ||
206 | +task 'release' => ['default', 'generate_docs', 'publish_packages', 'publish_docs', 'update_gemspec'] do | ||
207 | + puts | ||
208 | + puts "*** Remember to commit newly generated gemspec after release ***" | ||
209 | + puts | ||
210 | +end | ||
211 | + | ||
212 | +desc "Generate a gemspec file" | ||
213 | +task :gemspec do | ||
214 | + File.open("#{specification.name}.gemspec", 'w') do |f| | ||
215 | + f.write specification.to_yaml | ||
216 | + end | ||
217 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/misc.rb
0 → 100644
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +require 'test/unit' | ||
2 | +require 'mocha' | ||
3 | + | ||
4 | +class MiscExampleTest < Test::Unit::TestCase | ||
5 | + | ||
6 | + def test_mocking_a_class_method | ||
7 | + product = Product.new | ||
8 | + Product.expects(:find).with(1).returns(product) | ||
9 | + assert_equal product, Product.find(1) | ||
10 | + end | ||
11 | + | ||
12 | + def test_mocking_an_instance_method_on_a_real_object | ||
13 | + product = Product.new | ||
14 | + product.expects(:save).returns(true) | ||
15 | + assert product.save | ||
16 | + end | ||
17 | + | ||
18 | + def test_stubbing_instance_methods_on_real_objects | ||
19 | + prices = [stub(:pence => 1000), stub(:pence => 2000)] | ||
20 | + product = Product.new | ||
21 | + product.stubs(:prices).returns(prices) | ||
22 | + assert_equal [1000, 2000], product.prices.collect {|p| p.pence} | ||
23 | + end | ||
24 | + | ||
25 | + def test_stubbing_an_instance_method_on_all_instances_of_a_class | ||
26 | + Product.any_instance.stubs(:name).returns('stubbed_name') | ||
27 | + product = Product.new | ||
28 | + assert_equal 'stubbed_name', product.name | ||
29 | + end | ||
30 | + | ||
31 | + def test_traditional_mocking | ||
32 | + object = mock() | ||
33 | + object.expects(:expected_method).with(:p1, :p2).returns(:result) | ||
34 | + assert_equal :result, object.expected_method(:p1, :p2) | ||
35 | + end | ||
36 | + | ||
37 | + def test_shortcuts | ||
38 | + object = stub(:method1 => :result1, :method2 => :result2) | ||
39 | + assert_equal :result1, object.method1 | ||
40 | + assert_equal :result2, object.method2 | ||
41 | + end | ||
42 | + | ||
43 | +end | ||
0 | \ No newline at end of file | 44 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/mocha.rb
0 → 100644
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +class Enterprise | ||
2 | + | ||
3 | + def initialize(dilithium) | ||
4 | + @dilithium = dilithium | ||
5 | + end | ||
6 | + | ||
7 | + def go(warp_factor) | ||
8 | + warp_factor.times { @dilithium.nuke(:anti_matter) } | ||
9 | + end | ||
10 | + | ||
11 | +end | ||
12 | + | ||
13 | +require 'test/unit' | ||
14 | +require 'mocha' | ||
15 | + | ||
16 | +class EnterpriseTest < Test::Unit::TestCase | ||
17 | + | ||
18 | + def test_should_boldly_go | ||
19 | + dilithium = mock() | ||
20 | + dilithium.expects(:nuke).with(:anti_matter).at_least_once # auto-verified at end of test | ||
21 | + enterprise = Enterprise.new(dilithium) | ||
22 | + enterprise.go(2) | ||
23 | + end | ||
24 | + | ||
25 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/examples/stubba.rb
0 → 100644
@@ -0,0 +1,64 @@ | @@ -0,0 +1,64 @@ | ||
1 | +class Order | ||
2 | + | ||
3 | + attr_accessor :shipped_on | ||
4 | + | ||
5 | + def total_cost | ||
6 | + line_items.inject(0) { |total, line_item| total + line_item.price } + shipping_cost | ||
7 | + end | ||
8 | + | ||
9 | + def total_weight | ||
10 | + line_items.inject(0) { |total, line_item| total + line_item.weight } | ||
11 | + end | ||
12 | + | ||
13 | + def shipping_cost | ||
14 | + total_weight * 5 + 10 | ||
15 | + end | ||
16 | + | ||
17 | + class << self | ||
18 | + | ||
19 | + def find_all | ||
20 | + # Database.connection.execute('select * from orders... | ||
21 | + end | ||
22 | + | ||
23 | + def number_shipped_since(date) | ||
24 | + find_all.select { |order| order.shipped_on > date }.length | ||
25 | + end | ||
26 | + | ||
27 | + def unshipped_value | ||
28 | + find_all.inject(0) { |total, order| order.shipped_on ? total : total + order.total_cost } | ||
29 | + end | ||
30 | + | ||
31 | + end | ||
32 | + | ||
33 | +end | ||
34 | + | ||
35 | +require 'test/unit' | ||
36 | +require 'mocha' | ||
37 | + | ||
38 | +class OrderTest < Test::Unit::TestCase | ||
39 | + | ||
40 | + # illustrates stubbing instance method | ||
41 | + def test_should_calculate_shipping_cost_based_on_total_weight | ||
42 | + order = Order.new | ||
43 | + order.stubs(:total_weight).returns(10) | ||
44 | + assert_equal 60, order.shipping_cost | ||
45 | + end | ||
46 | + | ||
47 | + # illustrates stubbing class method | ||
48 | + def test_should_count_number_of_orders_shipped_after_specified_date | ||
49 | + now = Time.now; week_in_secs = 7 * 24 * 60 * 60 | ||
50 | + order_1 = Order.new; order_1.shipped_on = now - 1 * week_in_secs | ||
51 | + order_2 = Order.new; order_2.shipped_on = now - 3 * week_in_secs | ||
52 | + Order.stubs(:find_all).returns([order_1, order_2]) | ||
53 | + assert_equal 1, Order.number_shipped_since(now - 2 * week_in_secs) | ||
54 | + end | ||
55 | + | ||
56 | + # illustrates stubbing instance method for all instances of a class | ||
57 | + def test_should_calculate_value_of_unshipped_orders | ||
58 | + Order.stubs(:find_all).returns([Order.new, Order.new, Order.new]) | ||
59 | + Order.any_instance.stubs(:shipped_on).returns(nil) | ||
60 | + Order.any_instance.stubs(:total_cost).returns(10) | ||
61 | + assert_equal 30, Order.unshipped_value | ||
62 | + end | ||
63 | + | ||
64 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha.rb
0 → 100644
@@ -0,0 +1,69 @@ | @@ -0,0 +1,69 @@ | ||
1 | +require 'mocha_standalone' | ||
2 | +require 'mocha/configuration' | ||
3 | + | ||
4 | +if defined?(MiniTest::Unit::TestCase) && !MiniTest::Unit::TestCase.ancestors.include?(Mocha::API) | ||
5 | + require 'mocha/integration/mini_test' | ||
6 | + | ||
7 | + module MiniTest | ||
8 | + class Unit | ||
9 | + class TestCase | ||
10 | + | ||
11 | + include Mocha::API | ||
12 | + | ||
13 | + alias_method :run_before_mocha, :run | ||
14 | + remove_method :run | ||
15 | + | ||
16 | + include Mocha::Integration::MiniTest::Version131AndAbove | ||
17 | + | ||
18 | + end | ||
19 | + end | ||
20 | + end | ||
21 | +end | ||
22 | + | ||
23 | +if defined?(Bacon) && Bacon::VERSION >= "1.1" && defined?(Bacon::Context) && !Bacon::Context.ancestors.include?(Mocha::API) | ||
24 | + | ||
25 | + require 'mocha/integration/bacon' | ||
26 | + | ||
27 | + module Bacon | ||
28 | + class Context | ||
29 | + include Mocha::API | ||
30 | + include Mocha::Integration::Bacon::Version11AndAbove | ||
31 | + end | ||
32 | + end | ||
33 | + | ||
34 | +end | ||
35 | + | ||
36 | +require 'test/unit/testcase' | ||
37 | +require 'mocha/integration/test_unit' | ||
38 | + | ||
39 | +unless Test::Unit::TestCase.ancestors.include?(Mocha::API) | ||
40 | + module Test | ||
41 | + module Unit | ||
42 | + class TestCase | ||
43 | + | ||
44 | + include Mocha::API | ||
45 | + | ||
46 | + alias_method :run_before_mocha, :run | ||
47 | + remove_method :run | ||
48 | + | ||
49 | + test_unit_version = begin | ||
50 | + require 'test/unit/version' | ||
51 | + Test::Unit::VERSION | ||
52 | + rescue LoadError | ||
53 | + '1.x' | ||
54 | + end | ||
55 | + | ||
56 | + if test_unit_version == '2.0.0' | ||
57 | + include Mocha::Integration::TestUnit::GemVersion200 | ||
58 | + elsif test_unit_version >= '2.0.1' | ||
59 | + include Mocha::Integration::TestUnit::GemVersion201AndAbove | ||
60 | + elsif RUBY_VERSION < '1.8.6' | ||
61 | + include Mocha::Integration::TestUnit::RubyVersion185AndBelow | ||
62 | + else | ||
63 | + include Mocha::Integration::TestUnit::RubyVersion186AndAbove | ||
64 | + end | ||
65 | + | ||
66 | + end | ||
67 | + end | ||
68 | + end | ||
69 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/any_instance_method.rb
0 → 100644
@@ -0,0 +1,55 @@ | @@ -0,0 +1,55 @@ | ||
1 | +require 'mocha/class_method' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + class AnyInstanceMethod < ClassMethod | ||
6 | + | ||
7 | + def unstub | ||
8 | + remove_new_method | ||
9 | + restore_original_method | ||
10 | + stubbee.any_instance.reset_mocha | ||
11 | + end | ||
12 | + | ||
13 | + def mock | ||
14 | + stubbee.any_instance.mocha | ||
15 | + end | ||
16 | + | ||
17 | + def hide_original_method | ||
18 | + if method_exists?(method) | ||
19 | + begin | ||
20 | + stubbee.send(:alias_method, hidden_method, method) | ||
21 | + rescue NameError | ||
22 | + # deal with nasties like ActiveRecord::Associations::AssociationProxy | ||
23 | + end | ||
24 | + end | ||
25 | + end | ||
26 | + | ||
27 | + def define_new_method | ||
28 | + stubbee.class_eval("def #{method}(*args, &block); self.class.any_instance.mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__) | ||
29 | + end | ||
30 | + | ||
31 | + def remove_new_method | ||
32 | + stubbee.send(:remove_method, method) | ||
33 | + end | ||
34 | + | ||
35 | + def restore_original_method | ||
36 | + if method_exists?(hidden_method) | ||
37 | + begin | ||
38 | + stubbee.send(:alias_method, method, hidden_method) | ||
39 | + stubbee.send(:remove_method, hidden_method) | ||
40 | + rescue NameError | ||
41 | + # deal with nasties like ActiveRecord::Associations::AssociationProxy | ||
42 | + end | ||
43 | + end | ||
44 | + end | ||
45 | + | ||
46 | + def method_exists?(method) | ||
47 | + return true if stubbee.public_instance_methods(false).include?(method) | ||
48 | + return true if stubbee.protected_instance_methods(false).include?(method) | ||
49 | + return true if stubbee.private_instance_methods(false).include?(method) | ||
50 | + return false | ||
51 | + end | ||
52 | + | ||
53 | + end | ||
54 | + | ||
55 | +end | ||
0 | \ No newline at end of file | 56 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/api.rb
0 → 100644
@@ -0,0 +1,249 @@ | @@ -0,0 +1,249 @@ | ||
1 | +require 'mocha/parameter_matchers' | ||
2 | +require 'mocha/mockery' | ||
3 | +require 'mocha/sequence' | ||
4 | + | ||
5 | +module Mocha # :nodoc: | ||
6 | + | ||
7 | + # Methods added to Test::Unit::TestCase or equivalent. | ||
8 | + module API | ||
9 | + | ||
10 | + include ParameterMatchers | ||
11 | + | ||
12 | + # :call-seq: mock(name, &block) -> mock object | ||
13 | + # mock(expected_methods = {}, &block) -> mock object | ||
14 | + # mock(name, expected_methods = {}, &block) -> mock object | ||
15 | + # | ||
16 | + # Creates a mock object. | ||
17 | + # | ||
18 | + # +name+ is a +String+ identifier for the mock object. | ||
19 | + # | ||
20 | + # +expected_methods+ is a +Hash+ with expected method name symbols as keys and corresponding return values as values. | ||
21 | + # | ||
22 | + # Note that (contrary to expectations set up by #stub) these expectations <b>must</b> be fulfilled during the test. | ||
23 | + # def test_product | ||
24 | + # product = mock('ipod_product', :manufacturer => 'ipod', :price => 100) | ||
25 | + # assert_equal 'ipod', product.manufacturer | ||
26 | + # assert_equal 100, product.price | ||
27 | + # # an error will be raised unless both Product#manufacturer and Product#price have been called | ||
28 | + # end | ||
29 | + # | ||
30 | + # +block+ is an optional block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs. | ||
31 | + # def test_product | ||
32 | + # product = mock('ipod_product') do | ||
33 | + # expects(:manufacturer).returns('ipod') | ||
34 | + # expects(:price).returns(100) | ||
35 | + # end | ||
36 | + # assert_equal 'ipod', product.manufacturer | ||
37 | + # assert_equal 100, product.price | ||
38 | + # # an error will be raised unless both Product#manufacturer and Product#price have been called | ||
39 | + # end | ||
40 | + def mock(*arguments, &block) | ||
41 | + name = arguments.shift if arguments.first.is_a?(String) | ||
42 | + expectations = arguments.shift || {} | ||
43 | + mock = name ? Mockery.instance.named_mock(name, &block) : Mockery.instance.unnamed_mock(&block) | ||
44 | + mock.expects(expectations) | ||
45 | + mock | ||
46 | + end | ||
47 | + | ||
48 | + # :call-seq: stub(name, &block) -> mock object | ||
49 | + # stub(stubbed_methods = {}, &block) -> mock object | ||
50 | + # stub(name, stubbed_methods = {}, &block) -> mock object | ||
51 | + # | ||
52 | + # Creates a mock object. | ||
53 | + # | ||
54 | + # +name+ is a +String+ identifier for the mock object. | ||
55 | + # | ||
56 | + # +stubbed_methods+ is a +Hash+ with stubbed method name symbols as keys and corresponding return values as values. | ||
57 | + # Note that (contrary to expectations set up by #mock) these expectations <b>need not</b> be fulfilled during the test. | ||
58 | + # def test_product | ||
59 | + # product = stub('ipod_product', :manufacturer => 'ipod', :price => 100) | ||
60 | + # assert_equal 'ipod', product.manufacturer | ||
61 | + # assert_equal 100, product.price | ||
62 | + # # an error will not be raised even if Product#manufacturer and Product#price have not been called | ||
63 | + # end | ||
64 | + # | ||
65 | + # +block+ is an optional block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs. | ||
66 | + # def test_product | ||
67 | + # product = stub('ipod_product') do | ||
68 | + # stubs(:manufacturer).returns('ipod') | ||
69 | + # stubs(:price).returns(100) | ||
70 | + # end | ||
71 | + # assert_equal 'ipod', product.manufacturer | ||
72 | + # assert_equal 100, product.price | ||
73 | + # # an error will not be raised even if Product#manufacturer and Product#price have not been called | ||
74 | + # end | ||
75 | + def stub(*arguments, &block) | ||
76 | + name = arguments.shift if arguments.first.is_a?(String) | ||
77 | + expectations = arguments.shift || {} | ||
78 | + stub = name ? Mockery.instance.named_mock(name, &block) : Mockery.instance.unnamed_mock(&block) | ||
79 | + stub.stubs(expectations) | ||
80 | + stub | ||
81 | + end | ||
82 | + | ||
83 | + # :call-seq: stub_everything(name, &block) -> mock object | ||
84 | + # stub_everything(stubbed_methods = {}, &block) -> mock object | ||
85 | + # stub_everything(name, stubbed_methods = {}, &block) -> mock object | ||
86 | + # | ||
87 | + # Creates a mock object that accepts calls to any method. | ||
88 | + # | ||
89 | + # By default it will return +nil+ for any method call. | ||
90 | + # | ||
91 | + # +block+ is a block to be evaluated against the mock object instance, giving an alernative way to set up expectations & stubs. | ||
92 | + # | ||
93 | + # +name+ and +stubbed_methods+ work in the same way as for #stub. | ||
94 | + # def test_product | ||
95 | + # product = stub_everything('ipod_product', :price => 100) | ||
96 | + # assert_nil product.manufacturer | ||
97 | + # assert_nil product.any_old_method | ||
98 | + # assert_equal 100, product.price | ||
99 | + # end | ||
100 | + def stub_everything(*arguments, &block) | ||
101 | + name = arguments.shift if arguments.first.is_a?(String) | ||
102 | + expectations = arguments.shift || {} | ||
103 | + stub = name ? Mockery.instance.named_mock(name, &block) : Mockery.instance.unnamed_mock(&block) | ||
104 | + stub.stub_everything | ||
105 | + stub.stubs(expectations) | ||
106 | + stub | ||
107 | + end | ||
108 | + | ||
109 | + # :call-seq: sequence(name) -> sequence | ||
110 | + # | ||
111 | + # Returns a new sequence that is used to constrain the order in which expectations can occur. | ||
112 | + # | ||
113 | + # Specify that an expected invocation must occur in within a named +sequence+ by using Expectation#in_sequence. | ||
114 | + # | ||
115 | + # See also Expectation#in_sequence. | ||
116 | + # breakfast = sequence('breakfast') | ||
117 | + # | ||
118 | + # egg = mock('egg') | ||
119 | + # egg.expects(:crack).in_sequence(breakfast) | ||
120 | + # egg.expects(:fry).in_sequence(breakfast) | ||
121 | + # egg.expects(:eat).in_sequence(breakfast) | ||
122 | + def sequence(name) | ||
123 | + Sequence.new(name) | ||
124 | + end | ||
125 | + | ||
126 | + # :call-seq: states(name) -> state_machine | ||
127 | + # | ||
128 | + # Returns a new +state_machine+ that is used to constrain the order in which expectations can occur. | ||
129 | + # | ||
130 | + # Specify the initial +state+ of the +state_machine+ by using StateMachine#starts_as. | ||
131 | + # | ||
132 | + # Specify that an expected invocation should change the +state+ of the +state_machine+ by using Expectation#then. | ||
133 | + # | ||
134 | + # Specify that an expected invocation should be constrained to occur within a particular +state+ by using Expectation#when. | ||
135 | + # | ||
136 | + # A test can contain multiple +state_machines+. | ||
137 | + # | ||
138 | + # See also Expectation#then, Expectation#when and StateMachine. | ||
139 | + # power = states('power').starts_as('off') | ||
140 | + # | ||
141 | + # radio = mock('radio') | ||
142 | + # radio.expects(:switch_on).then(power.is('on')) | ||
143 | + # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on')) | ||
144 | + # radio.expects(:adjust_volume).with(+5).when(power.is('on')) | ||
145 | + # radio.expects(:select_channel).with('BBC World Service').when(power.is('on')) | ||
146 | + # radio.expects(:adjust_volume).with(-5).when(power.is('on')) | ||
147 | + # radio.expects(:switch_off).then(power.is('off')) | ||
148 | + def states(name) | ||
149 | + Mockery.instance.new_state_machine(name) | ||
150 | + end | ||
151 | + | ||
152 | + # Asserts that the given mock received the given method. | ||
153 | + # | ||
154 | + # Examples: | ||
155 | + # | ||
156 | + # assert_received(mock, :to_s) | ||
157 | + # assert_received(Radio, :new) {|expect| expect.with(1041) } | ||
158 | + # assert_received(radio, :volume) {|expect| expect.with(11).twice } | ||
159 | + def assert_received(mock, expected_method_name) | ||
160 | + matcher = have_received(expected_method_name) | ||
161 | + yield(matcher) if block_given? | ||
162 | + assert matcher.matches?(mock), matcher.failure_message | ||
163 | + end | ||
164 | + | ||
165 | + class HaveReceived #:nodoc: | ||
166 | + def initialize(expected_method_name) | ||
167 | + @expected_method_name = expected_method_name | ||
168 | + @expectations = [] | ||
169 | + end | ||
170 | + | ||
171 | + def method_missing(method, *args, &block) | ||
172 | + @expectations << [method, args, block] | ||
173 | + self | ||
174 | + end | ||
175 | + | ||
176 | + def matches?(mock) | ||
177 | + if mock.respond_to?(:mocha) | ||
178 | + @mock = mock.mocha | ||
179 | + else | ||
180 | + @mock = mock | ||
181 | + end | ||
182 | + | ||
183 | + @expectation = Expectation.new(@mock, @expected_method_name) | ||
184 | + @expectations.each do |method, args, block| | ||
185 | + @expectation.send(method, *args, &block) | ||
186 | + end | ||
187 | + @expectation.invocation_count = invocation_count | ||
188 | + @expectation.verified? | ||
189 | + end | ||
190 | + | ||
191 | + def failure_message | ||
192 | + @expectation.mocha_inspect | ||
193 | + end | ||
194 | + | ||
195 | + private | ||
196 | + | ||
197 | + def invocation_count | ||
198 | + matching_invocations.size | ||
199 | + end | ||
200 | + | ||
201 | + def matching_invocations | ||
202 | + invocations.select do |invocation| | ||
203 | + @expectation.match?(invocation.method_name, *invocation.arguments) | ||
204 | + end | ||
205 | + end | ||
206 | + | ||
207 | + def invocations | ||
208 | + Mockery.instance.invocations.select do |invocation| | ||
209 | + invocation.mock.equal?(@mock) | ||
210 | + end | ||
211 | + end | ||
212 | + end | ||
213 | + | ||
214 | + # :call-seq: | ||
215 | + # should have_received(method).with(arguments).times(times) | ||
216 | + # | ||
217 | + # Ensures that the given mock received the given method. | ||
218 | + # | ||
219 | + # Examples: | ||
220 | + # | ||
221 | + # mock.should have_received(:to_s) | ||
222 | + # Radio.should have_received(:new).with(1041) | ||
223 | + # radio.should have_received(:volume).with(11).twice | ||
224 | + def have_received(expected_method_name) | ||
225 | + HaveReceived.new(expected_method_name) | ||
226 | + end | ||
227 | + | ||
228 | + def mocha_setup # :nodoc: | ||
229 | + end | ||
230 | + | ||
231 | + def mocha_verify(assertion_counter = nil) # :nodoc: | ||
232 | + Mockery.instance.verify(assertion_counter) | ||
233 | + end | ||
234 | + | ||
235 | + def mocha_teardown # :nodoc: | ||
236 | + Mockery.instance.teardown | ||
237 | + Mockery.reset_instance | ||
238 | + end | ||
239 | + | ||
240 | + end | ||
241 | + | ||
242 | + def self.const_missing(name) | ||
243 | + return super unless name == :Standalone | ||
244 | + require 'mocha/deprecation' | ||
245 | + Deprecation.warning "Mocha::Standalone has been renamed to Mocha::API" | ||
246 | + return API | ||
247 | + end | ||
248 | + | ||
249 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/argument_iterator.rb
0 → 100644
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + class ArgumentIterator | ||
4 | + | ||
5 | + def initialize(argument) | ||
6 | + @argument = argument | ||
7 | + end | ||
8 | + | ||
9 | + def each(&block) | ||
10 | + if @argument.is_a?(Hash) then | ||
11 | + @argument.each do |method_name, return_value| | ||
12 | + block.call(method_name, return_value) | ||
13 | + end | ||
14 | + else | ||
15 | + block.call(@argument) | ||
16 | + end | ||
17 | + end | ||
18 | + | ||
19 | + end | ||
20 | + | ||
21 | +end | ||
0 | \ No newline at end of file | 22 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/backtrace_filter.rb
0 → 100644
@@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + class BacktraceFilter | ||
4 | + | ||
5 | + LIB_DIRECTORY = File.expand_path(File.join(File.dirname(__FILE__), "..")) + File::SEPARATOR | ||
6 | + | ||
7 | + def initialize(lib_directory = LIB_DIRECTORY) | ||
8 | + @lib_directory = lib_directory | ||
9 | + end | ||
10 | + | ||
11 | + def filtered(backtrace) | ||
12 | + backtrace.reject { |location| Regexp.new(@lib_directory).match(File.expand_path(location)) } | ||
13 | + end | ||
14 | + | ||
15 | + end | ||
16 | + | ||
17 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/cardinality.rb
0 → 100644
@@ -0,0 +1,95 @@ | @@ -0,0 +1,95 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + class Cardinality | ||
4 | + | ||
5 | + INFINITY = 1 / 0.0 | ||
6 | + | ||
7 | + class << self | ||
8 | + | ||
9 | + def exactly(count) | ||
10 | + new(count, count) | ||
11 | + end | ||
12 | + | ||
13 | + def at_least(count) | ||
14 | + new(count, INFINITY) | ||
15 | + end | ||
16 | + | ||
17 | + def at_most(count) | ||
18 | + new(0, count) | ||
19 | + end | ||
20 | + | ||
21 | + def times(range_or_count) | ||
22 | + case range_or_count | ||
23 | + when Range then new(range_or_count.first, range_or_count.last) | ||
24 | + else new(range_or_count, range_or_count) | ||
25 | + end | ||
26 | + end | ||
27 | + | ||
28 | + end | ||
29 | + | ||
30 | + def initialize(required, maximum) | ||
31 | + @required, @maximum = required, maximum | ||
32 | + end | ||
33 | + | ||
34 | + def invocations_allowed?(invocation_count) | ||
35 | + invocation_count < maximum | ||
36 | + end | ||
37 | + | ||
38 | + def satisfied?(invocations_so_far) | ||
39 | + invocations_so_far >= required | ||
40 | + end | ||
41 | + | ||
42 | + def needs_verifying? | ||
43 | + !allowed_any_number_of_times? | ||
44 | + end | ||
45 | + | ||
46 | + def verified?(invocation_count) | ||
47 | + (invocation_count >= required) && (invocation_count <= maximum) | ||
48 | + end | ||
49 | + | ||
50 | + def allowed_any_number_of_times? | ||
51 | + required == 0 && infinite?(maximum) | ||
52 | + end | ||
53 | + | ||
54 | + def used?(invocation_count) | ||
55 | + (invocation_count > 0) || (maximum == 0) | ||
56 | + end | ||
57 | + | ||
58 | + def mocha_inspect | ||
59 | + if allowed_any_number_of_times? | ||
60 | + "allowed any number of times" | ||
61 | + else | ||
62 | + if required == 0 && maximum == 0 | ||
63 | + "expected never" | ||
64 | + elsif required == maximum | ||
65 | + "expected exactly #{times(required)}" | ||
66 | + elsif infinite?(maximum) | ||
67 | + "expected at least #{times(required)}" | ||
68 | + elsif required == 0 | ||
69 | + "expected at most #{times(maximum)}" | ||
70 | + else | ||
71 | + "expected between #{required} and #{times(maximum)}" | ||
72 | + end | ||
73 | + end | ||
74 | + end | ||
75 | + | ||
76 | + protected | ||
77 | + | ||
78 | + attr_reader :required, :maximum | ||
79 | + | ||
80 | + def times(number) | ||
81 | + case number | ||
82 | + when 0 then "no times" | ||
83 | + when 1 then "once" | ||
84 | + when 2 then "twice" | ||
85 | + else "#{number} times" | ||
86 | + end | ||
87 | + end | ||
88 | + | ||
89 | + def infinite?(number) | ||
90 | + number.respond_to?(:infinite?) && number.infinite? | ||
91 | + end | ||
92 | + | ||
93 | + end | ||
94 | + | ||
95 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/central.rb
0 → 100644
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + class Central | ||
4 | + | ||
5 | + attr_accessor :stubba_methods | ||
6 | + | ||
7 | + def initialize | ||
8 | + self.stubba_methods = [] | ||
9 | + end | ||
10 | + | ||
11 | + def stub(method) | ||
12 | + unless stubba_methods.include?(method) | ||
13 | + method.stub | ||
14 | + stubba_methods.push(method) | ||
15 | + end | ||
16 | + end | ||
17 | + | ||
18 | + def unstub_all | ||
19 | + while stubba_methods.length > 0 | ||
20 | + method = stubba_methods.pop | ||
21 | + method.unstub | ||
22 | + end | ||
23 | + end | ||
24 | + | ||
25 | + end | ||
26 | + | ||
27 | +end | ||
0 | \ No newline at end of file | 28 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/change_state_side_effect.rb
0 → 100644
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + class ChangeStateSideEffect | ||
4 | + | ||
5 | + def initialize(state) | ||
6 | + @state = state | ||
7 | + end | ||
8 | + | ||
9 | + def perform | ||
10 | + @state.activate | ||
11 | + end | ||
12 | + | ||
13 | + def mocha_inspect | ||
14 | + "then #{@state.mocha_inspect}" | ||
15 | + end | ||
16 | + | ||
17 | + end | ||
18 | + | ||
19 | +end | ||
0 | \ No newline at end of file | 20 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/class_method.rb
0 → 100644
@@ -0,0 +1,87 @@ | @@ -0,0 +1,87 @@ | ||
1 | +require 'mocha/metaclass' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + class ClassMethod | ||
6 | + | ||
7 | + attr_reader :stubbee, :method | ||
8 | + | ||
9 | + def initialize(stubbee, method) | ||
10 | + @stubbee = stubbee | ||
11 | + @method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym | ||
12 | + end | ||
13 | + | ||
14 | + def stub | ||
15 | + hide_original_method | ||
16 | + define_new_method | ||
17 | + end | ||
18 | + | ||
19 | + def unstub | ||
20 | + remove_new_method | ||
21 | + restore_original_method | ||
22 | + stubbee.reset_mocha | ||
23 | + end | ||
24 | + | ||
25 | + def mock | ||
26 | + stubbee.mocha | ||
27 | + end | ||
28 | + | ||
29 | + def hide_original_method | ||
30 | + if method_exists?(method) | ||
31 | + begin | ||
32 | + stubbee.__metaclass__.send(:alias_method, hidden_method, method) | ||
33 | + rescue NameError | ||
34 | + # deal with nasties like ActiveRecord::Associations::AssociationProxy | ||
35 | + end | ||
36 | + end | ||
37 | + end | ||
38 | + | ||
39 | + def define_new_method | ||
40 | + stubbee.__metaclass__.class_eval("def #{method}(*args, &block); mocha.method_missing(:#{method}, *args, &block); end", __FILE__, __LINE__) | ||
41 | + end | ||
42 | + | ||
43 | + def remove_new_method | ||
44 | + stubbee.__metaclass__.send(:remove_method, method) | ||
45 | + end | ||
46 | + | ||
47 | + def restore_original_method | ||
48 | + if method_exists?(hidden_method) | ||
49 | + begin | ||
50 | + stubbee.__metaclass__.send(:alias_method, method, hidden_method) | ||
51 | + stubbee.__metaclass__.send(:remove_method, hidden_method) | ||
52 | + rescue NameError | ||
53 | + # deal with nasties like ActiveRecord::Associations::AssociationProxy | ||
54 | + end | ||
55 | + end | ||
56 | + end | ||
57 | + | ||
58 | + def hidden_method | ||
59 | + if RUBY_VERSION < '1.9' | ||
60 | + method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s[0]}_" } | ||
61 | + else | ||
62 | + method_name = method.to_s.gsub(/\W/) { |s| "_substituted_character_#{s.ord}_" } | ||
63 | + end | ||
64 | + hidden_method = "__stubba__#{method_name}__stubba__" | ||
65 | + RUBY_VERSION < '1.9' ? hidden_method.to_s : hidden_method.to_sym | ||
66 | + end | ||
67 | + | ||
68 | + def eql?(other) | ||
69 | + return false unless (other.class == self.class) | ||
70 | + (stubbee.object_id == other.stubbee.object_id) and (method == other.method) | ||
71 | + end | ||
72 | + | ||
73 | + alias_method :==, :eql? | ||
74 | + | ||
75 | + def to_s | ||
76 | + "#{stubbee}.#{method}" | ||
77 | + end | ||
78 | + | ||
79 | + def method_exists?(method) | ||
80 | + symbol = method.to_sym | ||
81 | + metaclass = stubbee.__metaclass__ | ||
82 | + metaclass.public_method_defined?(symbol) || metaclass.protected_method_defined?(symbol) || metaclass.private_method_defined?(symbol) | ||
83 | + end | ||
84 | + | ||
85 | + end | ||
86 | + | ||
87 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/configuration.rb
0 → 100644
@@ -0,0 +1,60 @@ | @@ -0,0 +1,60 @@ | ||
1 | +module Mocha # :nodoc: | ||
2 | + | ||
3 | + # Configuration settings | ||
4 | + class Configuration | ||
5 | + | ||
6 | + DEFAULTS = { :stubbing_method_unnecessarily => :allow, :stubbing_method_on_non_mock_object => :allow, :stubbing_non_existent_method => :allow, :stubbing_non_public_method => :allow } | ||
7 | + | ||
8 | + class << self | ||
9 | + | ||
10 | + # :call-seq: allow(action) | ||
11 | + # | ||
12 | + # Allow the specified <tt>action</tt> (as a symbol). | ||
13 | + # The <tt>actions</tt> currently available are <tt>:stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method</tt>. | ||
14 | + def allow(action) | ||
15 | + configuration[action] = :allow | ||
16 | + end | ||
17 | + | ||
18 | + def allow?(action) # :nodoc: | ||
19 | + configuration[action] == :allow | ||
20 | + end | ||
21 | + | ||
22 | + # :call-seq: warn_when(action) | ||
23 | + # | ||
24 | + # Warn if the specified <tt>action</tt> (as a symbol) is attempted. | ||
25 | + # The <tt>actions</tt> currently available are <tt>:stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method</tt>. | ||
26 | + def warn_when(action) | ||
27 | + configuration[action] = :warn | ||
28 | + end | ||
29 | + | ||
30 | + def warn_when?(action) # :nodoc: | ||
31 | + configuration[action] == :warn | ||
32 | + end | ||
33 | + | ||
34 | + # :call-seq: prevent(action) | ||
35 | + # | ||
36 | + # Raise a StubbingError if the specified <tt>action</tt> (as a symbol) is attempted. | ||
37 | + # The <tt>actions</tt> currently available are <tt>:stubbing_method_unnecessarily, :stubbing_method_on_non_mock_object, :stubbing_non_existent_method, :stubbing_non_public_method</tt>. | ||
38 | + def prevent(action) | ||
39 | + configuration[action] = :prevent | ||
40 | + end | ||
41 | + | ||
42 | + def prevent?(action) # :nodoc: | ||
43 | + configuration[action] == :prevent | ||
44 | + end | ||
45 | + | ||
46 | + def reset_configuration # :nodoc: | ||
47 | + @configuration = nil | ||
48 | + end | ||
49 | + | ||
50 | + private | ||
51 | + | ||
52 | + def configuration # :nodoc: | ||
53 | + @configuration ||= DEFAULTS.dup | ||
54 | + end | ||
55 | + | ||
56 | + end | ||
57 | + | ||
58 | + end | ||
59 | + | ||
60 | +end | ||
0 | \ No newline at end of file | 61 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/deprecation.rb
0 → 100644
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + class Deprecation | ||
4 | + | ||
5 | + class << self | ||
6 | + | ||
7 | + attr_accessor :mode, :messages | ||
8 | + | ||
9 | + def warning(message) | ||
10 | + @messages << message | ||
11 | + $stderr.puts "Mocha deprecation warning: #{message}" unless mode == :disabled | ||
12 | + $stderr.puts caller.join("\n ") if mode == :debug | ||
13 | + end | ||
14 | + | ||
15 | + end | ||
16 | + | ||
17 | + self.mode = :enabled | ||
18 | + self.messages = [] | ||
19 | + | ||
20 | + end | ||
21 | + | ||
22 | +end | ||
0 | \ No newline at end of file | 23 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/exception_raiser.rb
0 → 100644
@@ -0,0 +1,17 @@ | @@ -0,0 +1,17 @@ | ||
1 | +module Mocha # :nodoc: | ||
2 | + | ||
3 | + class ExceptionRaiser # :nodoc: | ||
4 | + | ||
5 | + def initialize(exception, message) | ||
6 | + @exception, @message = exception, message | ||
7 | + end | ||
8 | + | ||
9 | + def evaluate | ||
10 | + raise @exception, @exception.to_s if @exception.is_a?(Module) && @exception.ancestors.include?(Interrupt) | ||
11 | + raise @exception, @message if @message | ||
12 | + raise @exception | ||
13 | + end | ||
14 | + | ||
15 | + end | ||
16 | + | ||
17 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation.rb
0 → 100644
@@ -0,0 +1,484 @@ | @@ -0,0 +1,484 @@ | ||
1 | +require 'mocha/method_matcher' | ||
2 | +require 'mocha/parameters_matcher' | ||
3 | +require 'mocha/expectation_error' | ||
4 | +require 'mocha/return_values' | ||
5 | +require 'mocha/exception_raiser' | ||
6 | +require 'mocha/yield_parameters' | ||
7 | +require 'mocha/is_a' | ||
8 | +require 'mocha/in_state_ordering_constraint' | ||
9 | +require 'mocha/change_state_side_effect' | ||
10 | +require 'mocha/cardinality' | ||
11 | + | ||
12 | +module Mocha # :nodoc: | ||
13 | + | ||
14 | + # Methods on expectations returned from Mock#expects, Mock#stubs, Object#expects and Object#stubs. | ||
15 | + class Expectation | ||
16 | + | ||
17 | + # :call-seq: times(range) -> expectation | ||
18 | + # | ||
19 | + # Modifies expectation so that the number of calls to the expected method must be within a specific +range+. | ||
20 | + # | ||
21 | + # +range+ can be specified as an exact integer or as a range of integers | ||
22 | + # object = mock() | ||
23 | + # object.expects(:expected_method).times(3) | ||
24 | + # 3.times { object.expected_method } | ||
25 | + # # => verify succeeds | ||
26 | + # | ||
27 | + # object = mock() | ||
28 | + # object.expects(:expected_method).times(3) | ||
29 | + # 2.times { object.expected_method } | ||
30 | + # # => verify fails | ||
31 | + # | ||
32 | + # object = mock() | ||
33 | + # object.expects(:expected_method).times(2..4) | ||
34 | + # 3.times { object.expected_method } | ||
35 | + # # => verify succeeds | ||
36 | + # | ||
37 | + # object = mock() | ||
38 | + # object.expects(:expected_method).times(2..4) | ||
39 | + # object.expected_method | ||
40 | + # # => verify fails | ||
41 | + def times(range) | ||
42 | + @cardinality = Cardinality.times(range) | ||
43 | + self | ||
44 | + end | ||
45 | + | ||
46 | + # :call-seq: twice() -> expectation | ||
47 | + # | ||
48 | + # Modifies expectation so that the expected method must be called exactly twice. | ||
49 | + # object = mock() | ||
50 | + # object.expects(:expected_method).twice | ||
51 | + # object.expected_method | ||
52 | + # object.expected_method | ||
53 | + # # => verify succeeds | ||
54 | + # | ||
55 | + # object = mock() | ||
56 | + # object.expects(:expected_method).twice | ||
57 | + # object.expected_method | ||
58 | + # object.expected_method | ||
59 | + # object.expected_method | ||
60 | + # # => verify fails | ||
61 | + # | ||
62 | + # object = mock() | ||
63 | + # object.expects(:expected_method).twice | ||
64 | + # object.expected_method | ||
65 | + # # => verify fails | ||
66 | + def twice | ||
67 | + @cardinality = Cardinality.exactly(2) | ||
68 | + self | ||
69 | + end | ||
70 | + | ||
71 | + # :call-seq: once() -> expectation | ||
72 | + # | ||
73 | + # Modifies expectation so that the expected method must be called exactly once. | ||
74 | + # Note that this is the default behaviour for an expectation, but you may wish to use it for clarity/emphasis. | ||
75 | + # object = mock() | ||
76 | + # object.expects(:expected_method).once | ||
77 | + # object.expected_method | ||
78 | + # # => verify succeeds | ||
79 | + # | ||
80 | + # object = mock() | ||
81 | + # object.expects(:expected_method).once | ||
82 | + # object.expected_method | ||
83 | + # object.expected_method | ||
84 | + # # => verify fails | ||
85 | + # | ||
86 | + # object = mock() | ||
87 | + # object.expects(:expected_method).once | ||
88 | + # # => verify fails | ||
89 | + def once | ||
90 | + @cardinality = Cardinality.exactly(1) | ||
91 | + self | ||
92 | + end | ||
93 | + | ||
94 | + # :call-seq: never() -> expectation | ||
95 | + # | ||
96 | + # Modifies expectation so that the expected method must never be called. | ||
97 | + # object = mock() | ||
98 | + # object.expects(:expected_method).never | ||
99 | + # object.expected_method | ||
100 | + # # => verify fails | ||
101 | + # | ||
102 | + # object = mock() | ||
103 | + # object.expects(:expected_method).never | ||
104 | + # object.expected_method | ||
105 | + # # => verify succeeds | ||
106 | + def never | ||
107 | + @cardinality = Cardinality.exactly(0) | ||
108 | + self | ||
109 | + end | ||
110 | + | ||
111 | + # :call-seq: at_least(minimum_number_of_times) -> expectation | ||
112 | + # | ||
113 | + # Modifies expectation so that the expected method must be called at least a +minimum_number_of_times+. | ||
114 | + # object = mock() | ||
115 | + # object.expects(:expected_method).at_least(2) | ||
116 | + # 3.times { object.expected_method } | ||
117 | + # # => verify succeeds | ||
118 | + # | ||
119 | + # object = mock() | ||
120 | + # object.expects(:expected_method).at_least(2) | ||
121 | + # object.expected_method | ||
122 | + # # => verify fails | ||
123 | + def at_least(minimum_number_of_times) | ||
124 | + @cardinality = Cardinality.at_least(minimum_number_of_times) | ||
125 | + self | ||
126 | + end | ||
127 | + | ||
128 | + # :call-seq: at_least_once() -> expectation | ||
129 | + # | ||
130 | + # Modifies expectation so that the expected method must be called at least once. | ||
131 | + # object = mock() | ||
132 | + # object.expects(:expected_method).at_least_once | ||
133 | + # object.expected_method | ||
134 | + # # => verify succeeds | ||
135 | + # | ||
136 | + # object = mock() | ||
137 | + # object.expects(:expected_method).at_least_once | ||
138 | + # # => verify fails | ||
139 | + def at_least_once | ||
140 | + at_least(1) | ||
141 | + self | ||
142 | + end | ||
143 | + | ||
144 | + # :call-seq: at_most(maximum_number_of_times) -> expectation | ||
145 | + # | ||
146 | + # Modifies expectation so that the expected method must be called at most a +maximum_number_of_times+. | ||
147 | + # object = mock() | ||
148 | + # object.expects(:expected_method).at_most(2) | ||
149 | + # 2.times { object.expected_method } | ||
150 | + # # => verify succeeds | ||
151 | + # | ||
152 | + # object = mock() | ||
153 | + # object.expects(:expected_method).at_most(2) | ||
154 | + # 3.times { object.expected_method } | ||
155 | + # # => verify fails | ||
156 | + def at_most(maximum_number_of_times) | ||
157 | + @cardinality = Cardinality.at_most(maximum_number_of_times) | ||
158 | + self | ||
159 | + end | ||
160 | + | ||
161 | + # :call-seq: at_most_once() -> expectation | ||
162 | + # | ||
163 | + # Modifies expectation so that the expected method must be called at most once. | ||
164 | + # object = mock() | ||
165 | + # object.expects(:expected_method).at_most_once | ||
166 | + # object.expected_method | ||
167 | + # # => verify succeeds | ||
168 | + # | ||
169 | + # object = mock() | ||
170 | + # object.expects(:expected_method).at_most_once | ||
171 | + # 2.times { object.expected_method } | ||
172 | + # # => verify fails | ||
173 | + def at_most_once() | ||
174 | + at_most(1) | ||
175 | + self | ||
176 | + end | ||
177 | + | ||
178 | + # :call-seq: with(*expected_parameters, &matching_block) -> expectation | ||
179 | + # | ||
180 | + # Modifies expectation so that the expected method must be called with +expected_parameters+. | ||
181 | + # object = mock() | ||
182 | + # object.expects(:expected_method).with(:param1, :param2) | ||
183 | + # object.expected_method(:param1, :param2) | ||
184 | + # # => verify succeeds | ||
185 | + # | ||
186 | + # object = mock() | ||
187 | + # object.expects(:expected_method).with(:param1, :param2) | ||
188 | + # object.expected_method(:param3) | ||
189 | + # # => verify fails | ||
190 | + # May be used with parameter matchers in Mocha::ParameterMatchers. | ||
191 | + # | ||
192 | + # If a +matching_block+ is given, the block is called with the parameters passed to the expected method. | ||
193 | + # The expectation is matched if the block evaluates to +true+. | ||
194 | + # object = mock() | ||
195 | + # object.expects(:expected_method).with() { |value| value % 4 == 0 } | ||
196 | + # object.expected_method(16) | ||
197 | + # # => verify succeeds | ||
198 | + # | ||
199 | + # object = mock() | ||
200 | + # object.expects(:expected_method).with() { |value| value % 4 == 0 } | ||
201 | + # object.expected_method(17) | ||
202 | + # # => verify fails | ||
203 | + def with(*expected_parameters, &matching_block) | ||
204 | + @parameters_matcher = ParametersMatcher.new(expected_parameters, &matching_block) | ||
205 | + self | ||
206 | + end | ||
207 | + | ||
208 | + # :call-seq: yields(*parameters) -> expectation | ||
209 | + # | ||
210 | + # Modifies expectation so that when the expected method is called, it yields with the specified +parameters+. | ||
211 | + # object = mock() | ||
212 | + # object.expects(:expected_method).yields('result') | ||
213 | + # yielded_value = nil | ||
214 | + # object.expected_method { |value| yielded_value = value } | ||
215 | + # yielded_value # => 'result' | ||
216 | + # May be called multiple times on the same expectation for consecutive invocations. Also see Expectation#then. | ||
217 | + # object = mock() | ||
218 | + # object.stubs(:expected_method).yields(1).then.yields(2) | ||
219 | + # yielded_values_from_first_invocation = [] | ||
220 | + # yielded_values_from_second_invocation = [] | ||
221 | + # object.expected_method { |value| yielded_values_from_first_invocation << value } # first invocation | ||
222 | + # object.expected_method { |value| yielded_values_from_second_invocation << value } # second invocation | ||
223 | + # yielded_values_from_first_invocation # => [1] | ||
224 | + # yielded_values_from_second_invocation # => [2] | ||
225 | + def yields(*parameters) | ||
226 | + @yield_parameters.add(*parameters) | ||
227 | + self | ||
228 | + end | ||
229 | + | ||
230 | + # :call-seq: multiple_yields(*parameter_groups) -> expectation | ||
231 | + # | ||
232 | + # Modifies expectation so that when the expected method is called, it yields multiple times per invocation with the specified +parameter_groups+. | ||
233 | + # object = mock() | ||
234 | + # object.expects(:expected_method).multiple_yields(['result_1', 'result_2'], ['result_3']) | ||
235 | + # yielded_values = [] | ||
236 | + # object.expected_method { |*values| yielded_values << values } | ||
237 | + # yielded_values # => [['result_1', 'result_2'], ['result_3]] | ||
238 | + # May be called multiple times on the same expectation for consecutive invocations. Also see Expectation#then. | ||
239 | + # object = mock() | ||
240 | + # object.stubs(:expected_method).multiple_yields([1, 2], [3]).then.multiple_yields([4], [5, 6]) | ||
241 | + # yielded_values_from_first_invocation = [] | ||
242 | + # yielded_values_from_second_invocation = [] | ||
243 | + # object.expected_method { |*values| yielded_values_from_first_invocation << values } # first invocation | ||
244 | + # object.expected_method { |*values| yielded_values_from_second_invocation << values } # second invocation | ||
245 | + # yielded_values_from_first_invocation # => [[1, 2], [3]] | ||
246 | + # yielded_values_from_second_invocation # => [[4], [5, 6]] | ||
247 | + def multiple_yields(*parameter_groups) | ||
248 | + @yield_parameters.multiple_add(*parameter_groups) | ||
249 | + self | ||
250 | + end | ||
251 | + | ||
252 | + # :call-seq: returns(value) -> expectation | ||
253 | + # returns(*values) -> expectation | ||
254 | + # | ||
255 | + # Modifies expectation so that when the expected method is called, it returns the specified +value+. | ||
256 | + # object = mock() | ||
257 | + # object.stubs(:stubbed_method).returns('result') | ||
258 | + # object.stubbed_method # => 'result' | ||
259 | + # object.stubbed_method # => 'result' | ||
260 | + # If multiple +values+ are given, these are returned in turn on consecutive calls to the method. | ||
261 | + # object = mock() | ||
262 | + # object.stubs(:stubbed_method).returns(1, 2) | ||
263 | + # object.stubbed_method # => 1 | ||
264 | + # object.stubbed_method # => 2 | ||
265 | + # May be called multiple times on the same expectation. Also see Expectation#then. | ||
266 | + # object = mock() | ||
267 | + # object.stubs(:expected_method).returns(1, 2).then.returns(3) | ||
268 | + # object.expected_method # => 1 | ||
269 | + # object.expected_method # => 2 | ||
270 | + # object.expected_method # => 3 | ||
271 | + # May be called in conjunction with Expectation#raises on the same expectation. | ||
272 | + # object = mock() | ||
273 | + # object.stubs(:expected_method).returns(1, 2).then.raises(Exception) | ||
274 | + # object.expected_method # => 1 | ||
275 | + # object.expected_method # => 2 | ||
276 | + # object.expected_method # => raises exception of class Exception1 | ||
277 | + # Note that in Ruby a method returning multiple values is exactly equivalent to a method returning an Array of those values. | ||
278 | + # object = mock() | ||
279 | + # object.stubs(:expected_method).returns([1, 2]) | ||
280 | + # x, y = object.expected_method | ||
281 | + # x # => 1 | ||
282 | + # y # => 2 | ||
283 | + def returns(*values) | ||
284 | + @return_values += ReturnValues.build(*values) | ||
285 | + self | ||
286 | + end | ||
287 | + | ||
288 | + # :call-seq: raises(exception = RuntimeError, message = nil) -> expectation | ||
289 | + # | ||
290 | + # Modifies expectation so that when the expected method is called, it raises the specified +exception+ with the specified +message+. | ||
291 | + # object = mock() | ||
292 | + # object.expects(:expected_method).raises(Exception, 'message') | ||
293 | + # object.expected_method # => raises exception of class Exception and with message 'message' | ||
294 | + # May be called multiple times on the same expectation. Also see Expectation#then. | ||
295 | + # object = mock() | ||
296 | + # object.stubs(:expected_method).raises(Exception1).then.raises(Exception2) | ||
297 | + # object.expected_method # => raises exception of class Exception1 | ||
298 | + # object.expected_method # => raises exception of class Exception2 | ||
299 | + # May be called in conjunction with Expectation#returns on the same expectation. | ||
300 | + # object = mock() | ||
301 | + # object.stubs(:expected_method).raises(Exception).then.returns(2, 3) | ||
302 | + # object.expected_method # => raises exception of class Exception1 | ||
303 | + # object.expected_method # => 2 | ||
304 | + # object.expected_method # => 3 | ||
305 | + def raises(exception = RuntimeError, message = nil) | ||
306 | + @return_values += ReturnValues.new(ExceptionRaiser.new(exception, message)) | ||
307 | + self | ||
308 | + end | ||
309 | + | ||
310 | + # :call-seq: then() -> expectation | ||
311 | + # then(state_machine.is(state)) -> expectation | ||
312 | + # | ||
313 | + # <tt>then()</tt> is used as syntactic sugar to improve readability. It has no effect on state of the expectation. | ||
314 | + # object = mock() | ||
315 | + # object.stubs(:expected_method).returns(1, 2).then.raises(Exception).then.returns(4) | ||
316 | + # object.expected_method # => 1 | ||
317 | + # object.expected_method # => 2 | ||
318 | + # object.expected_method # => raises exception of class Exception | ||
319 | + # object.expected_method # => 4 | ||
320 | + # | ||
321 | + # <tt>then(state_machine.is(state))</tt> is used to change the +state_machine+ to the specified +state+ when the invocation occurs. | ||
322 | + # | ||
323 | + # See also API#states, StateMachine and Expectation#when. | ||
324 | + # power = states('power').starts_as('off') | ||
325 | + # | ||
326 | + # radio = mock('radio') | ||
327 | + # radio.expects(:switch_on).then(power.is('on')) | ||
328 | + # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on')) | ||
329 | + # radio.expects(:adjust_volume).with(+5).when(power.is('on')) | ||
330 | + # radio.expects(:select_channel).with('BBC World Service').when(power.is('on')) | ||
331 | + # radio.expects(:adjust_volume).with(-5).when(power.is('on')) | ||
332 | + # radio.expects(:switch_off).then(power.is('off')) | ||
333 | + def then(*parameters) | ||
334 | + if parameters.length == 1 | ||
335 | + state = parameters.first | ||
336 | + add_side_effect(ChangeStateSideEffect.new(state)) | ||
337 | + end | ||
338 | + self | ||
339 | + end | ||
340 | + | ||
341 | + # :call-seq: when(state_machine.is(state)) -> exception | ||
342 | + # | ||
343 | + # Constrains the expectation to occur only when the +state_machine+ is in the named +state+. | ||
344 | + # | ||
345 | + # See also API#states, StateMachine#starts_as and Expectation#then. | ||
346 | + # power = states('power').starts_as('off') | ||
347 | + # | ||
348 | + # radio = mock('radio') | ||
349 | + # radio.expects(:switch_on).then(power.is('on')) | ||
350 | + # radio.expects(:select_channel).with('BBC Radio 4').when(power.is('on')) | ||
351 | + # radio.expects(:adjust_volume).with(+5).when(power.is('on')) | ||
352 | + # radio.expects(:select_channel).with('BBC World Service').when(power.is('on')) | ||
353 | + # radio.expects(:adjust_volume).with(-5).when(power.is('on')) | ||
354 | + # radio.expects(:switch_off).then(power.is('off')) | ||
355 | + def when(state_predicate) | ||
356 | + add_ordering_constraint(InStateOrderingConstraint.new(state_predicate)) | ||
357 | + self | ||
358 | + end | ||
359 | + | ||
360 | + # :call-seq: in_sequence(*sequences) -> expectation | ||
361 | + # | ||
362 | + # Constrains this expectation so that it must be invoked at the current point in the sequence. | ||
363 | + # | ||
364 | + # To expect a sequence of invocations, write the expectations in order and add the in_sequence(sequence) clause to each one. | ||
365 | + # | ||
366 | + # Expectations in a sequence can have any invocation count. | ||
367 | + # | ||
368 | + # If an expectation in a sequence is stubbed, rather than expected, it can be skipped in the sequence. | ||
369 | + # | ||
370 | + # See also API#sequence. | ||
371 | + # breakfast = sequence('breakfast') | ||
372 | + # | ||
373 | + # egg = mock('egg') | ||
374 | + # egg.expects(:crack).in_sequence(breakfast) | ||
375 | + # egg.expects(:fry).in_sequence(breakfast) | ||
376 | + # egg.expects(:eat).in_sequence(breakfast) | ||
377 | + def in_sequence(*sequences) | ||
378 | + sequences.each { |sequence| add_in_sequence_ordering_constraint(sequence) } | ||
379 | + self | ||
380 | + end | ||
381 | + | ||
382 | + # :stopdoc: | ||
383 | + | ||
384 | + attr_reader :backtrace | ||
385 | + attr_accessor :invocation_count | ||
386 | + | ||
387 | + def initialize(mock, expected_method_name, backtrace = nil) | ||
388 | + @mock = mock | ||
389 | + @method_matcher = MethodMatcher.new(expected_method_name.to_sym) | ||
390 | + @parameters_matcher = ParametersMatcher.new | ||
391 | + @ordering_constraints = [] | ||
392 | + @side_effects = [] | ||
393 | + @cardinality, @invocation_count = Cardinality.exactly(1), 0 | ||
394 | + @return_values = ReturnValues.new | ||
395 | + @yield_parameters = YieldParameters.new | ||
396 | + @backtrace = backtrace || caller | ||
397 | + end | ||
398 | + | ||
399 | + def add_ordering_constraint(ordering_constraint) | ||
400 | + @ordering_constraints << ordering_constraint | ||
401 | + end | ||
402 | + | ||
403 | + def add_in_sequence_ordering_constraint(sequence) | ||
404 | + sequence.constrain_as_next_in_sequence(self) | ||
405 | + end | ||
406 | + | ||
407 | + def add_side_effect(side_effect) | ||
408 | + @side_effects << side_effect | ||
409 | + end | ||
410 | + | ||
411 | + def perform_side_effects | ||
412 | + @side_effects.each { |side_effect| side_effect.perform } | ||
413 | + end | ||
414 | + | ||
415 | + def in_correct_order? | ||
416 | + @ordering_constraints.all? { |ordering_constraint| ordering_constraint.allows_invocation_now? } | ||
417 | + end | ||
418 | + | ||
419 | + def matches_method?(method_name) | ||
420 | + @method_matcher.match?(method_name) | ||
421 | + end | ||
422 | + | ||
423 | + def match?(actual_method_name, *actual_parameters) | ||
424 | + @method_matcher.match?(actual_method_name) && @parameters_matcher.match?(actual_parameters) && in_correct_order? | ||
425 | + end | ||
426 | + | ||
427 | + def invocations_allowed? | ||
428 | + @cardinality.invocations_allowed?(@invocation_count) | ||
429 | + end | ||
430 | + | ||
431 | + def satisfied? | ||
432 | + @cardinality.satisfied?(@invocation_count) | ||
433 | + end | ||
434 | + | ||
435 | + def invoke(args) | ||
436 | + @invocation_count += 1 | ||
437 | + Mockery.instance.invocation(@mock, method_name, args) | ||
438 | + perform_side_effects() | ||
439 | + if block_given? then | ||
440 | + @yield_parameters.next_invocation.each do |yield_parameters| | ||
441 | + yield(*yield_parameters) | ||
442 | + end | ||
443 | + end | ||
444 | + @return_values.next | ||
445 | + end | ||
446 | + | ||
447 | + def verified?(assertion_counter = nil) | ||
448 | + assertion_counter.increment if assertion_counter && @cardinality.needs_verifying? | ||
449 | + @cardinality.verified?(@invocation_count) | ||
450 | + end | ||
451 | + | ||
452 | + def used? | ||
453 | + @cardinality.used?(@invocation_count) | ||
454 | + end | ||
455 | + | ||
456 | + def mocha_inspect | ||
457 | + message = "#{@cardinality.mocha_inspect}, " | ||
458 | + message << case @invocation_count | ||
459 | + when 0 then "not yet invoked" | ||
460 | + when 1 then "already invoked once" | ||
461 | + when 2 then "already invoked twice" | ||
462 | + else "already invoked #{@invocation_count} times" | ||
463 | + end | ||
464 | + message << ": " | ||
465 | + message << method_signature | ||
466 | + message << "; #{@ordering_constraints.map { |oc| oc.mocha_inspect }.join("; ")}" unless @ordering_constraints.empty? | ||
467 | + message | ||
468 | + end | ||
469 | + | ||
470 | + def method_signature | ||
471 | + "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}" | ||
472 | + end | ||
473 | + | ||
474 | + private | ||
475 | + | ||
476 | + def method_name | ||
477 | + @method_matcher.expected_method_name | ||
478 | + end | ||
479 | + | ||
480 | + # :startdoc: | ||
481 | + | ||
482 | + end | ||
483 | + | ||
484 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation_error.rb
0 → 100644
@@ -0,0 +1,15 @@ | @@ -0,0 +1,15 @@ | ||
1 | +require 'mocha/backtrace_filter' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + class ExpectationError < StandardError | ||
6 | + | ||
7 | + def initialize(message = nil, backtrace = []) | ||
8 | + super(message) | ||
9 | + filter = BacktraceFilter.new | ||
10 | + set_backtrace(filter.filtered(backtrace)) | ||
11 | + end | ||
12 | + | ||
13 | + end | ||
14 | + | ||
15 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/expectation_list.rb
0 → 100644
@@ -0,0 +1,50 @@ | @@ -0,0 +1,50 @@ | ||
1 | +module Mocha # :nodoc: | ||
2 | + | ||
3 | + class ExpectationList | ||
4 | + | ||
5 | + def initialize | ||
6 | + @expectations = [] | ||
7 | + end | ||
8 | + | ||
9 | + def add(expectation) | ||
10 | + @expectations.unshift(expectation) | ||
11 | + expectation | ||
12 | + end | ||
13 | + | ||
14 | + def matches_method?(method_name) | ||
15 | + @expectations.any? { |expectation| expectation.matches_method?(method_name) } | ||
16 | + end | ||
17 | + | ||
18 | + def match(method_name, *arguments) | ||
19 | + matching_expectations(method_name, *arguments).first | ||
20 | + end | ||
21 | + | ||
22 | + def match_allowing_invocation(method_name, *arguments) | ||
23 | + matching_expectations(method_name, *arguments).detect { |e| e.invocations_allowed? } | ||
24 | + end | ||
25 | + | ||
26 | + def verified?(assertion_counter = nil) | ||
27 | + @expectations.all? { |expectation| expectation.verified?(assertion_counter) } | ||
28 | + end | ||
29 | + | ||
30 | + def to_a | ||
31 | + @expectations | ||
32 | + end | ||
33 | + | ||
34 | + def to_set | ||
35 | + @expectations.to_set | ||
36 | + end | ||
37 | + | ||
38 | + def length | ||
39 | + @expectations.length | ||
40 | + end | ||
41 | + | ||
42 | + private | ||
43 | + | ||
44 | + def matching_expectations(method_name, *arguments) | ||
45 | + @expectations.select { |e| e.match?(method_name, *arguments) } | ||
46 | + end | ||
47 | + | ||
48 | + end | ||
49 | + | ||
50 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/in_state_ordering_constraint.rb
0 → 100644
@@ -0,0 +1,19 @@ | @@ -0,0 +1,19 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + class InStateOrderingConstraint | ||
4 | + | ||
5 | + def initialize(state_predicate) | ||
6 | + @state_predicate = state_predicate | ||
7 | + end | ||
8 | + | ||
9 | + def allows_invocation_now? | ||
10 | + @state_predicate.active? | ||
11 | + end | ||
12 | + | ||
13 | + def mocha_inspect | ||
14 | + "when #{@state_predicate.mocha_inspect}" | ||
15 | + end | ||
16 | + | ||
17 | + end | ||
18 | + | ||
19 | +end | ||
0 | \ No newline at end of file | 20 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/inspect.rb
0 → 100644
@@ -0,0 +1,67 @@ | @@ -0,0 +1,67 @@ | ||
1 | +require 'date' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ObjectMethods | ||
6 | + def mocha_inspect | ||
7 | + address = self.__id__ * 2 | ||
8 | + address += 0x100000000 if address < 0 | ||
9 | + inspect =~ /#</ ? "#<#{self.class}:0x#{'%x' % address}>" : inspect | ||
10 | + end | ||
11 | + end | ||
12 | + | ||
13 | + module StringMethods | ||
14 | + def mocha_inspect | ||
15 | + inspect.gsub(/\"/, "'") | ||
16 | + end | ||
17 | + end | ||
18 | + | ||
19 | + module ArrayMethods | ||
20 | + def mocha_inspect | ||
21 | + "[#{collect { |member| member.mocha_inspect }.join(', ')}]" | ||
22 | + end | ||
23 | + end | ||
24 | + | ||
25 | + module HashMethods | ||
26 | + def mocha_inspect | ||
27 | + "{#{collect { |key, value| "#{key.mocha_inspect} => #{value.mocha_inspect}" }.join(', ')}}" | ||
28 | + end | ||
29 | + end | ||
30 | + | ||
31 | + module TimeMethods | ||
32 | + def mocha_inspect | ||
33 | + "#{inspect} (#{to_f} secs)" | ||
34 | + end | ||
35 | + end | ||
36 | + | ||
37 | + module DateMethods | ||
38 | + def mocha_inspect | ||
39 | + to_s | ||
40 | + end | ||
41 | + end | ||
42 | + | ||
43 | +end | ||
44 | + | ||
45 | +class Object | ||
46 | + include Mocha::ObjectMethods | ||
47 | +end | ||
48 | + | ||
49 | +class String | ||
50 | + include Mocha::StringMethods | ||
51 | +end | ||
52 | + | ||
53 | +class Array | ||
54 | + include Mocha::ArrayMethods | ||
55 | +end | ||
56 | + | ||
57 | +class Hash | ||
58 | + include Mocha::HashMethods | ||
59 | +end | ||
60 | + | ||
61 | +class Time | ||
62 | + include Mocha::TimeMethods | ||
63 | +end | ||
64 | + | ||
65 | +class Date | ||
66 | + include Mocha::DateMethods | ||
67 | +end | ||
0 | \ No newline at end of file | 68 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/instance_method.rb
0 → 100644
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +require 'mocha/class_method' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + class InstanceMethod < ClassMethod | ||
6 | + | ||
7 | + def method_exists?(method) | ||
8 | + return true if stubbee.public_methods(false).include?(method) | ||
9 | + return true if stubbee.protected_methods(false).include?(method) | ||
10 | + return true if stubbee.private_methods(false).include?(method) | ||
11 | + return false | ||
12 | + end | ||
13 | + | ||
14 | + end | ||
15 | + | ||
16 | +end | ||
0 | \ No newline at end of file | 17 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon.rb
0 → 100644
@@ -0,0 +1 @@ | @@ -0,0 +1 @@ | ||
1 | +require 'mocha/integration/bacon/version_11_and_above.rb' |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon/assertion_counter.rb
0 → 100644
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + module Integration | ||
4 | + | ||
5 | + module Bacon | ||
6 | + | ||
7 | + class AssertionCounter | ||
8 | + | ||
9 | + def initialize(counter) | ||
10 | + @counter = counter | ||
11 | + end | ||
12 | + | ||
13 | + def increment | ||
14 | + @counter[:requirements] += 1 | ||
15 | + end | ||
16 | + | ||
17 | + end | ||
18 | + | ||
19 | + end | ||
20 | + | ||
21 | + end | ||
22 | + | ||
23 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/bacon/version_11_and_above.rb
0 → 100644
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +require 'mocha/integration/bacon/assertion_counter' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module Integration | ||
6 | + | ||
7 | + module Bacon | ||
8 | + | ||
9 | + module Version11AndAbove | ||
10 | + | ||
11 | + def self.included(base) | ||
12 | + | ||
13 | + base.class_eval do | ||
14 | + alias :it_before_bacon :it | ||
15 | + def it(description) | ||
16 | + it_before_bacon(description) do | ||
17 | + assertion_counter = ::Mocha::Integration::Bacon::AssertionCounter.new(::Bacon::Counter) | ||
18 | + mocha_setup | ||
19 | + yield | ||
20 | + mocha_verify(assertion_counter) | ||
21 | + mocha_teardown | ||
22 | + end | ||
23 | + end | ||
24 | + end | ||
25 | + | ||
26 | + end | ||
27 | + | ||
28 | + end | ||
29 | + | ||
30 | + end | ||
31 | + | ||
32 | + end | ||
33 | + | ||
34 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test.rb
0 → 100644
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test/assertion_counter.rb
0 → 100644
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + module Integration | ||
4 | + | ||
5 | + module MiniTest | ||
6 | + | ||
7 | + class AssertionCounter | ||
8 | + | ||
9 | + def initialize(test_case) | ||
10 | + @test_case = test_case | ||
11 | + end | ||
12 | + | ||
13 | + def increment | ||
14 | + @test_case._assertions += 1 | ||
15 | + end | ||
16 | + | ||
17 | + end | ||
18 | + | ||
19 | + end | ||
20 | + | ||
21 | + end | ||
22 | + | ||
23 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/mini_test/version_131_and_above.rb
0 → 100644
@@ -0,0 +1,49 @@ | @@ -0,0 +1,49 @@ | ||
1 | +require 'mocha/integration/mini_test/assertion_counter' | ||
2 | +require 'mocha/expectation_error' | ||
3 | + | ||
4 | +module Mocha | ||
5 | + | ||
6 | + module Integration | ||
7 | + | ||
8 | + module MiniTest | ||
9 | + | ||
10 | + def self.translate(exception) | ||
11 | + return exception unless exception.kind_of?(::Mocha::ExpectationError) | ||
12 | + translated_exception = ::MiniTest::Assertion.new(exception.message) | ||
13 | + translated_exception.set_backtrace(exception.backtrace) | ||
14 | + translated_exception | ||
15 | + end | ||
16 | + | ||
17 | + module Version131AndAbove | ||
18 | + def run runner | ||
19 | + assertion_counter = AssertionCounter.new(self) | ||
20 | + result = '.' | ||
21 | + begin | ||
22 | + begin | ||
23 | + @passed = nil | ||
24 | + self.setup | ||
25 | + self.__send__ self.name | ||
26 | + mocha_verify(assertion_counter) | ||
27 | + @passed = true | ||
28 | + rescue Exception => e | ||
29 | + @passed = false | ||
30 | + result = runner.puke(self.class, self.name, Mocha::Integration::MiniTest.translate(e)) | ||
31 | + ensure | ||
32 | + begin | ||
33 | + self.teardown | ||
34 | + rescue Exception => e | ||
35 | + result = runner.puke(self.class, self.name, Mocha::Integration::MiniTest.translate(e)) | ||
36 | + end | ||
37 | + end | ||
38 | + ensure | ||
39 | + mocha_teardown | ||
40 | + end | ||
41 | + result | ||
42 | + end | ||
43 | + end | ||
44 | + | ||
45 | + end | ||
46 | + | ||
47 | + end | ||
48 | + | ||
49 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit.rb
0 → 100644
@@ -0,0 +1,4 @@ | @@ -0,0 +1,4 @@ | ||
1 | +require 'mocha/integration/test_unit/gem_version_200' | ||
2 | +require 'mocha/integration/test_unit/gem_version_201_and_above' | ||
3 | +require 'mocha/integration/test_unit/ruby_version_185_and_below' | ||
4 | +require 'mocha/integration/test_unit/ruby_version_186_and_above' | ||
0 | \ No newline at end of file | 5 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/assertion_counter.rb
0 → 100644
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + module Integration | ||
4 | + | ||
5 | + module TestUnit | ||
6 | + | ||
7 | + class AssertionCounter | ||
8 | + | ||
9 | + def initialize(test_result) | ||
10 | + @test_result = test_result | ||
11 | + end | ||
12 | + | ||
13 | + def increment | ||
14 | + @test_result.add_assertion | ||
15 | + end | ||
16 | + | ||
17 | + end | ||
18 | + | ||
19 | + end | ||
20 | + | ||
21 | + end | ||
22 | + | ||
23 | +end | ||
0 | \ No newline at end of file | 24 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/gem_version_200.rb
0 → 100644
@@ -0,0 +1,49 @@ | @@ -0,0 +1,49 @@ | ||
1 | +require 'test/unit/testcase' | ||
2 | +require 'mocha/integration/test_unit/assertion_counter' | ||
3 | +require 'mocha/expectation_error' | ||
4 | + | ||
5 | +module Mocha | ||
6 | + | ||
7 | + module Integration | ||
8 | + | ||
9 | + module TestUnit | ||
10 | + | ||
11 | + module GemVersion200 | ||
12 | + def run(result) | ||
13 | + assertion_counter = AssertionCounter.new(result) | ||
14 | + begin | ||
15 | + @_result = result | ||
16 | + yield(Test::Unit::TestCase::STARTED, name) | ||
17 | + begin | ||
18 | + begin | ||
19 | + run_setup | ||
20 | + __send__(@method_name) | ||
21 | + mocha_verify(assertion_counter) | ||
22 | + rescue Mocha::ExpectationError => e | ||
23 | + add_failure(e.message, e.backtrace) | ||
24 | + rescue Exception | ||
25 | + @interrupted = true | ||
26 | + raise unless handle_exception($!) | ||
27 | + ensure | ||
28 | + begin | ||
29 | + run_teardown | ||
30 | + rescue Exception | ||
31 | + raise unless handle_exception($!) | ||
32 | + end | ||
33 | + end | ||
34 | + ensure | ||
35 | + mocha_teardown | ||
36 | + end | ||
37 | + result.add_run | ||
38 | + yield(Test::Unit::TestCase::FINISHED, name) | ||
39 | + ensure | ||
40 | + @_result = nil | ||
41 | + end | ||
42 | + end | ||
43 | + end | ||
44 | + | ||
45 | + end | ||
46 | + | ||
47 | + end | ||
48 | + | ||
49 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/gem_version_201_and_above.rb
0 → 100644
@@ -0,0 +1,49 @@ | @@ -0,0 +1,49 @@ | ||
1 | +require 'test/unit/testcase' | ||
2 | +require 'mocha/integration/test_unit/assertion_counter' | ||
3 | +require 'mocha/expectation_error' | ||
4 | + | ||
5 | +module Mocha | ||
6 | + | ||
7 | + module Integration | ||
8 | + | ||
9 | + module TestUnit | ||
10 | + | ||
11 | + module GemVersion201AndAbove | ||
12 | + def run(result) | ||
13 | + assertion_counter = AssertionCounter.new(result) | ||
14 | + begin | ||
15 | + @_result = result | ||
16 | + yield(Test::Unit::TestCase::STARTED, name) | ||
17 | + begin | ||
18 | + begin | ||
19 | + run_setup | ||
20 | + run_test | ||
21 | + mocha_verify(assertion_counter) | ||
22 | + rescue Mocha::ExpectationError => e | ||
23 | + add_failure(e.message, e.backtrace) | ||
24 | + rescue Exception | ||
25 | + @interrupted = true | ||
26 | + raise unless handle_exception($!) | ||
27 | + ensure | ||
28 | + begin | ||
29 | + run_teardown | ||
30 | + rescue Exception | ||
31 | + raise unless handle_exception($!) | ||
32 | + end | ||
33 | + end | ||
34 | + ensure | ||
35 | + mocha_teardown | ||
36 | + end | ||
37 | + result.add_run | ||
38 | + yield(Test::Unit::TestCase::FINISHED, name) | ||
39 | + ensure | ||
40 | + @_result = nil | ||
41 | + end | ||
42 | + end | ||
43 | + end | ||
44 | + | ||
45 | + end | ||
46 | + | ||
47 | + end | ||
48 | + | ||
49 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/ruby_version_185_and_below.rb
0 → 100644
@@ -0,0 +1,48 @@ | @@ -0,0 +1,48 @@ | ||
1 | +require 'test/unit/testcase' | ||
2 | +require 'mocha/integration/test_unit/assertion_counter' | ||
3 | +require 'mocha/expectation_error' | ||
4 | + | ||
5 | +module Mocha | ||
6 | + | ||
7 | + module Integration | ||
8 | + | ||
9 | + module TestUnit | ||
10 | + | ||
11 | + module RubyVersion185AndBelow | ||
12 | + def run(result) | ||
13 | + assertion_counter = AssertionCounter.new(result) | ||
14 | + yield(Test::Unit::TestCase::STARTED, name) | ||
15 | + @_result = result | ||
16 | + begin | ||
17 | + begin | ||
18 | + setup | ||
19 | + __send__(@method_name) | ||
20 | + mocha_verify(assertion_counter) | ||
21 | + rescue Mocha::ExpectationError => e | ||
22 | + add_failure(e.message, e.backtrace) | ||
23 | + rescue Test::Unit::AssertionFailedError => e | ||
24 | + add_failure(e.message, e.backtrace) | ||
25 | + rescue StandardError, ScriptError | ||
26 | + add_error($!) | ||
27 | + ensure | ||
28 | + begin | ||
29 | + teardown | ||
30 | + rescue Test::Unit::AssertionFailedError => e | ||
31 | + add_failure(e.message, e.backtrace) | ||
32 | + rescue StandardError, ScriptError | ||
33 | + add_error($!) | ||
34 | + end | ||
35 | + end | ||
36 | + ensure | ||
37 | + mocha_teardown | ||
38 | + end | ||
39 | + result.add_run | ||
40 | + yield(Test::Unit::TestCase::FINISHED, name) | ||
41 | + end | ||
42 | + end | ||
43 | + | ||
44 | + end | ||
45 | + | ||
46 | + end | ||
47 | + | ||
48 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/integration/test_unit/ruby_version_186_and_above.rb
0 → 100644
@@ -0,0 +1,50 @@ | @@ -0,0 +1,50 @@ | ||
1 | +require 'test/unit/testcase' | ||
2 | +require 'mocha/integration/test_unit/assertion_counter' | ||
3 | +require 'mocha/expectation_error' | ||
4 | + | ||
5 | +module Mocha | ||
6 | + | ||
7 | + module Integration | ||
8 | + | ||
9 | + module TestUnit | ||
10 | + | ||
11 | + module RubyVersion186AndAbove | ||
12 | + def run(result) | ||
13 | + assertion_counter = AssertionCounter.new(result) | ||
14 | + yield(Test::Unit::TestCase::STARTED, name) | ||
15 | + @_result = result | ||
16 | + begin | ||
17 | + begin | ||
18 | + setup | ||
19 | + __send__(@method_name) | ||
20 | + mocha_verify(assertion_counter) | ||
21 | + rescue Mocha::ExpectationError => e | ||
22 | + add_failure(e.message, e.backtrace) | ||
23 | + rescue Test::Unit::AssertionFailedError => e | ||
24 | + add_failure(e.message, e.backtrace) | ||
25 | + rescue Exception | ||
26 | + raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class | ||
27 | + add_error($!) | ||
28 | + ensure | ||
29 | + begin | ||
30 | + teardown | ||
31 | + rescue Test::Unit::AssertionFailedError => e | ||
32 | + add_failure(e.message, e.backtrace) | ||
33 | + rescue Exception | ||
34 | + raise if Test::Unit::TestCase::PASSTHROUGH_EXCEPTIONS.include? $!.class | ||
35 | + add_error($!) | ||
36 | + end | ||
37 | + end | ||
38 | + ensure | ||
39 | + mocha_teardown | ||
40 | + end | ||
41 | + result.add_run | ||
42 | + yield(Test::Unit::TestCase::FINISHED, name) | ||
43 | + end | ||
44 | + end | ||
45 | + | ||
46 | + end | ||
47 | + | ||
48 | + end | ||
49 | + | ||
50 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/invocation.rb
0 → 100644
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/is_a.rb
0 → 100644
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/logger.rb
0 → 100644
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/metaclass.rb
0 → 100644
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/method_matcher.rb
0 → 100644
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + class MethodMatcher | ||
4 | + | ||
5 | + attr_reader :expected_method_name | ||
6 | + | ||
7 | + def initialize(expected_method_name) | ||
8 | + @expected_method_name = expected_method_name | ||
9 | + end | ||
10 | + | ||
11 | + def match?(actual_method_name) | ||
12 | + @expected_method_name == actual_method_name | ||
13 | + end | ||
14 | + | ||
15 | + def mocha_inspect | ||
16 | + "#{@expected_method_name}" | ||
17 | + end | ||
18 | + | ||
19 | + end | ||
20 | + | ||
21 | +end | ||
0 | \ No newline at end of file | 22 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/mock.rb
0 → 100644
@@ -0,0 +1,200 @@ | @@ -0,0 +1,200 @@ | ||
1 | +require 'mocha/expectation' | ||
2 | +require 'mocha/expectation_list' | ||
3 | +require 'mocha/metaclass' | ||
4 | +require 'mocha/names' | ||
5 | +require 'mocha/mockery' | ||
6 | +require 'mocha/method_matcher' | ||
7 | +require 'mocha/parameters_matcher' | ||
8 | +require 'mocha/unexpected_invocation' | ||
9 | +require 'mocha/argument_iterator' | ||
10 | + | ||
11 | +module Mocha # :nodoc: | ||
12 | + | ||
13 | + # Traditional mock object. | ||
14 | + # | ||
15 | + # Methods return an Expectation which can be further modified by methods on Expectation. | ||
16 | + class Mock | ||
17 | + | ||
18 | + # :call-seq: expects(method_name) -> expectation | ||
19 | + # expects(method_names_vs_return_values) -> last expectation | ||
20 | + # | ||
21 | + # Adds an expectation that a method identified by +method_name+ Symbol/String must be called exactly once with any parameters. | ||
22 | + # Returns the new expectation which can be further modified by methods on Expectation. | ||
23 | + # object = mock() | ||
24 | + # object.expects(:method1) | ||
25 | + # object.method1 | ||
26 | + # # no error raised | ||
27 | + # | ||
28 | + # object = mock() | ||
29 | + # object.expects(:method1) | ||
30 | + # # error raised, because method1 not called exactly once | ||
31 | + # If +method_names_vs_return_values+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+. | ||
32 | + # object = mock() | ||
33 | + # object.expects(:method1 => :result1, :method2 => :result2) | ||
34 | + # | ||
35 | + # # exactly equivalent to | ||
36 | + # | ||
37 | + # object = mock() | ||
38 | + # object.expects(:method1).returns(:result1) | ||
39 | + # object.expects(:method2).returns(:result2) | ||
40 | + # | ||
41 | + # Aliased by <tt>\_\_expects\_\_</tt> | ||
42 | + def expects(method_name_or_hash, backtrace = nil) | ||
43 | + iterator = ArgumentIterator.new(method_name_or_hash) | ||
44 | + iterator.each { |*args| | ||
45 | + method_name = args.shift | ||
46 | + ensure_method_not_already_defined(method_name) | ||
47 | + expectation = Expectation.new(self, method_name, backtrace) | ||
48 | + expectation.returns(args.shift) if args.length > 0 | ||
49 | + @expectations.add(expectation) | ||
50 | + } | ||
51 | + end | ||
52 | + | ||
53 | + # :call-seq: stubs(method_name) -> expectation | ||
54 | + # stubs(method_names_vs_return_values) -> last expectation | ||
55 | + # | ||
56 | + # Adds an expectation that a method identified by +method_name+ Symbol/String may be called any number of times with any parameters. | ||
57 | + # Returns the new expectation which can be further modified by methods on Expectation. | ||
58 | + # object = mock() | ||
59 | + # object.stubs(:method1) | ||
60 | + # object.method1 | ||
61 | + # object.method1 | ||
62 | + # # no error raised | ||
63 | + # If +method_names_vs_return_values+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+. | ||
64 | + # object = mock() | ||
65 | + # object.stubs(:method1 => :result1, :method2 => :result2) | ||
66 | + # | ||
67 | + # # exactly equivalent to | ||
68 | + # | ||
69 | + # object = mock() | ||
70 | + # object.stubs(:method1).returns(:result1) | ||
71 | + # object.stubs(:method2).returns(:result2) | ||
72 | + # | ||
73 | + # Aliased by <tt>\_\_stubs\_\_</tt> | ||
74 | + def stubs(method_name_or_hash, backtrace = nil) | ||
75 | + iterator = ArgumentIterator.new(method_name_or_hash) | ||
76 | + iterator.each { |*args| | ||
77 | + method_name = args.shift | ||
78 | + ensure_method_not_already_defined(method_name) | ||
79 | + expectation = Expectation.new(self, method_name, backtrace) | ||
80 | + expectation.at_least(0) | ||
81 | + expectation.returns(args.shift) if args.length > 0 | ||
82 | + @expectations.add(expectation) | ||
83 | + } | ||
84 | + end | ||
85 | + | ||
86 | + # :call-seq: responds_like(responder) -> mock | ||
87 | + # | ||
88 | + # Constrains the +mock+ so that it can only expect or stub methods to which +responder+ responds. The constraint is only applied at method invocation time. | ||
89 | + # | ||
90 | + # A +NoMethodError+ will be raised if the +responder+ does not <tt>respond_to?</tt> a method invocation (even if the method has been expected or stubbed). | ||
91 | + # | ||
92 | + # The +mock+ will delegate its <tt>respond_to?</tt> method to the +responder+. | ||
93 | + # class Sheep | ||
94 | + # def chew(grass); end | ||
95 | + # def self.number_of_legs; end | ||
96 | + # end | ||
97 | + # | ||
98 | + # sheep = mock('sheep') | ||
99 | + # sheep.expects(:chew) | ||
100 | + # sheep.expects(:foo) | ||
101 | + # sheep.respond_to?(:chew) # => true | ||
102 | + # sheep.respond_to?(:foo) # => true | ||
103 | + # sheep.chew | ||
104 | + # sheep.foo | ||
105 | + # # no error raised | ||
106 | + # | ||
107 | + # sheep = mock('sheep') | ||
108 | + # sheep.responds_like(Sheep.new) | ||
109 | + # sheep.expects(:chew) | ||
110 | + # sheep.expects(:foo) | ||
111 | + # sheep.respond_to?(:chew) # => true | ||
112 | + # sheep.respond_to?(:foo) # => false | ||
113 | + # sheep.chew | ||
114 | + # sheep.foo # => raises NoMethodError exception | ||
115 | + # | ||
116 | + # sheep_class = mock('sheep_class') | ||
117 | + # sheep_class.responds_like(Sheep) | ||
118 | + # sheep_class.stubs(:number_of_legs).returns(4) | ||
119 | + # sheep_class.expects(:foo) | ||
120 | + # sheep_class.respond_to?(:number_of_legs) # => true | ||
121 | + # sheep_class.respond_to?(:foo) # => false | ||
122 | + # assert_equal 4, sheep_class.number_of_legs | ||
123 | + # sheep_class.foo # => raises NoMethodError exception | ||
124 | + # | ||
125 | + # Aliased by +quacks_like+ | ||
126 | + def responds_like(object) | ||
127 | + @responder = object | ||
128 | + self | ||
129 | + end | ||
130 | + | ||
131 | + # :stopdoc: | ||
132 | + | ||
133 | + def initialize(name = nil, &block) | ||
134 | + @name = name || DefaultName.new(self) | ||
135 | + @expectations = ExpectationList.new | ||
136 | + @everything_stubbed = false | ||
137 | + @responder = nil | ||
138 | + instance_eval(&block) if block | ||
139 | + end | ||
140 | + | ||
141 | + attr_reader :everything_stubbed, :expectations | ||
142 | + | ||
143 | + alias_method :__expects__, :expects | ||
144 | + | ||
145 | + alias_method :__stubs__, :stubs | ||
146 | + | ||
147 | + alias_method :quacks_like, :responds_like | ||
148 | + | ||
149 | + def stub_everything | ||
150 | + @everything_stubbed = true | ||
151 | + end | ||
152 | + | ||
153 | + def method_missing(symbol, *arguments, &block) | ||
154 | + if @responder and not @responder.respond_to?(symbol) | ||
155 | + raise NoMethodError, "undefined method `#{symbol}' for #{self.mocha_inspect} which responds like #{@responder.mocha_inspect}" | ||
156 | + end | ||
157 | + if matching_expectation_allowing_invocation = @expectations.match_allowing_invocation(symbol, *arguments) | ||
158 | + matching_expectation_allowing_invocation.invoke(arguments, &block) | ||
159 | + else | ||
160 | + if (matching_expectation = @expectations.match(symbol, *arguments)) || (!matching_expectation && !@everything_stubbed) | ||
161 | + message = UnexpectedInvocation.new(self, symbol, *arguments).to_s | ||
162 | + message << Mockery.instance.mocha_inspect | ||
163 | + raise ExpectationError.new(message, caller) | ||
164 | + end | ||
165 | + end | ||
166 | + end | ||
167 | + | ||
168 | + def respond_to?(symbol, include_private = false) | ||
169 | + if @responder then | ||
170 | + if @responder.method(:respond_to?).arity > 1 | ||
171 | + @responder.respond_to?(symbol, include_private) | ||
172 | + else | ||
173 | + @responder.respond_to?(symbol) | ||
174 | + end | ||
175 | + else | ||
176 | + @everything_stubbed || @expectations.matches_method?(symbol) | ||
177 | + end | ||
178 | + end | ||
179 | + | ||
180 | + def __verified__?(assertion_counter = nil) | ||
181 | + @expectations.verified?(assertion_counter) | ||
182 | + end | ||
183 | + | ||
184 | + def mocha_inspect | ||
185 | + @name.mocha_inspect | ||
186 | + end | ||
187 | + | ||
188 | + def inspect | ||
189 | + mocha_inspect | ||
190 | + end | ||
191 | + | ||
192 | + def ensure_method_not_already_defined(method_name) | ||
193 | + self.__metaclass__.send(:undef_method, method_name) if self.__metaclass__.method_defined?(method_name) | ||
194 | + end | ||
195 | + | ||
196 | + # :startdoc: | ||
197 | + | ||
198 | + end | ||
199 | + | ||
200 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/mockery.rb
0 → 100644
@@ -0,0 +1,189 @@ | @@ -0,0 +1,189 @@ | ||
1 | +require 'mocha/central' | ||
2 | +require 'mocha/mock' | ||
3 | +require 'mocha/names' | ||
4 | +require 'mocha/state_machine' | ||
5 | +require 'mocha/logger' | ||
6 | +require 'mocha/configuration' | ||
7 | +require 'mocha/stubbing_error' | ||
8 | +require 'mocha/invocation' | ||
9 | + | ||
10 | +module Mocha | ||
11 | + | ||
12 | + class Mockery | ||
13 | + | ||
14 | + class << self | ||
15 | + | ||
16 | + def instance | ||
17 | + @instance ||= new | ||
18 | + end | ||
19 | + | ||
20 | + def reset_instance | ||
21 | + @instance = nil | ||
22 | + end | ||
23 | + | ||
24 | + end | ||
25 | + | ||
26 | + def named_mock(name, &block) | ||
27 | + add_mock(Mock.new(Name.new(name), &block)) | ||
28 | + end | ||
29 | + | ||
30 | + def unnamed_mock(&block) | ||
31 | + add_mock(Mock.new(&block)) | ||
32 | + end | ||
33 | + | ||
34 | + def mock_impersonating(object, &block) | ||
35 | + add_mock(Mock.new(ImpersonatingName.new(object), &block)) | ||
36 | + end | ||
37 | + | ||
38 | + def mock_impersonating_any_instance_of(klass, &block) | ||
39 | + add_mock(Mock.new(ImpersonatingAnyInstanceName.new(klass), &block)) | ||
40 | + end | ||
41 | + | ||
42 | + def new_state_machine(name) | ||
43 | + add_state_machine(StateMachine.new(name)) | ||
44 | + end | ||
45 | + | ||
46 | + def invocation(mock, method_name, args) | ||
47 | + invocations << Invocation.new(mock, method_name, args) | ||
48 | + end | ||
49 | + | ||
50 | + def verify(assertion_counter = nil) | ||
51 | + unless mocks.all? { |mock| mock.__verified__?(assertion_counter) } | ||
52 | + message = "not all expectations were satisfied\n#{mocha_inspect}" | ||
53 | + if unsatisfied_expectations.empty? | ||
54 | + backtrace = caller | ||
55 | + else | ||
56 | + backtrace = unsatisfied_expectations[0].backtrace | ||
57 | + end | ||
58 | + raise ExpectationError.new(message, backtrace) | ||
59 | + end | ||
60 | + expectations.each do |e| | ||
61 | + unless Mocha::Configuration.allow?(:stubbing_method_unnecessarily) | ||
62 | + unless e.used? | ||
63 | + on_stubbing_method_unnecessarily(e) | ||
64 | + end | ||
65 | + end | ||
66 | + end | ||
67 | + end | ||
68 | + | ||
69 | + def teardown | ||
70 | + stubba.unstub_all | ||
71 | + reset | ||
72 | + end | ||
73 | + | ||
74 | + def stubba | ||
75 | + @stubba ||= Central.new | ||
76 | + end | ||
77 | + | ||
78 | + def mocks | ||
79 | + @mocks ||= [] | ||
80 | + end | ||
81 | + | ||
82 | + def state_machines | ||
83 | + @state_machines ||= [] | ||
84 | + end | ||
85 | + | ||
86 | + def mocha_inspect | ||
87 | + message = "" | ||
88 | + message << "unsatisfied expectations:\n- #{unsatisfied_expectations.map { |e| e.mocha_inspect }.join("\n- ")}\n" unless unsatisfied_expectations.empty? | ||
89 | + message << "satisfied expectations:\n- #{satisfied_expectations.map { |e| e.mocha_inspect }.join("\n- ")}\n" unless satisfied_expectations.empty? | ||
90 | + message << "states:\n- #{state_machines.map { |sm| sm.mocha_inspect }.join("\n- ")}" unless state_machines.empty? | ||
91 | + message | ||
92 | + end | ||
93 | + | ||
94 | + def on_stubbing(object, method) | ||
95 | + method = RUBY_VERSION < '1.9' ? method.to_s : method.to_sym | ||
96 | + unless Mocha::Configuration.allow?(:stubbing_non_existent_method) | ||
97 | + unless object.method_exists?(method, include_public_methods = true) | ||
98 | + on_stubbing_non_existent_method(object, method) | ||
99 | + end | ||
100 | + end | ||
101 | + unless Mocha::Configuration.allow?(:stubbing_non_public_method) | ||
102 | + if object.method_exists?(method, include_public_methods = false) | ||
103 | + on_stubbing_non_public_method(object, method) | ||
104 | + end | ||
105 | + end | ||
106 | + unless Mocha::Configuration.allow?(:stubbing_method_on_non_mock_object) | ||
107 | + on_stubbing_method_on_non_mock_object(object, method) | ||
108 | + end | ||
109 | + end | ||
110 | + | ||
111 | + def on_stubbing_non_existent_method(object, method) | ||
112 | + if Mocha::Configuration.prevent?(:stubbing_non_existent_method) | ||
113 | + raise StubbingError.new("stubbing non-existent method: #{object.mocha_inspect}.#{method}", caller) | ||
114 | + end | ||
115 | + if Mocha::Configuration.warn_when?(:stubbing_non_existent_method) | ||
116 | + logger.warn "stubbing non-existent method: #{object.mocha_inspect}.#{method}" | ||
117 | + end | ||
118 | + end | ||
119 | + | ||
120 | + def on_stubbing_non_public_method(object, method) | ||
121 | + if Mocha::Configuration.prevent?(:stubbing_non_public_method) | ||
122 | + raise StubbingError.new("stubbing non-public method: #{object.mocha_inspect}.#{method}", caller) | ||
123 | + end | ||
124 | + if Mocha::Configuration.warn_when?(:stubbing_non_public_method) | ||
125 | + logger.warn "stubbing non-public method: #{object.mocha_inspect}.#{method}" | ||
126 | + end | ||
127 | + end | ||
128 | + | ||
129 | + def on_stubbing_method_on_non_mock_object(object, method) | ||
130 | + if Mocha::Configuration.prevent?(:stubbing_method_on_non_mock_object) | ||
131 | + raise StubbingError.new("stubbing method on non-mock object: #{object.mocha_inspect}.#{method}", caller) | ||
132 | + end | ||
133 | + if Mocha::Configuration.warn_when?(:stubbing_method_on_non_mock_object) | ||
134 | + logger.warn "stubbing method on non-mock object: #{object.mocha_inspect}.#{method}" | ||
135 | + end | ||
136 | + end | ||
137 | + | ||
138 | + def on_stubbing_method_unnecessarily(expectation) | ||
139 | + if Mocha::Configuration.prevent?(:stubbing_method_unnecessarily) | ||
140 | + raise StubbingError.new("stubbing method unnecessarily: #{expectation.method_signature}", expectation.backtrace) | ||
141 | + end | ||
142 | + if Mocha::Configuration.warn_when?(:stubbing_method_unnecessarily) | ||
143 | + logger.warn "stubbing method unnecessarily: #{expectation.method_signature}" | ||
144 | + end | ||
145 | + end | ||
146 | + | ||
147 | + attr_writer :logger | ||
148 | + | ||
149 | + def logger | ||
150 | + @logger ||= Logger.new($stderr) | ||
151 | + end | ||
152 | + | ||
153 | + def invocations | ||
154 | + @invocations ||= [] | ||
155 | + end | ||
156 | + | ||
157 | + private | ||
158 | + | ||
159 | + def expectations | ||
160 | + mocks.map { |mock| mock.expectations.to_a }.flatten | ||
161 | + end | ||
162 | + | ||
163 | + def unsatisfied_expectations | ||
164 | + expectations.reject { |e| e.verified? } | ||
165 | + end | ||
166 | + | ||
167 | + def satisfied_expectations | ||
168 | + expectations.select { |e| e.verified? } | ||
169 | + end | ||
170 | + | ||
171 | + def add_mock(mock) | ||
172 | + mocks << mock | ||
173 | + mock | ||
174 | + end | ||
175 | + | ||
176 | + def add_state_machine(state_machine) | ||
177 | + state_machines << state_machine | ||
178 | + state_machine | ||
179 | + end | ||
180 | + | ||
181 | + def reset | ||
182 | + @stubba = nil | ||
183 | + @mocks = nil | ||
184 | + @state_machines = nil | ||
185 | + end | ||
186 | + | ||
187 | + end | ||
188 | + | ||
189 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/module_method.rb
0 → 100644
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +require 'mocha/module_method' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + class ModuleMethod < ClassMethod | ||
6 | + | ||
7 | + def method_exists?(method) | ||
8 | + return true if stubbee.public_methods(false).include?(method) | ||
9 | + return true if stubbee.protected_methods(false).include?(method) | ||
10 | + return true if stubbee.private_methods(false).include?(method) | ||
11 | + return false | ||
12 | + end | ||
13 | + | ||
14 | + end | ||
15 | + | ||
16 | +end | ||
0 | \ No newline at end of file | 17 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/multiple_yields.rb
0 → 100644
@@ -0,0 +1,20 @@ | @@ -0,0 +1,20 @@ | ||
1 | +module Mocha # :nodoc: | ||
2 | + | ||
3 | + class MultipleYields # :nodoc: | ||
4 | + | ||
5 | + attr_reader :parameter_groups | ||
6 | + | ||
7 | + def initialize(*parameter_groups) | ||
8 | + @parameter_groups = parameter_groups | ||
9 | + end | ||
10 | + | ||
11 | + def each | ||
12 | + @parameter_groups.each do |parameter_group| | ||
13 | + yield(parameter_group) | ||
14 | + end | ||
15 | + end | ||
16 | + | ||
17 | + end | ||
18 | + | ||
19 | +end | ||
20 | + |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/names.rb
0 → 100644
@@ -0,0 +1,53 @@ | @@ -0,0 +1,53 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + class ImpersonatingName | ||
4 | + | ||
5 | + def initialize(object) | ||
6 | + @object = object | ||
7 | + end | ||
8 | + | ||
9 | + def mocha_inspect | ||
10 | + @object.mocha_inspect | ||
11 | + end | ||
12 | + | ||
13 | + end | ||
14 | + | ||
15 | + class ImpersonatingAnyInstanceName | ||
16 | + | ||
17 | + def initialize(klass) | ||
18 | + @klass = klass | ||
19 | + end | ||
20 | + | ||
21 | + def mocha_inspect | ||
22 | + "#<AnyInstance:#{@klass.mocha_inspect}>" | ||
23 | + end | ||
24 | + | ||
25 | + end | ||
26 | + | ||
27 | + class Name | ||
28 | + | ||
29 | + def initialize(name) | ||
30 | + @name = name | ||
31 | + end | ||
32 | + | ||
33 | + def mocha_inspect | ||
34 | + "#<Mock:#{@name}>" | ||
35 | + end | ||
36 | + | ||
37 | + end | ||
38 | + | ||
39 | + class DefaultName | ||
40 | + | ||
41 | + def initialize(mock) | ||
42 | + @mock = mock | ||
43 | + end | ||
44 | + | ||
45 | + def mocha_inspect | ||
46 | + address = @mock.__id__ * 2 | ||
47 | + address += 0x100000000 if address < 0 | ||
48 | + "#<Mock:0x#{'%x' % address}>" | ||
49 | + end | ||
50 | + | ||
51 | + end | ||
52 | + | ||
53 | +end | ||
0 | \ No newline at end of file | 54 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/no_yields.rb
0 → 100644
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/object.rb
0 → 100644
@@ -0,0 +1,187 @@ | @@ -0,0 +1,187 @@ | ||
1 | +require 'mocha/mockery' | ||
2 | +require 'mocha/instance_method' | ||
3 | +require 'mocha/class_method' | ||
4 | +require 'mocha/module_method' | ||
5 | +require 'mocha/any_instance_method' | ||
6 | +require 'mocha/argument_iterator' | ||
7 | + | ||
8 | +module Mocha | ||
9 | + | ||
10 | + # Methods added all objects to allow mocking and stubbing on real objects. | ||
11 | + # | ||
12 | + # Methods return a Mocha::Expectation which can be further modified by methods on Mocha::Expectation. | ||
13 | + module ObjectMethods | ||
14 | + | ||
15 | + def mocha # :nodoc: | ||
16 | + @mocha ||= Mocha::Mockery.instance.mock_impersonating(self) | ||
17 | + end | ||
18 | + | ||
19 | + def reset_mocha # :nodoc: | ||
20 | + @mocha = nil | ||
21 | + end | ||
22 | + | ||
23 | + def stubba_method # :nodoc: | ||
24 | + Mocha::InstanceMethod | ||
25 | + end | ||
26 | + | ||
27 | + def stubba_object # :nodoc: | ||
28 | + self | ||
29 | + end | ||
30 | + | ||
31 | + # :call-seq: expects(method_name) -> expectation | ||
32 | + # expects(method_names_vs_return_values) -> last expectation | ||
33 | + # | ||
34 | + # Adds an expectation that a method identified by +method_name+ Symbol must be called exactly once with any parameters. | ||
35 | + # Returns the new expectation which can be further modified by methods on Mocha::Expectation. | ||
36 | + # product = Product.new | ||
37 | + # product.expects(:save).returns(true) | ||
38 | + # assert_equal true, product.save | ||
39 | + # | ||
40 | + # The original implementation of <tt>Product#save</tt> is replaced temporarily. | ||
41 | + # | ||
42 | + # The original implementation of <tt>Product#save</tt> is restored at the end of the test. | ||
43 | + # | ||
44 | + # If +method_names_vs_return_values+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+. | ||
45 | + # product = Product.new | ||
46 | + # product.expects(:valid? => true, :save => true) | ||
47 | + # | ||
48 | + # # exactly equivalent to | ||
49 | + # | ||
50 | + # product = Product.new | ||
51 | + # product.expects(:valid?).returns(true) | ||
52 | + # product.expects(:save).returns(true) | ||
53 | + def expects(method_name_or_hash) | ||
54 | + expectation = nil | ||
55 | + mockery = Mocha::Mockery.instance | ||
56 | + iterator = ArgumentIterator.new(method_name_or_hash) | ||
57 | + iterator.each { |*args| | ||
58 | + method_name = args.shift | ||
59 | + mockery.on_stubbing(self, method_name) | ||
60 | + method = stubba_method.new(stubba_object, method_name) | ||
61 | + mockery.stubba.stub(method) | ||
62 | + expectation = mocha.expects(method_name, caller) | ||
63 | + expectation.returns(args.shift) if args.length > 0 | ||
64 | + } | ||
65 | + expectation | ||
66 | + end | ||
67 | + | ||
68 | + # :call-seq: stubs(method_name) -> expectation | ||
69 | + # stubs(method_names_vs_return_values) -> last expectation | ||
70 | + # | ||
71 | + # Adds an expectation that a method identified by +method_name+ Symbol may be called any number of times with any parameters. | ||
72 | + # Returns the new expectation which can be further modified by methods on Mocha::Expectation. | ||
73 | + # product = Product.new | ||
74 | + # product.stubs(:save).returns(true) | ||
75 | + # assert_equal true, product.save | ||
76 | + # | ||
77 | + # The original implementation of <tt>Product#save</tt> is replaced temporarily. | ||
78 | + # | ||
79 | + # The original implementation of <tt>Product#save</tt> is restored at the end of the test. | ||
80 | + # | ||
81 | + # If +method_names_vs_return_values+ is a +Hash+, an expectation will be set up for each entry using the key as +method_name+ and value as +return_value+. | ||
82 | + # product = Product.new | ||
83 | + # product.stubs(:valid? => true, :save => true) | ||
84 | + # | ||
85 | + # # exactly equivalent to | ||
86 | + # | ||
87 | + # product = Product.new | ||
88 | + # product.stubs(:valid?).returns(true) | ||
89 | + # product.stubs(:save).returns(true) | ||
90 | + def stubs(method_name_or_hash) | ||
91 | + expectation = nil | ||
92 | + mockery = Mocha::Mockery.instance | ||
93 | + iterator = ArgumentIterator.new(method_name_or_hash) | ||
94 | + iterator.each { |*args| | ||
95 | + method_name = args.shift | ||
96 | + mockery.on_stubbing(self, method_name) | ||
97 | + method = stubba_method.new(stubba_object, method_name) | ||
98 | + mockery.stubba.stub(method) | ||
99 | + expectation = mocha.stubs(method_name, caller) | ||
100 | + expectation.returns(args.shift) if args.length > 0 | ||
101 | + } | ||
102 | + expectation | ||
103 | + end | ||
104 | + | ||
105 | + def method_exists?(method, include_public_methods = true) # :nodoc: | ||
106 | + if include_public_methods | ||
107 | + return true if public_methods(include_superclass_methods = true).include?(method) | ||
108 | + return true if respond_to?(method.to_sym) | ||
109 | + end | ||
110 | + return true if protected_methods(include_superclass_methods = true).include?(method) | ||
111 | + return true if private_methods(include_superclass_methods = true).include?(method) | ||
112 | + return false | ||
113 | + end | ||
114 | + | ||
115 | + end | ||
116 | + | ||
117 | + module ModuleMethods # :nodoc: | ||
118 | + | ||
119 | + def stubba_method | ||
120 | + Mocha::ModuleMethod | ||
121 | + end | ||
122 | + | ||
123 | + end | ||
124 | + | ||
125 | + # Methods added all classes to allow mocking and stubbing on real objects. | ||
126 | + module ClassMethods | ||
127 | + | ||
128 | + def stubba_method # :nodoc: | ||
129 | + Mocha::ClassMethod | ||
130 | + end | ||
131 | + | ||
132 | + class AnyInstance # :nodoc: | ||
133 | + | ||
134 | + def initialize(klass) | ||
135 | + @stubba_object = klass | ||
136 | + end | ||
137 | + | ||
138 | + def mocha | ||
139 | + @mocha ||= Mocha::Mockery.instance.mock_impersonating_any_instance_of(@stubba_object) | ||
140 | + end | ||
141 | + | ||
142 | + def stubba_method | ||
143 | + Mocha::AnyInstanceMethod | ||
144 | + end | ||
145 | + | ||
146 | + def stubba_object | ||
147 | + @stubba_object | ||
148 | + end | ||
149 | + | ||
150 | + def method_exists?(method, include_public_methods = true) | ||
151 | + if include_public_methods | ||
152 | + return true if @stubba_object.public_instance_methods(include_superclass_methods = true).include?(method) | ||
153 | + end | ||
154 | + return true if @stubba_object.protected_instance_methods(include_superclass_methods = true).include?(method) | ||
155 | + return true if @stubba_object.private_instance_methods(include_superclass_methods = true).include?(method) | ||
156 | + return false | ||
157 | + end | ||
158 | + | ||
159 | + end | ||
160 | + | ||
161 | + # :call-seq: any_instance -> mock object | ||
162 | + # | ||
163 | + # Returns a mock object which will detect calls to any instance of this class. | ||
164 | + # Product.any_instance.stubs(:save).returns(false) | ||
165 | + # product_1 = Product.new | ||
166 | + # assert_equal false, product_1.save | ||
167 | + # product_2 = Product.new | ||
168 | + # assert_equal false, product_2.save | ||
169 | + def any_instance | ||
170 | + @any_instance ||= AnyInstance.new(self) | ||
171 | + end | ||
172 | + | ||
173 | + end | ||
174 | + | ||
175 | +end | ||
176 | + | ||
177 | +class Object # :nodoc: | ||
178 | + include Mocha::ObjectMethods | ||
179 | +end | ||
180 | + | ||
181 | +class Module # :nodoc: | ||
182 | + include Mocha::ModuleMethods | ||
183 | +end | ||
184 | + | ||
185 | +class Class # :nodoc: | ||
186 | + include Mocha::ClassMethods | ||
187 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers.rb
0 → 100644
@@ -0,0 +1,27 @@ | @@ -0,0 +1,27 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + # Used as parameters for Expectation#with to restrict the parameter values which will match the expectation. Can be nested. | ||
4 | + module ParameterMatchers; end | ||
5 | + | ||
6 | +end | ||
7 | + | ||
8 | +require 'mocha/parameter_matchers/object' | ||
9 | + | ||
10 | +require 'mocha/parameter_matchers/all_of' | ||
11 | +require 'mocha/parameter_matchers/any_of' | ||
12 | +require 'mocha/parameter_matchers/any_parameters' | ||
13 | +require 'mocha/parameter_matchers/anything' | ||
14 | +require 'mocha/parameter_matchers/equals' | ||
15 | +require 'mocha/parameter_matchers/has_entry' | ||
16 | +require 'mocha/parameter_matchers/has_entries' | ||
17 | +require 'mocha/parameter_matchers/has_key' | ||
18 | +require 'mocha/parameter_matchers/has_value' | ||
19 | +require 'mocha/parameter_matchers/includes' | ||
20 | +require 'mocha/parameter_matchers/instance_of' | ||
21 | +require 'mocha/parameter_matchers/is_a' | ||
22 | +require 'mocha/parameter_matchers/kind_of' | ||
23 | +require 'mocha/parameter_matchers/not' | ||
24 | +require 'mocha/parameter_matchers/optionally' | ||
25 | +require 'mocha/parameter_matchers/regexp_matches' | ||
26 | +require 'mocha/parameter_matchers/responds_with' | ||
27 | +require 'mocha/parameter_matchers/yaml_equivalent' |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/all_of.rb
0 → 100644
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: all_of(*parameter_matchers) -> parameter_matcher | ||
8 | + # | ||
9 | + # Matches if all +parameter_matchers+ match. | ||
10 | + # object = mock() | ||
11 | + # object.expects(:method_1).with(all_of(includes(1), includes(3))) | ||
12 | + # object.method_1([1, 3]) | ||
13 | + # # no error raised | ||
14 | + # | ||
15 | + # object = mock() | ||
16 | + # object.expects(:method_1).with(all_of(includes(1), includes(3))) | ||
17 | + # object.method_1([1, 2]) | ||
18 | + # # error raised, because method_1 was not called with object including 1 and 3 | ||
19 | + def all_of(*matchers) | ||
20 | + AllOf.new(*matchers) | ||
21 | + end | ||
22 | + | ||
23 | + class AllOf < Base # :nodoc: | ||
24 | + | ||
25 | + def initialize(*matchers) | ||
26 | + @matchers = matchers | ||
27 | + end | ||
28 | + | ||
29 | + def matches?(available_parameters) | ||
30 | + parameter = available_parameters.shift | ||
31 | + @matchers.all? { |matcher| matcher.to_matcher.matches?([parameter]) } | ||
32 | + end | ||
33 | + | ||
34 | + def mocha_inspect | ||
35 | + "all_of(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })" | ||
36 | + end | ||
37 | + | ||
38 | + end | ||
39 | + | ||
40 | + end | ||
41 | + | ||
42 | +end | ||
0 | \ No newline at end of file | 43 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/any_of.rb
0 → 100644
@@ -0,0 +1,47 @@ | @@ -0,0 +1,47 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: any_of(*parameter_matchers) -> parameter_matcher | ||
8 | + # | ||
9 | + # Matches if any +parameter_matchers+ match. | ||
10 | + # object = mock() | ||
11 | + # object.expects(:method_1).with(any_of(1, 3)) | ||
12 | + # object.method_1(1) | ||
13 | + # # no error raised | ||
14 | + # | ||
15 | + # object = mock() | ||
16 | + # object.expects(:method_1).with(any_of(1, 3)) | ||
17 | + # object.method_1(3) | ||
18 | + # # no error raised | ||
19 | + # | ||
20 | + # object = mock() | ||
21 | + # object.expects(:method_1).with(any_of(1, 3)) | ||
22 | + # object.method_1(2) | ||
23 | + # # error raised, because method_1 was not called with 1 or 3 | ||
24 | + def any_of(*matchers) | ||
25 | + AnyOf.new(*matchers) | ||
26 | + end | ||
27 | + | ||
28 | + class AnyOf < Base # :nodoc: | ||
29 | + | ||
30 | + def initialize(*matchers) | ||
31 | + @matchers = matchers | ||
32 | + end | ||
33 | + | ||
34 | + def matches?(available_parameters) | ||
35 | + parameter = available_parameters.shift | ||
36 | + @matchers.any? { |matcher| matcher.to_matcher.matches?([parameter]) } | ||
37 | + end | ||
38 | + | ||
39 | + def mocha_inspect | ||
40 | + "any_of(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })" | ||
41 | + end | ||
42 | + | ||
43 | + end | ||
44 | + | ||
45 | + end | ||
46 | + | ||
47 | +end | ||
0 | \ No newline at end of file | 48 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/any_parameters.rb
0 → 100644
@@ -0,0 +1,40 @@ | @@ -0,0 +1,40 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: any_parameters() -> parameter_matcher | ||
8 | + # | ||
9 | + # Matches any parameters. | ||
10 | + # object = mock() | ||
11 | + # object.expects(:method_1).with(any_parameters) | ||
12 | + # object.method_1(1, 2, 3, 4) | ||
13 | + # # no error raised | ||
14 | + # | ||
15 | + # object = mock() | ||
16 | + # object.expects(:method_1).with(any_parameters) | ||
17 | + # object.method_1(5, 6, 7, 8, 9, 0) | ||
18 | + # # no error raised | ||
19 | + def any_parameters | ||
20 | + AnyParameters.new | ||
21 | + end | ||
22 | + | ||
23 | + class AnyParameters < Base # :nodoc: | ||
24 | + | ||
25 | + def matches?(available_parameters) | ||
26 | + while available_parameters.length > 0 do | ||
27 | + available_parameters.shift | ||
28 | + end | ||
29 | + return true | ||
30 | + end | ||
31 | + | ||
32 | + def mocha_inspect | ||
33 | + "any_parameters" | ||
34 | + end | ||
35 | + | ||
36 | + end | ||
37 | + | ||
38 | + end | ||
39 | + | ||
40 | +end | ||
0 | \ No newline at end of file | 41 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/anything.rb
0 → 100644
@@ -0,0 +1,33 @@ | @@ -0,0 +1,33 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: anything() -> parameter_matcher | ||
8 | + # | ||
9 | + # Matches any object. | ||
10 | + # object = mock() | ||
11 | + # object.expects(:method_1).with(anything) | ||
12 | + # object.method_1('foo') | ||
13 | + # # no error raised | ||
14 | + def anything | ||
15 | + Anything.new | ||
16 | + end | ||
17 | + | ||
18 | + class Anything < Base # :nodoc: | ||
19 | + | ||
20 | + def matches?(available_parameters) | ||
21 | + available_parameters.shift | ||
22 | + return true | ||
23 | + end | ||
24 | + | ||
25 | + def mocha_inspect | ||
26 | + "anything" | ||
27 | + end | ||
28 | + | ||
29 | + end | ||
30 | + | ||
31 | + end | ||
32 | + | ||
33 | +end | ||
0 | \ No newline at end of file | 34 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/base.rb
0 → 100644
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/equals.rb
0 → 100644
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: equals(value) -> parameter_matcher | ||
8 | + # | ||
9 | + # Matches +Object+ equalling +value+. | ||
10 | + # object = mock() | ||
11 | + # object.expects(:method_1).with(equals(2)) | ||
12 | + # object.method_1(2) | ||
13 | + # # no error raised | ||
14 | + # | ||
15 | + # object = mock() | ||
16 | + # object.expects(:method_1).with(equals(2)) | ||
17 | + # object.method_1(3) | ||
18 | + # # error raised, because method_1 was not called with Object equalling 3 | ||
19 | + def equals(value) | ||
20 | + Equals.new(value) | ||
21 | + end | ||
22 | + | ||
23 | + class Equals < Base # :nodoc: | ||
24 | + | ||
25 | + def initialize(value) | ||
26 | + @value = value | ||
27 | + end | ||
28 | + | ||
29 | + def matches?(available_parameters) | ||
30 | + parameter = available_parameters.shift | ||
31 | + parameter == @value | ||
32 | + end | ||
33 | + | ||
34 | + def mocha_inspect | ||
35 | + @value.mocha_inspect | ||
36 | + end | ||
37 | + | ||
38 | + end | ||
39 | + | ||
40 | + end | ||
41 | + | ||
42 | +end | ||
0 | \ No newline at end of file | 43 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_entries.rb
0 → 100644
@@ -0,0 +1,45 @@ | @@ -0,0 +1,45 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | +require 'mocha/parameter_matchers/all_of' | ||
3 | +require 'mocha/parameter_matchers/has_entry' | ||
4 | + | ||
5 | +module Mocha | ||
6 | + | ||
7 | + module ParameterMatchers | ||
8 | + | ||
9 | + # :call-seq: has_entries(entries) -> parameter_matcher | ||
10 | + # | ||
11 | + # Matches +Hash+ containing all +entries+. | ||
12 | + # object = mock() | ||
13 | + # object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2)) | ||
14 | + # object.method_1('key_1' => 1, 'key_2' => 2, 'key_3' => 3) | ||
15 | + # # no error raised | ||
16 | + # | ||
17 | + # object = mock() | ||
18 | + # object.expects(:method_1).with(has_entries('key_1' => 1, 'key_2' => 2)) | ||
19 | + # object.method_1('key_1' => 1, 'key_2' => 99) | ||
20 | + # # error raised, because method_1 was not called with Hash containing entries: 'key_1' => 1, 'key_2' => 2 | ||
21 | + def has_entries(entries) | ||
22 | + HasEntries.new(entries) | ||
23 | + end | ||
24 | + | ||
25 | + class HasEntries < Base # :nodoc: | ||
26 | + | ||
27 | + def initialize(entries) | ||
28 | + @entries = entries | ||
29 | + end | ||
30 | + | ||
31 | + def matches?(available_parameters) | ||
32 | + parameter = available_parameters.shift | ||
33 | + has_entry_matchers = @entries.map { |key, value| HasEntry.new(key, value) } | ||
34 | + AllOf.new(*has_entry_matchers).matches?([parameter]) | ||
35 | + end | ||
36 | + | ||
37 | + def mocha_inspect | ||
38 | + "has_entries(#{@entries.mocha_inspect})" | ||
39 | + end | ||
40 | + | ||
41 | + end | ||
42 | + | ||
43 | + end | ||
44 | + | ||
45 | +end | ||
0 | \ No newline at end of file | 46 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_entry.rb
0 → 100644
@@ -0,0 +1,57 @@ | @@ -0,0 +1,57 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: has_entry(key, value) -> parameter_matcher | ||
8 | + # has_entry(key => value) -> parameter_matcher | ||
9 | + # | ||
10 | + # Matches +Hash+ containing entry with +key+ and +value+. | ||
11 | + # object = mock() | ||
12 | + # object.expects(:method_1).with(has_entry('key_1', 1)) | ||
13 | + # object.method_1('key_1' => 1, 'key_2' => 2) | ||
14 | + # # no error raised | ||
15 | + # | ||
16 | + # object = mock() | ||
17 | + # object.expects(:method_1).with(has_entry('key_1' => 1)) | ||
18 | + # object.method_1('key_1' => 1, 'key_2' => 2) | ||
19 | + # # no error raised | ||
20 | + # | ||
21 | + # object = mock() | ||
22 | + # object.expects(:method_1).with(has_entry('key_1', 1)) | ||
23 | + # object.method_1('key_1' => 2, 'key_2' => 1) | ||
24 | + # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1 | ||
25 | + # | ||
26 | + # object = mock() | ||
27 | + # object.expects(:method_1).with(has_entry('key_1' => 1)) | ||
28 | + # object.method_1('key_1' => 2, 'key_2' => 1) | ||
29 | + # # error raised, because method_1 was not called with Hash containing entry: 'key_1' => 1 | ||
30 | + def has_entry(*options) | ||
31 | + key, value = options.shift, options.shift | ||
32 | + key, value = key.to_a[0][0..1] if key.is_a?(Hash) | ||
33 | + HasEntry.new(key, value) | ||
34 | + end | ||
35 | + | ||
36 | + class HasEntry < Base # :nodoc: | ||
37 | + | ||
38 | + def initialize(key, value) | ||
39 | + @key, @value = key, value | ||
40 | + end | ||
41 | + | ||
42 | + def matches?(available_parameters) | ||
43 | + parameter = available_parameters.shift | ||
44 | + return false unless parameter.respond_to?(:keys) && parameter.respond_to?(:[]) | ||
45 | + matching_keys = parameter.keys.select { |key| @key.to_matcher.matches?([key]) } | ||
46 | + matching_keys.any? { |key| @value.to_matcher.matches?([parameter[key]]) } | ||
47 | + end | ||
48 | + | ||
49 | + def mocha_inspect | ||
50 | + "has_entry(#{@key.mocha_inspect} => #{@value.mocha_inspect})" | ||
51 | + end | ||
52 | + | ||
53 | + end | ||
54 | + | ||
55 | + end | ||
56 | + | ||
57 | +end | ||
0 | \ No newline at end of file | 58 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_key.rb
0 → 100644
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: has_key(key) -> parameter_matcher | ||
8 | + # | ||
9 | + # Matches +Hash+ containing +key+. | ||
10 | + # object = mock() | ||
11 | + # object.expects(:method_1).with(has_key('key_1')) | ||
12 | + # object.method_1('key_1' => 1, 'key_2' => 2) | ||
13 | + # # no error raised | ||
14 | + # | ||
15 | + # object = mock() | ||
16 | + # object.expects(:method_1).with(has_key('key_1')) | ||
17 | + # object.method_1('key_2' => 2) | ||
18 | + # # error raised, because method_1 was not called with Hash containing key: 'key_1' | ||
19 | + def has_key(key) | ||
20 | + HasKey.new(key) | ||
21 | + end | ||
22 | + | ||
23 | + class HasKey < Base # :nodoc: | ||
24 | + | ||
25 | + def initialize(key) | ||
26 | + @key = key | ||
27 | + end | ||
28 | + | ||
29 | + def matches?(available_parameters) | ||
30 | + parameter = available_parameters.shift | ||
31 | + parameter.keys.any? { |key| @key.to_matcher.matches?([key]) } | ||
32 | + end | ||
33 | + | ||
34 | + def mocha_inspect | ||
35 | + "has_key(#{@key.mocha_inspect})" | ||
36 | + end | ||
37 | + | ||
38 | + end | ||
39 | + | ||
40 | + end | ||
41 | + | ||
42 | +end | ||
0 | \ No newline at end of file | 43 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/has_value.rb
0 → 100644
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: has_value(value) -> parameter_matcher | ||
8 | + # | ||
9 | + # Matches +Hash+ containing +value+. | ||
10 | + # object = mock() | ||
11 | + # object.expects(:method_1).with(has_value(1)) | ||
12 | + # object.method_1('key_1' => 1, 'key_2' => 2) | ||
13 | + # # no error raised | ||
14 | + # | ||
15 | + # object = mock() | ||
16 | + # object.expects(:method_1).with(has_value(1)) | ||
17 | + # object.method_1('key_2' => 2) | ||
18 | + # # error raised, because method_1 was not called with Hash containing value: 1 | ||
19 | + def has_value(value) | ||
20 | + HasValue.new(value) | ||
21 | + end | ||
22 | + | ||
23 | + class HasValue < Base # :nodoc: | ||
24 | + | ||
25 | + def initialize(value) | ||
26 | + @value = value | ||
27 | + end | ||
28 | + | ||
29 | + def matches?(available_parameters) | ||
30 | + parameter = available_parameters.shift | ||
31 | + parameter.values.any? { |value| @value.to_matcher.matches?([value]) } | ||
32 | + end | ||
33 | + | ||
34 | + def mocha_inspect | ||
35 | + "has_value(#{@value.mocha_inspect})" | ||
36 | + end | ||
37 | + | ||
38 | + end | ||
39 | + | ||
40 | + end | ||
41 | + | ||
42 | +end | ||
0 | \ No newline at end of file | 43 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/includes.rb
0 → 100644
@@ -0,0 +1,40 @@ | @@ -0,0 +1,40 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: includes(item) -> parameter_matcher | ||
8 | + # | ||
9 | + # Matches any object that responds true to include?(item) | ||
10 | + # object = mock() | ||
11 | + # object.expects(:method_1).with(includes('foo')) | ||
12 | + # object.method_1(['foo', 'bar']) | ||
13 | + # # no error raised | ||
14 | + # | ||
15 | + # object.method_1(['baz']) | ||
16 | + # # error raised, because ['baz'] does not include 'foo'. | ||
17 | + def includes(item) | ||
18 | + Includes.new(item) | ||
19 | + end | ||
20 | + | ||
21 | + class Includes < Base # :nodoc: | ||
22 | + | ||
23 | + def initialize(item) | ||
24 | + @item = item | ||
25 | + end | ||
26 | + | ||
27 | + def matches?(available_parameters) | ||
28 | + parameter = available_parameters.shift | ||
29 | + return parameter.include?(@item) | ||
30 | + end | ||
31 | + | ||
32 | + def mocha_inspect | ||
33 | + "includes(#{@item.mocha_inspect})" | ||
34 | + end | ||
35 | + | ||
36 | + end | ||
37 | + | ||
38 | + end | ||
39 | + | ||
40 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/instance_of.rb
0 → 100644
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: instance_of(klass) -> parameter_matcher | ||
8 | + # | ||
9 | + # Matches any object that is an instance of +klass+ | ||
10 | + # object = mock() | ||
11 | + # object.expects(:method_1).with(instance_of(String)) | ||
12 | + # object.method_1('string') | ||
13 | + # # no error raised | ||
14 | + # | ||
15 | + # object = mock() | ||
16 | + # object.expects(:method_1).with(instance_of(String)) | ||
17 | + # object.method_1(99) | ||
18 | + # # error raised, because method_1 was not called with an instance of String | ||
19 | + def instance_of(klass) | ||
20 | + InstanceOf.new(klass) | ||
21 | + end | ||
22 | + | ||
23 | + class InstanceOf < Base # :nodoc: | ||
24 | + | ||
25 | + def initialize(klass) | ||
26 | + @klass = klass | ||
27 | + end | ||
28 | + | ||
29 | + def matches?(available_parameters) | ||
30 | + parameter = available_parameters.shift | ||
31 | + parameter.instance_of?(@klass) | ||
32 | + end | ||
33 | + | ||
34 | + def mocha_inspect | ||
35 | + "instance_of(#{@klass.mocha_inspect})" | ||
36 | + end | ||
37 | + | ||
38 | + end | ||
39 | + | ||
40 | + end | ||
41 | + | ||
42 | +end | ||
0 | \ No newline at end of file | 43 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/is_a.rb
0 → 100644
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: is_a(klass) -> parameter_matcher | ||
8 | + # | ||
9 | + # Matches any object that is a +klass+ | ||
10 | + # object = mock() | ||
11 | + # object.expects(:method_1).with(is_a(Integer)) | ||
12 | + # object.method_1(99) | ||
13 | + # # no error raised | ||
14 | + # | ||
15 | + # object = mock() | ||
16 | + # object.expects(:method_1).with(is_a(Integer)) | ||
17 | + # object.method_1('string') | ||
18 | + # # error raised, because method_1 was not called with an Integer | ||
19 | + def is_a(klass) | ||
20 | + IsA.new(klass) | ||
21 | + end | ||
22 | + | ||
23 | + class IsA < Base # :nodoc: | ||
24 | + | ||
25 | + def initialize(klass) | ||
26 | + @klass = klass | ||
27 | + end | ||
28 | + | ||
29 | + def matches?(available_parameters) | ||
30 | + parameter = available_parameters.shift | ||
31 | + parameter.is_a?(@klass) | ||
32 | + end | ||
33 | + | ||
34 | + def mocha_inspect | ||
35 | + "is_a(#{@klass.mocha_inspect})" | ||
36 | + end | ||
37 | + | ||
38 | + end | ||
39 | + | ||
40 | + end | ||
41 | + | ||
42 | +end | ||
0 | \ No newline at end of file | 43 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/kind_of.rb
0 → 100644
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: kind_of(klass) -> parameter_matcher | ||
8 | + # | ||
9 | + # Matches any object that is a kind of +klass+ | ||
10 | + # object = mock() | ||
11 | + # object.expects(:method_1).with(kind_of(Integer)) | ||
12 | + # object.method_1(99) | ||
13 | + # # no error raised | ||
14 | + # | ||
15 | + # object = mock() | ||
16 | + # object.expects(:method_1).with(kind_of(Integer)) | ||
17 | + # object.method_1('string') | ||
18 | + # # error raised, because method_1 was not called with a kind of Integer | ||
19 | + def kind_of(klass) | ||
20 | + KindOf.new(klass) | ||
21 | + end | ||
22 | + | ||
23 | + class KindOf < Base # :nodoc: | ||
24 | + | ||
25 | + def initialize(klass) | ||
26 | + @klass = klass | ||
27 | + end | ||
28 | + | ||
29 | + def matches?(available_parameters) | ||
30 | + parameter = available_parameters.shift | ||
31 | + parameter.kind_of?(@klass) | ||
32 | + end | ||
33 | + | ||
34 | + def mocha_inspect | ||
35 | + "kind_of(#{@klass.mocha_inspect})" | ||
36 | + end | ||
37 | + | ||
38 | + end | ||
39 | + | ||
40 | + end | ||
41 | + | ||
42 | +end | ||
0 | \ No newline at end of file | 43 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/not.rb
0 → 100644
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: Not(parameter_matcher) -> parameter_matcher | ||
8 | + # | ||
9 | + # Matches if +parameter_matcher+ does not match. | ||
10 | + # object = mock() | ||
11 | + # object.expects(:method_1).with(Not(includes(1))) | ||
12 | + # object.method_1([0, 2, 3]) | ||
13 | + # # no error raised | ||
14 | + # | ||
15 | + # object = mock() | ||
16 | + # object.expects(:method_1).with(Not(includes(1))) | ||
17 | + # object.method_1([0, 1, 2, 3]) | ||
18 | + # # error raised, because method_1 was not called with object not including 1 | ||
19 | + def Not(matcher) | ||
20 | + Not.new(matcher) | ||
21 | + end | ||
22 | + | ||
23 | + class Not < Base # :nodoc: | ||
24 | + | ||
25 | + def initialize(matcher) | ||
26 | + @matcher = matcher | ||
27 | + end | ||
28 | + | ||
29 | + def matches?(available_parameters) | ||
30 | + parameter = available_parameters.shift | ||
31 | + !@matcher.matches?([parameter]) | ||
32 | + end | ||
33 | + | ||
34 | + def mocha_inspect | ||
35 | + "Not(#{@matcher.mocha_inspect})" | ||
36 | + end | ||
37 | + | ||
38 | + end | ||
39 | + | ||
40 | + end | ||
41 | + | ||
42 | +end | ||
0 | \ No newline at end of file | 43 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/object.rb
0 → 100644
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/optionally.rb
0 → 100644
@@ -0,0 +1,55 @@ | @@ -0,0 +1,55 @@ | ||
1 | +module Mocha | ||
2 | + | ||
3 | + module ParameterMatchers | ||
4 | + | ||
5 | + # :call-seq: optionally(*parameter_matchers) -> parameter_matcher | ||
6 | + # | ||
7 | + # Matches optional parameters if available. | ||
8 | + # object = mock() | ||
9 | + # object.expects(:method_1).with(1, 2, optionally(3, 4)) | ||
10 | + # object.method_1(1, 2) | ||
11 | + # # no error raised | ||
12 | + # | ||
13 | + # object = mock() | ||
14 | + # object.expects(:method_1).with(1, 2, optionally(3, 4)) | ||
15 | + # object.method_1(1, 2, 3) | ||
16 | + # # no error raised | ||
17 | + # | ||
18 | + # object = mock() | ||
19 | + # object.expects(:method_1).with(1, 2, optionally(3, 4)) | ||
20 | + # object.method_1(1, 2, 3, 4) | ||
21 | + # # no error raised | ||
22 | + # | ||
23 | + # object = mock() | ||
24 | + # object.expects(:method_1).with(1, 2, optionally(3, 4)) | ||
25 | + # object.method_1(1, 2, 3, 5) | ||
26 | + # # error raised, because optional parameters did not match | ||
27 | + def optionally(*matchers) | ||
28 | + Optionally.new(*matchers) | ||
29 | + end | ||
30 | + | ||
31 | + class Optionally < Base # :nodoc: | ||
32 | + | ||
33 | + def initialize(*parameters) | ||
34 | + @matchers = parameters.map { |parameter| parameter.to_matcher } | ||
35 | + end | ||
36 | + | ||
37 | + def matches?(available_parameters) | ||
38 | + index = 0 | ||
39 | + while (available_parameters.length > 0) && (index < @matchers.length) do | ||
40 | + matcher = @matchers[index] | ||
41 | + return false unless matcher.matches?(available_parameters) | ||
42 | + index += 1 | ||
43 | + end | ||
44 | + return true | ||
45 | + end | ||
46 | + | ||
47 | + def mocha_inspect | ||
48 | + "optionally(#{@matchers.map { |matcher| matcher.mocha_inspect }.join(", ") })" | ||
49 | + end | ||
50 | + | ||
51 | + end | ||
52 | + | ||
53 | + end | ||
54 | + | ||
55 | +end | ||
0 | \ No newline at end of file | 56 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/regexp_matches.rb
0 → 100644
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + module ParameterMatchers | ||
6 | + | ||
7 | + # :call-seq: regexp_matches(regular_expression) -> parameter_matcher | ||
8 | + # | ||
9 | + # Matches any object that matches +regular_expression+. | ||
10 | + # object = mock() | ||
11 | + # object.expects(:method_1).with(regexp_matches(/e/)) | ||
12 | + # object.method_1('hello') | ||
13 | + # # no error raised | ||
14 | + # | ||
15 | + # object = mock() | ||
16 | + # object.expects(:method_1).with(regexp_matches(/a/)) | ||
17 | + # object.method_1('hello') | ||
18 | + # # error raised, because method_1 was not called with a parameter that matched the | ||
19 | + # # regular expression | ||
20 | + def regexp_matches(regexp) | ||
21 | + RegexpMatches.new(regexp) | ||
22 | + end | ||
23 | + | ||
24 | + class RegexpMatches < Base # :nodoc: | ||
25 | + | ||
26 | + def initialize(regexp) | ||
27 | + @regexp = regexp | ||
28 | + end | ||
29 | + | ||
30 | + def matches?(available_parameters) | ||
31 | + parameter = available_parameters.shift | ||
32 | + parameter =~ @regexp | ||
33 | + end | ||
34 | + | ||
35 | + def mocha_inspect | ||
36 | + "regexp_matches(#{@regexp.mocha_inspect})" | ||
37 | + end | ||
38 | + | ||
39 | + end | ||
40 | + | ||
41 | + end | ||
42 | + | ||
43 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/responds_with.rb
0 → 100644
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | +require 'yaml' | ||
3 | + | ||
4 | +module Mocha | ||
5 | + | ||
6 | + module ParameterMatchers | ||
7 | + | ||
8 | + # :call-seq: responds_with(message, result) -> parameter_matcher | ||
9 | + # | ||
10 | + # Matches any object that responds to +message+ with +result+. To put it another way, it tests the quack, not the duck. | ||
11 | + # object = mock() | ||
12 | + # object.expects(:method_1).with(responds_with(:upcase, "FOO")) | ||
13 | + # object.method_1("foo") | ||
14 | + # # no error raised, because "foo".upcase == "FOO" | ||
15 | + # | ||
16 | + # object = mock() | ||
17 | + # object.expects(:method_1).with(responds_with(:upcase, "BAR")) | ||
18 | + # object.method_1("foo") | ||
19 | + # # error raised, because "foo".upcase != "BAR" | ||
20 | + def responds_with(message, result) | ||
21 | + RespondsWith.new(message, result) | ||
22 | + end | ||
23 | + | ||
24 | + class RespondsWith < Base # :nodoc: | ||
25 | + | ||
26 | + def initialize(message, result) | ||
27 | + @message, @result = message, result | ||
28 | + end | ||
29 | + | ||
30 | + def matches?(available_parameters) | ||
31 | + parameter = available_parameters.shift | ||
32 | + parameter.__send__(@message) == @result | ||
33 | + end | ||
34 | + | ||
35 | + def mocha_inspect | ||
36 | + "responds_with(#{@message.mocha_inspect}, #{@result.mocha_inspect})" | ||
37 | + end | ||
38 | + | ||
39 | + end | ||
40 | + | ||
41 | + end | ||
42 | + | ||
43 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameter_matchers/yaml_equivalent.rb
0 → 100644
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +require 'mocha/parameter_matchers/base' | ||
2 | +require 'yaml' | ||
3 | + | ||
4 | +module Mocha | ||
5 | + | ||
6 | + module ParameterMatchers | ||
7 | + | ||
8 | + # :call-seq: yaml_equivalent(object) -> parameter_matcher | ||
9 | + # | ||
10 | + # Matches any YAML that represents the specified +object+ | ||
11 | + # object = mock() | ||
12 | + # object.expects(:method_1).with(yaml_equivalent(1, 2, 3)) | ||
13 | + # object.method_1("--- \n- 1\n- 2\n- 3\n") | ||
14 | + # # no error raised | ||
15 | + # | ||
16 | + # object = mock() | ||
17 | + # object.expects(:method_1).with(yaml_equivalent(1, 2, 3)) | ||
18 | + # object.method_1("--- \n- 1\n- 2\n") | ||
19 | + # # error raised, because method_1 was not called with YAML representing the specified Array | ||
20 | + def yaml_equivalent(object) | ||
21 | + YamlEquivalent.new(object) | ||
22 | + end | ||
23 | + | ||
24 | + class YamlEquivalent < Base # :nodoc: | ||
25 | + | ||
26 | + def initialize(object) | ||
27 | + @object = object | ||
28 | + end | ||
29 | + | ||
30 | + def matches?(available_parameters) | ||
31 | + parameter = available_parameters.shift | ||
32 | + @object == YAML.load(parameter) | ||
33 | + end | ||
34 | + | ||
35 | + def mocha_inspect | ||
36 | + "yaml_equivalent(#{@object.mocha_inspect})" | ||
37 | + end | ||
38 | + | ||
39 | + end | ||
40 | + | ||
41 | + end | ||
42 | + | ||
43 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/parameters_matcher.rb
0 → 100644
@@ -0,0 +1,37 @@ | @@ -0,0 +1,37 @@ | ||
1 | +require 'mocha/inspect' | ||
2 | +require 'mocha/parameter_matchers' | ||
3 | + | ||
4 | +module Mocha | ||
5 | + | ||
6 | + class ParametersMatcher | ||
7 | + | ||
8 | + def initialize(expected_parameters = [ParameterMatchers::AnyParameters.new], &matching_block) | ||
9 | + @expected_parameters, @matching_block = expected_parameters, matching_block | ||
10 | + end | ||
11 | + | ||
12 | + def match?(actual_parameters = []) | ||
13 | + if @matching_block | ||
14 | + return @matching_block.call(*actual_parameters) | ||
15 | + else | ||
16 | + return parameters_match?(actual_parameters) | ||
17 | + end | ||
18 | + end | ||
19 | + | ||
20 | + def parameters_match?(actual_parameters) | ||
21 | + matchers.all? { |matcher| matcher.matches?(actual_parameters) } && (actual_parameters.length == 0) | ||
22 | + end | ||
23 | + | ||
24 | + def mocha_inspect | ||
25 | + signature = matchers.mocha_inspect | ||
26 | + signature = signature.gsub(/^\[|\]$/, '') | ||
27 | + signature = signature.gsub(/^\{|\}$/, '') if matchers.length == 1 | ||
28 | + "(#{signature})" | ||
29 | + end | ||
30 | + | ||
31 | + def matchers | ||
32 | + @expected_parameters.map { |parameter| parameter.to_matcher } | ||
33 | + end | ||
34 | + | ||
35 | + end | ||
36 | + | ||
37 | +end | ||
0 | \ No newline at end of file | 38 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/pretty_parameters.rb
0 → 100644
@@ -0,0 +1,28 @@ | @@ -0,0 +1,28 @@ | ||
1 | +require 'mocha/inspect' | ||
2 | + | ||
3 | +module Mocha | ||
4 | + | ||
5 | + class PrettyParameters | ||
6 | + | ||
7 | + def initialize(params) | ||
8 | + @params = params | ||
9 | + @params_string = params.mocha_inspect | ||
10 | + end | ||
11 | + | ||
12 | + def pretty | ||
13 | + remove_outer_array_braces! | ||
14 | + remove_outer_hash_braces! | ||
15 | + @params_string | ||
16 | + end | ||
17 | + | ||
18 | + def remove_outer_array_braces! | ||
19 | + @params_string = @params_string.gsub(/^\[|\]$/, '') | ||
20 | + end | ||
21 | + | ||
22 | + def remove_outer_hash_braces! | ||
23 | + @params_string = @params_string.gsub(/^\{|\}$/, '') if @params.length == 1 | ||
24 | + end | ||
25 | + | ||
26 | + end | ||
27 | + | ||
28 | +end | ||
0 | \ No newline at end of file | 29 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/return_values.rb
0 → 100644
@@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
1 | +require 'mocha/single_return_value' | ||
2 | + | ||
3 | +module Mocha # :nodoc: | ||
4 | + | ||
5 | + class ReturnValues # :nodoc: | ||
6 | + | ||
7 | + def self.build(*values) | ||
8 | + new(*values.map { |value| SingleReturnValue.new(value) }) | ||
9 | + end | ||
10 | + | ||
11 | + attr_accessor :values | ||
12 | + | ||
13 | + def initialize(*values) | ||
14 | + @values = values | ||
15 | + end | ||
16 | + | ||
17 | + def next | ||
18 | + case @values.length | ||
19 | + when 0 then nil | ||
20 | + when 1 then @values.first.evaluate | ||
21 | + else @values.shift.evaluate | ||
22 | + end | ||
23 | + end | ||
24 | + | ||
25 | + def +(other) | ||
26 | + self.class.new(*(@values + other.values)) | ||
27 | + end | ||
28 | + | ||
29 | + end | ||
30 | + | ||
31 | +end | ||
0 | \ No newline at end of file | 32 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/sequence.rb
0 → 100644
@@ -0,0 +1,42 @@ | @@ -0,0 +1,42 @@ | ||
1 | +module Mocha # :nodoc: | ||
2 | + | ||
3 | + class Sequence | ||
4 | + | ||
5 | + class InSequenceOrderingConstraint | ||
6 | + | ||
7 | + def initialize(sequence, index) | ||
8 | + @sequence, @index = sequence, index | ||
9 | + end | ||
10 | + | ||
11 | + def allows_invocation_now? | ||
12 | + @sequence.satisfied_to_index?(@index) | ||
13 | + end | ||
14 | + | ||
15 | + def mocha_inspect | ||
16 | + "in sequence #{@sequence.mocha_inspect}" | ||
17 | + end | ||
18 | + | ||
19 | + end | ||
20 | + | ||
21 | + def initialize(name) | ||
22 | + @name = name | ||
23 | + @expectations = [] | ||
24 | + end | ||
25 | + | ||
26 | + def constrain_as_next_in_sequence(expectation) | ||
27 | + index = @expectations.length | ||
28 | + @expectations << expectation | ||
29 | + expectation.add_ordering_constraint(InSequenceOrderingConstraint.new(self, index)) | ||
30 | + end | ||
31 | + | ||
32 | + def satisfied_to_index?(index) | ||
33 | + @expectations[0...index].all? { |expectation| expectation.satisfied? } | ||
34 | + end | ||
35 | + | ||
36 | + def mocha_inspect | ||
37 | + "#{@name.mocha_inspect}" | ||
38 | + end | ||
39 | + | ||
40 | + end | ||
41 | + | ||
42 | +end | ||
0 | \ No newline at end of file | 43 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/single_return_value.rb
0 → 100644
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/single_yield.rb
0 → 100644
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/state_machine.rb
0 → 100644
@@ -0,0 +1,91 @@ | @@ -0,0 +1,91 @@ | ||
1 | +module Mocha # :nodoc: | ||
2 | + | ||
3 | + # A state machine that is used to constrain the order of invocations. | ||
4 | + # An invocation can be constrained to occur when a state is, or is_not, active. | ||
5 | + class StateMachine | ||
6 | + | ||
7 | + class State # :nodoc: | ||
8 | + | ||
9 | + def initialize(state_machine, state) | ||
10 | + @state_machine, @state = state_machine, state | ||
11 | + end | ||
12 | + | ||
13 | + def activate | ||
14 | + @state_machine.current_state = @state | ||
15 | + end | ||
16 | + | ||
17 | + def active? | ||
18 | + @state_machine.current_state == @state | ||
19 | + end | ||
20 | + | ||
21 | + def mocha_inspect | ||
22 | + "#{@state_machine.name} is #{@state.mocha_inspect}" | ||
23 | + end | ||
24 | + | ||
25 | + end | ||
26 | + | ||
27 | + class StatePredicate # :nodoc: | ||
28 | + | ||
29 | + def initialize(state_machine, state) | ||
30 | + @state_machine, @state = state_machine, state | ||
31 | + end | ||
32 | + | ||
33 | + def active? | ||
34 | + @state_machine.current_state != @state | ||
35 | + end | ||
36 | + | ||
37 | + def mocha_inspect | ||
38 | + "#{@state_machine.name} is not #{@state.mocha_inspect}" | ||
39 | + end | ||
40 | + | ||
41 | + end | ||
42 | + | ||
43 | + attr_reader :name # :nodoc: | ||
44 | + | ||
45 | + attr_accessor :current_state # :nodoc: | ||
46 | + | ||
47 | + def initialize(name) # :nodoc: | ||
48 | + @name = name | ||
49 | + @current_state = nil | ||
50 | + end | ||
51 | + | ||
52 | + # :call-seq: starts_as(initial_state) -> state_machine | ||
53 | + # | ||
54 | + # Put the +state_machine+ into the +initial_state+. | ||
55 | + def starts_as(initial_state) | ||
56 | + become(initial_state) | ||
57 | + self | ||
58 | + end | ||
59 | + | ||
60 | + # :call-seq: become(next_state) | ||
61 | + # | ||
62 | + # Put the +state_machine+ into the +next_state+. | ||
63 | + def become(next_state) | ||
64 | + @current_state = next_state | ||
65 | + end | ||
66 | + | ||
67 | + # :call-seq: is(state) | ||
68 | + # | ||
69 | + # Determines whether the +state_machine+ is in the specified +state+. | ||
70 | + def is(state) | ||
71 | + State.new(self, state) | ||
72 | + end | ||
73 | + | ||
74 | + # :call-seq: is_not(state) | ||
75 | + # | ||
76 | + # Determines whether the +state_machine+ is not in the specified +state+. | ||
77 | + def is_not(state) | ||
78 | + StatePredicate.new(self, state) | ||
79 | + end | ||
80 | + | ||
81 | + def mocha_inspect # :nodoc: | ||
82 | + if @current_state | ||
83 | + "#{@name} is #{@current_state.mocha_inspect}" | ||
84 | + else | ||
85 | + "#{@name} has no current state" | ||
86 | + end | ||
87 | + end | ||
88 | + | ||
89 | + end | ||
90 | + | ||
91 | +end | ||
0 | \ No newline at end of file | 92 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/stubbing_error.rb
0 → 100644
@@ -0,0 +1,16 @@ | @@ -0,0 +1,16 @@ | ||
1 | +require 'mocha/backtrace_filter' | ||
2 | + | ||
3 | +module Mocha # :nodoc: | ||
4 | + | ||
5 | + # Exception raised when an action prevented by Configuration#prevent is attempted. | ||
6 | + class StubbingError < StandardError | ||
7 | + | ||
8 | + def initialize(message = nil, backtrace = []) # :nodoc: | ||
9 | + super(message) | ||
10 | + filter = BacktraceFilter.new | ||
11 | + set_backtrace(filter.filtered(backtrace)) | ||
12 | + end | ||
13 | + | ||
14 | + end | ||
15 | + | ||
16 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/unexpected_invocation.rb
0 → 100644
@@ -0,0 +1,18 @@ | @@ -0,0 +1,18 @@ | ||
1 | +module Mocha # :nodoc: | ||
2 | + | ||
3 | + class UnexpectedInvocation | ||
4 | + | ||
5 | + def initialize(mock, symbol, *arguments) | ||
6 | + @mock = mock | ||
7 | + @method_matcher = MethodMatcher.new(symbol) | ||
8 | + @parameters_matcher = ParametersMatcher.new(arguments) | ||
9 | + end | ||
10 | + | ||
11 | + def to_s | ||
12 | + method_signature = "#{@mock.mocha_inspect}.#{@method_matcher.mocha_inspect}#{@parameters_matcher.mocha_inspect}" | ||
13 | + "unexpected invocation: #{method_signature}\n" | ||
14 | + end | ||
15 | + | ||
16 | + end | ||
17 | + | ||
18 | +end | ||
0 | \ No newline at end of file | 19 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha/yield_parameters.rb
0 → 100644
@@ -0,0 +1,31 @@ | @@ -0,0 +1,31 @@ | ||
1 | +require 'mocha/no_yields' | ||
2 | +require 'mocha/single_yield' | ||
3 | +require 'mocha/multiple_yields' | ||
4 | + | ||
5 | +module Mocha # :nodoc: | ||
6 | + | ||
7 | + class YieldParameters # :nodoc: | ||
8 | + | ||
9 | + def initialize | ||
10 | + @parameter_groups = [] | ||
11 | + end | ||
12 | + | ||
13 | + def next_invocation | ||
14 | + case @parameter_groups.length | ||
15 | + when 0 then NoYields.new | ||
16 | + when 1 then @parameter_groups.first | ||
17 | + else @parameter_groups.shift | ||
18 | + end | ||
19 | + end | ||
20 | + | ||
21 | + def add(*parameters) | ||
22 | + @parameter_groups << SingleYield.new(*parameters) | ||
23 | + end | ||
24 | + | ||
25 | + def multiple_add(*parameter_groups) | ||
26 | + @parameter_groups << MultipleYields.new(*parameter_groups) | ||
27 | + end | ||
28 | + | ||
29 | + end | ||
30 | + | ||
31 | +end | ||
0 | \ No newline at end of file | 32 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/mocha_standalone.rb
0 → 100644
vendor/gems/jferris-mocha-0.9.5.0.1241126838/lib/stubba.rb
0 → 100644
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/acceptance_test_helper.rb
0 → 100644
@@ -0,0 +1,38 @@ | @@ -0,0 +1,38 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "..", "test_helper") | ||
2 | +require 'test_runner' | ||
3 | +require 'mocha/configuration' | ||
4 | + | ||
5 | +module AcceptanceTest | ||
6 | + | ||
7 | + class FakeLogger | ||
8 | + | ||
9 | + attr_reader :warnings | ||
10 | + | ||
11 | + def initialize | ||
12 | + @warnings = [] | ||
13 | + end | ||
14 | + | ||
15 | + def warn(message) | ||
16 | + @warnings << message | ||
17 | + end | ||
18 | + | ||
19 | + end | ||
20 | + | ||
21 | + attr_reader :logger | ||
22 | + | ||
23 | + include TestRunner | ||
24 | + | ||
25 | + def setup_acceptance_test | ||
26 | + Mocha::Configuration.reset_configuration | ||
27 | + @logger = FakeLogger.new | ||
28 | + mockery = Mocha::Mockery.instance | ||
29 | + @original_logger = mockery.logger | ||
30 | + mockery.logger = @logger | ||
31 | + end | ||
32 | + | ||
33 | + def teardown_acceptance_test | ||
34 | + Mocha::Configuration.reset_configuration | ||
35 | + Mocha::Mockery.instance.logger = @original_logger | ||
36 | + end | ||
37 | + | ||
38 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/api_test.rb
0 → 100644
@@ -0,0 +1,139 @@ | @@ -0,0 +1,139 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | +require 'mocha_standalone' | ||
3 | +require 'simple_counter' | ||
4 | + | ||
5 | +class NotATestUnitAssertionFailedError < StandardError | ||
6 | +end | ||
7 | + | ||
8 | +class NotATestUnitTestCase | ||
9 | + | ||
10 | + include Mocha::API | ||
11 | + | ||
12 | + attr_reader :assertion_counter | ||
13 | + | ||
14 | + def initialize | ||
15 | + @assertion_counter = SimpleCounter.new | ||
16 | + end | ||
17 | + | ||
18 | + def run(test_method) | ||
19 | + mocha_setup | ||
20 | + begin | ||
21 | + prepare | ||
22 | + begin | ||
23 | + send(test_method) | ||
24 | + mocha_verify(@assertion_counter) | ||
25 | + rescue Mocha::ExpectationError => e | ||
26 | + new_error = NotATestUnitAssertionFailedError.new(e.message) | ||
27 | + new_error.set_backtrace(e.backtrace) | ||
28 | + raise new_error | ||
29 | + ensure | ||
30 | + cleanup | ||
31 | + end | ||
32 | + ensure | ||
33 | + mocha_teardown | ||
34 | + end | ||
35 | + end | ||
36 | + | ||
37 | + def prepare | ||
38 | + end | ||
39 | + | ||
40 | + def cleanup | ||
41 | + end | ||
42 | + | ||
43 | +end | ||
44 | + | ||
45 | +class SampleTest < NotATestUnitTestCase | ||
46 | + | ||
47 | + def mocha_with_fulfilled_expectation | ||
48 | + mockee = mock() | ||
49 | + mockee.expects(:blah) | ||
50 | + mockee.blah | ||
51 | + end | ||
52 | + | ||
53 | + def mocha_with_unfulfilled_expectation | ||
54 | + mockee = mock() | ||
55 | + mockee.expects(:blah) | ||
56 | + end | ||
57 | + | ||
58 | + def mocha_with_unexpected_invocation | ||
59 | + mockee = mock() | ||
60 | + mockee.blah | ||
61 | + end | ||
62 | + | ||
63 | + def stubba_with_fulfilled_expectation | ||
64 | + stubbee = Class.new { define_method(:blah) {} }.new | ||
65 | + stubbee.expects(:blah) | ||
66 | + stubbee.blah | ||
67 | + end | ||
68 | + | ||
69 | + def stubba_with_unfulfilled_expectation | ||
70 | + stubbee = Class.new { define_method(:blah) {} }.new | ||
71 | + stubbee.expects(:blah) | ||
72 | + end | ||
73 | + | ||
74 | + def mocha_with_matching_parameter | ||
75 | + mockee = mock() | ||
76 | + mockee.expects(:blah).with(has_key(:wibble)) | ||
77 | + mockee.blah(:wibble => 1) | ||
78 | + end | ||
79 | + | ||
80 | + def mocha_with_non_matching_parameter | ||
81 | + mockee = mock() | ||
82 | + mockee.expects(:blah).with(has_key(:wibble)) | ||
83 | + mockee.blah(:wobble => 2) | ||
84 | + end | ||
85 | + | ||
86 | +end | ||
87 | + | ||
88 | +require 'test/unit' | ||
89 | + | ||
90 | +class APITest < Test::Unit::TestCase | ||
91 | + | ||
92 | + attr_reader :sample_test | ||
93 | + | ||
94 | + include AcceptanceTest | ||
95 | + | ||
96 | + def setup | ||
97 | + @sample_test = SampleTest.new | ||
98 | + setup_acceptance_test | ||
99 | + end | ||
100 | + | ||
101 | + def teardown | ||
102 | + teardown_acceptance_test | ||
103 | + end | ||
104 | + | ||
105 | + def test_should_pass_mocha_test | ||
106 | + assert_nothing_raised { sample_test.run(:mocha_with_fulfilled_expectation) } | ||
107 | + assert_equal 1, sample_test.assertion_counter.count | ||
108 | + end | ||
109 | + | ||
110 | + def test_should_fail_mocha_test_due_to_unfulfilled_exception | ||
111 | + assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_unfulfilled_expectation) } | ||
112 | + assert_equal 1, sample_test.assertion_counter.count | ||
113 | + end | ||
114 | + | ||
115 | + def test_should_fail_mocha_test_due_to_unexpected_invocation | ||
116 | + assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_unexpected_invocation) } | ||
117 | + assert_equal 0, sample_test.assertion_counter.count | ||
118 | + end | ||
119 | + | ||
120 | + def test_should_pass_stubba_test | ||
121 | + assert_nothing_raised { sample_test.run(:stubba_with_fulfilled_expectation) } | ||
122 | + assert_equal 1, sample_test.assertion_counter.count | ||
123 | + end | ||
124 | + | ||
125 | + def test_should_fail_stubba_test | ||
126 | + assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:stubba_with_unfulfilled_expectation) } | ||
127 | + assert_equal 1, sample_test.assertion_counter.count | ||
128 | + end | ||
129 | + | ||
130 | + def test_should_pass_mocha_test_with_matching_parameter | ||
131 | + assert_nothing_raised { sample_test.run(:mocha_with_matching_parameter) } | ||
132 | + assert_equal 1, sample_test.assertion_counter.count | ||
133 | + end | ||
134 | + | ||
135 | + def test_should_fail_mocha_test_with_non_matching_parameter | ||
136 | + assert_raises(NotATestUnitAssertionFailedError) { sample_test.run(:mocha_with_non_matching_parameter) } | ||
137 | + end | ||
138 | + | ||
139 | +end | ||
0 | \ No newline at end of file | 140 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bacon_spec.rb
0 → 100644
@@ -0,0 +1,67 @@ | @@ -0,0 +1,67 @@ | ||
1 | +# This is not meant to be run by itself. It will be run by bacon_test.rb | ||
2 | +$:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "..", "lib")) | ||
3 | +require 'bacon' | ||
4 | +require 'mocha' | ||
5 | + | ||
6 | +module MetaTestOutput | ||
7 | + def handle_specification(name) | ||
8 | + yield | ||
9 | + end | ||
10 | + | ||
11 | + def handle_requirement(description) | ||
12 | + yield | ||
13 | + end | ||
14 | + | ||
15 | + def handle_summary | ||
16 | + puts | ||
17 | + puts Bacon::ErrorLog if Bacon::Backtraces | ||
18 | + puts "%d tests, %d assertions, %d failures, %d errors" % | ||
19 | + Bacon::Counter.values_at(:specifications, :requirements, :failed, :errors) | ||
20 | + end | ||
21 | + | ||
22 | +end | ||
23 | + | ||
24 | +Bacon.extend MetaTestOutput | ||
25 | +Bacon.summary_on_exit | ||
26 | + | ||
27 | +describe "Bacon specs using Mocha" do | ||
28 | + should "pass when all expectations were fulfilled" do | ||
29 | + mockee = mock() | ||
30 | + mockee.expects(:blah) | ||
31 | + mockee.blah | ||
32 | + end | ||
33 | + | ||
34 | + should "fail when not all expectations were fulfilled" do | ||
35 | + mockee = mock() | ||
36 | + mockee.expects(:blah) | ||
37 | + end | ||
38 | + | ||
39 | + should "fail when there is an unexpected invocation" do | ||
40 | + mockee = mock() | ||
41 | + mockee.blah | ||
42 | + end | ||
43 | + | ||
44 | + should "pass when they receive all expected parameters" do | ||
45 | + mockee = mock() | ||
46 | + mockee.expects(:blah).with(has_key(:wibble)) | ||
47 | + mockee.blah(:wibble => 1) | ||
48 | + end | ||
49 | + | ||
50 | + should "fail when they receive unexpected parameters" do | ||
51 | + mockee = mock() | ||
52 | + mockee.expects(:blah).with(has_key(:wibble)) | ||
53 | + mockee.blah(:wobble => 2) | ||
54 | + end | ||
55 | + | ||
56 | + should "pass when all Stubba expectations are fulfilled" do | ||
57 | + stubbee = Class.new { define_method(:blah) {} }.new | ||
58 | + stubbee.expects(:blah) | ||
59 | + stubbee.blah | ||
60 | + end | ||
61 | + | ||
62 | + should "fail when not all Stubba expectations were fulfilled" do | ||
63 | + stubbee = Class.new { define_method(:blah) {} }.new | ||
64 | + stubbee.expects(:blah) | ||
65 | + end | ||
66 | + | ||
67 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bacon_test.rb
0 → 100644
@@ -0,0 +1,110 @@ | @@ -0,0 +1,110 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | + | ||
3 | +begin | ||
4 | + require 'bacon' | ||
5 | +rescue LoadError | ||
6 | + # Bacon not available | ||
7 | +end | ||
8 | + | ||
9 | +if defined?(Bacon) && Bacon::VERSION >= "1.1" | ||
10 | + | ||
11 | + class BaconRunner | ||
12 | + | ||
13 | + attr_reader :output, :tests, :assertions, :failures, :errors | ||
14 | + | ||
15 | + def initialize(*paths) | ||
16 | + @paths = paths | ||
17 | + end | ||
18 | + | ||
19 | + def run(name) | ||
20 | + @output = `bacon -n '#{name}' #{@paths.join(' ')}` | ||
21 | + numbers = @output.scan(/(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors/) | ||
22 | + numbers.flatten!.map!{|e| e.to_i} | ||
23 | + | ||
24 | + @tests = numbers[0] | ||
25 | + @assertions = numbers[1] | ||
26 | + @failures = numbers[2] | ||
27 | + @errors = numbers[3] | ||
28 | + end | ||
29 | + | ||
30 | + end | ||
31 | + | ||
32 | + class BaconTest < Test::Unit::TestCase | ||
33 | + | ||
34 | + def setup | ||
35 | + @runner = BaconRunner.new("#{File.dirname(__FILE__)}/bacon_spec.rb") | ||
36 | + end | ||
37 | + | ||
38 | + def test_should_pass_mocha_test | ||
39 | + | ||
40 | + @runner.run('should pass when all expectations were fulfilled') | ||
41 | + | ||
42 | + assert_equal 0, @runner.errors | ||
43 | + assert_equal 1, @runner.tests | ||
44 | + end | ||
45 | + | ||
46 | + def test_should_fail_mocha_test_due_to_unfulfilled_expectation | ||
47 | + | ||
48 | + @runner.run('should fail when not all expectations were fulfilled') | ||
49 | + | ||
50 | + assert_equal 1, @runner.errors | ||
51 | + assert_equal 1, @runner.tests | ||
52 | + assert_not_all_expectation_were_satisfied(@runner.output) | ||
53 | + | ||
54 | + end | ||
55 | + | ||
56 | + def test_should_fail_mocha_test_due_to_unexpected_invocation | ||
57 | + @runner.run('should fail when there is an unexpected invocation') | ||
58 | + | ||
59 | + assert_equal 1, @runner.errors | ||
60 | + assert_equal 1, @runner.tests | ||
61 | + assert_unexpected_invocation(@runner.output) | ||
62 | + end | ||
63 | + | ||
64 | + | ||
65 | + def test_should_pass_stubba_test | ||
66 | + @runner.run('should pass when all Stubba expectations are fulfilled') | ||
67 | + | ||
68 | + assert_equal 0, @runner.errors | ||
69 | + assert_equal 1, @runner.tests | ||
70 | + end | ||
71 | + | ||
72 | + def test_should_fail_stubba_test_due_to_unfulfilled_expectation | ||
73 | + @runner.run('should fail when not all Stubba expectations were fulfilled') | ||
74 | + | ||
75 | + assert_equal 1, @runner.errors | ||
76 | + assert_equal 1, @runner.tests | ||
77 | + assert_not_all_expectation_were_satisfied(@runner.output) | ||
78 | + end | ||
79 | + | ||
80 | + def test_should_pass_mocha_test_with_matching_parameter | ||
81 | + @runner.run('should pass when they receive all expected parameters') | ||
82 | + | ||
83 | + assert_equal 0, @runner.errors | ||
84 | + assert_equal 1, @runner.tests | ||
85 | + end | ||
86 | + | ||
87 | + def test_should_fail_mocha_test_with_non_matching_parameter | ||
88 | + @runner.run('should fail when they receive unexpected parameters') | ||
89 | + | ||
90 | + assert_equal 1, @runner.errors | ||
91 | + assert_equal 1, @runner.tests | ||
92 | + assert_unexpected_invocation(@runner.output) | ||
93 | + end | ||
94 | + | ||
95 | + private | ||
96 | + | ||
97 | + def assert_unexpected_invocation(string) | ||
98 | + assert_match Regexp.new('unexpected invocation'), string, "Bacon output:\n#{string}" | ||
99 | + end | ||
100 | + | ||
101 | + def assert_not_all_expectation_were_satisfied(string) | ||
102 | + assert_match Regexp.new('not all expectations were satisfied'), string, "Bacon output:\n#{string}" | ||
103 | + end | ||
104 | + | ||
105 | + end | ||
106 | + | ||
107 | +else | ||
108 | + warn "Bacon is not available, so BaconTest has not been run." | ||
109 | +end | ||
110 | + |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_18914_test.rb
0 → 100644
@@ -0,0 +1,43 @@ | @@ -0,0 +1,43 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | +require 'mocha' | ||
3 | + | ||
4 | +class Bug18914Test < Test::Unit::TestCase | ||
5 | + | ||
6 | + include AcceptanceTest | ||
7 | + | ||
8 | + def setup | ||
9 | + setup_acceptance_test | ||
10 | + end | ||
11 | + | ||
12 | + def teardown | ||
13 | + teardown_acceptance_test | ||
14 | + end | ||
15 | + | ||
16 | + class AlwaysEql | ||
17 | + | ||
18 | + def my_method | ||
19 | + true | ||
20 | + end | ||
21 | + | ||
22 | + def ==(o) | ||
23 | + true | ||
24 | + end | ||
25 | + | ||
26 | + def eql?(o) | ||
27 | + true | ||
28 | + end | ||
29 | + | ||
30 | + end | ||
31 | + | ||
32 | + def test_should_not_allow_stubbing_of_non_mock_instance_disrupted_by_legitimate_overriding_of_eql_method | ||
33 | + | ||
34 | + always_eql_1 = AlwaysEql.new | ||
35 | + always_eql_1.stubs(:my_method).returns(false) | ||
36 | + | ||
37 | + always_eql_2 = AlwaysEql.new | ||
38 | + always_eql_2.stubs(:my_method).returns(false) | ||
39 | + | ||
40 | + assert_equal false, always_eql_2.my_method | ||
41 | + end | ||
42 | + | ||
43 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_21465_test.rb
0 → 100644
@@ -0,0 +1,34 @@ | @@ -0,0 +1,34 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | +require 'mocha' | ||
3 | + | ||
4 | +class Bug21465Test < Test::Unit::TestCase | ||
5 | + | ||
6 | + include AcceptanceTest | ||
7 | + | ||
8 | + def setup | ||
9 | + setup_acceptance_test | ||
10 | + end | ||
11 | + | ||
12 | + def teardown | ||
13 | + teardown_acceptance_test | ||
14 | + end | ||
15 | + | ||
16 | + def test_should_allow_expected_method_name_to_be_a_string | ||
17 | + test_result = run_as_test do | ||
18 | + mock = mock() | ||
19 | + mock.expects('wibble') | ||
20 | + mock.wibble | ||
21 | + end | ||
22 | + assert_passed(test_result) | ||
23 | + end | ||
24 | + | ||
25 | + def test_should_allow_stubbed_method_name_to_be_a_string | ||
26 | + test_result = run_as_test do | ||
27 | + mock = mock() | ||
28 | + mock.stubs('wibble') | ||
29 | + mock.wibble | ||
30 | + end | ||
31 | + assert_passed(test_result) | ||
32 | + end | ||
33 | + | ||
34 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/bug_21563_test.rb
0 → 100644
@@ -0,0 +1,25 @@ | @@ -0,0 +1,25 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | +require 'mocha' | ||
3 | + | ||
4 | +class Bug21563Test < Test::Unit::TestCase | ||
5 | + | ||
6 | + include AcceptanceTest | ||
7 | + | ||
8 | + def setup | ||
9 | + setup_acceptance_test | ||
10 | + end | ||
11 | + | ||
12 | + def teardown | ||
13 | + teardown_acceptance_test | ||
14 | + end | ||
15 | + | ||
16 | + def test_should_allow_stubbing_of_verified_method | ||
17 | + test_result = run_as_test do | ||
18 | + object = Object.new | ||
19 | + object.stubs(:verified?).returns(false) | ||
20 | + assert !object.verified? | ||
21 | + end | ||
22 | + assert_passed(test_result) | ||
23 | + end | ||
24 | + | ||
25 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/expected_invocation_count_test.rb
0 → 100644
@@ -0,0 +1,196 @@ | @@ -0,0 +1,196 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | +require 'mocha' | ||
3 | + | ||
4 | +class ExpectedInvocationCountTest < Test::Unit::TestCase | ||
5 | + | ||
6 | + include AcceptanceTest | ||
7 | + | ||
8 | + def setup | ||
9 | + setup_acceptance_test | ||
10 | + end | ||
11 | + | ||
12 | + def teardown | ||
13 | + teardown_acceptance_test | ||
14 | + end | ||
15 | + | ||
16 | + def test_should_pass_if_method_is_never_expected_and_is_never_called | ||
17 | + test_result = run_as_test do | ||
18 | + mock = mock('mock') | ||
19 | + mock.expects(:method).never | ||
20 | + 0.times { mock.method } | ||
21 | + end | ||
22 | + assert_passed(test_result) | ||
23 | + end | ||
24 | + | ||
25 | + def test_should_fail_fast_if_method_is_never_expected_but_is_called_once | ||
26 | + test_result = run_as_test do | ||
27 | + mock = mock('mock') | ||
28 | + mock.expects(:method).never | ||
29 | + 1.times { mock.method } | ||
30 | + end | ||
31 | + assert_failed(test_result) | ||
32 | + assert_equal ["unexpected invocation: #<Mock:mock>.method()\nsatisfied expectations:\n- expected never, not yet invoked: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages | ||
33 | + end | ||
34 | + | ||
35 | + def test_should_pass_if_method_is_expected_twice_and_is_called_twice | ||
36 | + test_result = run_as_test do | ||
37 | + mock = mock('mock') | ||
38 | + mock.expects(:method).twice | ||
39 | + 2.times { mock.method } | ||
40 | + end | ||
41 | + assert_passed(test_result) | ||
42 | + end | ||
43 | + | ||
44 | + def test_should_fail_if_method_is_expected_twice_but_is_called_once | ||
45 | + test_result = run_as_test do | ||
46 | + mock = mock('mock') | ||
47 | + mock.expects(:method).twice | ||
48 | + 1.times { mock.method } | ||
49 | + end | ||
50 | + assert_failed(test_result) | ||
51 | + assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected exactly twice, already invoked once: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages | ||
52 | + end | ||
53 | + | ||
54 | + def test_should_fail_fast_if_method_is_expected_twice_but_is_called_three_times | ||
55 | + test_result = run_as_test do | ||
56 | + mock = mock('mock') | ||
57 | + mock.expects(:method).twice | ||
58 | + 3.times { mock.method } | ||
59 | + end | ||
60 | + assert_failed(test_result) | ||
61 | + assert_equal ["unexpected invocation: #<Mock:mock>.method()\nsatisfied expectations:\n- expected exactly twice, already invoked twice: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages | ||
62 | + end | ||
63 | + | ||
64 | + def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_twice | ||
65 | + test_result = run_as_test do | ||
66 | + mock = mock('mock') | ||
67 | + mock.expects(:method).times(2..4) | ||
68 | + 2.times { mock.method } | ||
69 | + end | ||
70 | + assert_passed(test_result) | ||
71 | + end | ||
72 | + | ||
73 | + def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_three_times | ||
74 | + test_result = run_as_test do | ||
75 | + mock = mock('mock') | ||
76 | + mock.expects(:method).times(2..4) | ||
77 | + 3.times { mock.method } | ||
78 | + end | ||
79 | + assert_passed(test_result) | ||
80 | + end | ||
81 | + | ||
82 | + def test_should_pass_if_method_is_expected_between_two_and_four_times_and_is_called_four_times | ||
83 | + test_result = run_as_test do | ||
84 | + mock = mock('mock') | ||
85 | + mock.expects(:method).times(2..4) | ||
86 | + 4.times { mock.method } | ||
87 | + end | ||
88 | + assert_passed(test_result) | ||
89 | + end | ||
90 | + | ||
91 | + def test_should_fail_if_method_is_expected_between_two_and_four_times_and_is_called_once | ||
92 | + test_result = run_as_test do | ||
93 | + mock = mock('mock') | ||
94 | + mock.expects(:method).times(2..4) | ||
95 | + 1.times { mock.method } | ||
96 | + end | ||
97 | + assert_failed(test_result) | ||
98 | + assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected between 2 and 4 times, already invoked once: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages | ||
99 | + end | ||
100 | + | ||
101 | + def test_should_fail_fast_if_method_is_expected_between_two_and_four_times_and_is_called_five_times | ||
102 | + test_result = run_as_test do | ||
103 | + mock = mock('mock') | ||
104 | + mock.expects(:method).times(2..4) | ||
105 | + 5.times { mock.method } | ||
106 | + end | ||
107 | + assert_failed(test_result) | ||
108 | + assert_equal ["unexpected invocation: #<Mock:mock>.method()\nsatisfied expectations:\n- expected between 2 and 4 times, already invoked 4 times: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages | ||
109 | + end | ||
110 | + | ||
111 | + def test_should_pass_if_method_is_expected_at_least_once_and_is_called_once | ||
112 | + test_result = run_as_test do | ||
113 | + mock = mock('mock') | ||
114 | + mock.expects(:method).at_least_once | ||
115 | + 1.times { mock.method } | ||
116 | + end | ||
117 | + assert_passed(test_result) | ||
118 | + end | ||
119 | + | ||
120 | + def test_should_pass_if_method_is_expected_at_least_once_and_is_called_twice | ||
121 | + test_result = run_as_test do | ||
122 | + mock = mock('mock') | ||
123 | + mock.expects(:method).at_least_once | ||
124 | + 2.times { mock.method } | ||
125 | + end | ||
126 | + assert_passed(test_result) | ||
127 | + end | ||
128 | + | ||
129 | + def test_should_fail_if_method_is_expected_at_least_once_but_is_never_called | ||
130 | + test_result = run_as_test do | ||
131 | + mock = mock('mock') | ||
132 | + mock.expects(:method).at_least_once | ||
133 | + 0.times { mock.method } | ||
134 | + end | ||
135 | + assert_failed(test_result) | ||
136 | + assert_equal ["not all expectations were satisfied\nunsatisfied expectations:\n- expected at least once, not yet invoked: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages | ||
137 | + end | ||
138 | + | ||
139 | + def test_should_pass_if_method_is_expected_at_most_once_and_is_never_called | ||
140 | + test_result = run_as_test do | ||
141 | + mock = mock('mock') | ||
142 | + mock.expects(:method).at_most_once | ||
143 | + 0.times { mock.method } | ||
144 | + end | ||
145 | + assert_passed(test_result) | ||
146 | + end | ||
147 | + | ||
148 | + def test_should_pass_if_method_is_expected_at_most_once_and_called_once | ||
149 | + test_result = run_as_test do | ||
150 | + mock = mock('mock') | ||
151 | + mock.expects(:method).at_most_once | ||
152 | + 1.times { mock.method } | ||
153 | + end | ||
154 | + assert_passed(test_result) | ||
155 | + end | ||
156 | + | ||
157 | + def test_should_fail_fast_if_method_is_expected_at_most_once_but_is_called_twice | ||
158 | + test_result = run_as_test do | ||
159 | + mock = mock('mock') | ||
160 | + mock.expects(:method).at_most_once | ||
161 | + 2.times { mock.method } | ||
162 | + end | ||
163 | + assert_failed(test_result) | ||
164 | + assert_equal ["unexpected invocation: #<Mock:mock>.method()\nsatisfied expectations:\n- expected at most once, already invoked once: #<Mock:mock>.method(any_parameters)\n"], test_result.failure_messages | ||
165 | + end | ||
166 | + | ||
167 | + def test_should_pass_if_method_is_never_expected_and_is_never_called_even_if_everything_is_stubbed | ||
168 | + test_result = run_as_test do | ||
169 | + stub = stub_everything('stub') | ||
170 | + stub.expects(:method).never | ||
171 | + 0.times { stub.method } | ||
172 | + end | ||
173 | + assert_passed(test_result) | ||
174 | + end | ||
175 | + | ||
176 | + def test_should_fail_fast_if_method_is_never_expected_but_is_called_once_even_if_everything_is_stubbed | ||
177 | + test_result = run_as_test do | ||
178 | + stub = stub_everything('stub') | ||
179 | + stub.expects(:method).never | ||
180 | + 1.times { stub.method } | ||
181 | + end | ||
182 | + assert_failed(test_result) | ||
183 | + assert_equal ["unexpected invocation: #<Mock:stub>.method()\nsatisfied expectations:\n- expected never, not yet invoked: #<Mock:stub>.method(any_parameters)\n"], test_result.failure_messages | ||
184 | + end | ||
185 | + | ||
186 | + def test_should_fail_fast_if_there_is_no_matching_expectation | ||
187 | + test_result = run_as_test do | ||
188 | + mock = mock('mock') | ||
189 | + mock.expects(:method).with(1) | ||
190 | + 1.times { mock.method } | ||
191 | + end | ||
192 | + assert_failed(test_result) | ||
193 | + assert_equal ["unexpected invocation: #<Mock:mock>.method()\nunsatisfied expectations:\n- expected exactly once, not yet invoked: #<Mock:mock>.method(1)\n"], test_result.failure_messages | ||
194 | + end | ||
195 | + | ||
196 | +end |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/failure_messages_test.rb
0 → 100644
@@ -0,0 +1,64 @@ | @@ -0,0 +1,64 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | +require 'mocha' | ||
3 | + | ||
4 | +class FailureMessagesTest < Test::Unit::TestCase | ||
5 | + | ||
6 | + OBJECT_ADDRESS_PATTERN = '0x[0-9A-Fa-f]{1,12}' | ||
7 | + | ||
8 | + include AcceptanceTest | ||
9 | + | ||
10 | + def setup | ||
11 | + setup_acceptance_test | ||
12 | + end | ||
13 | + | ||
14 | + def teardown | ||
15 | + teardown_acceptance_test | ||
16 | + end | ||
17 | + | ||
18 | + class Foo; end | ||
19 | + | ||
20 | + def test_should_display_class_name_when_expectation_was_on_class | ||
21 | + test_result = run_as_test do | ||
22 | + Foo.expects(:bar) | ||
23 | + end | ||
24 | + assert_match Regexp.new('FailureMessagesTest::Foo'), test_result.failures[0].message | ||
25 | + end | ||
26 | + | ||
27 | + def test_should_display_class_name_and_address_when_expectation_was_on_instance | ||
28 | + test_result = run_as_test do | ||
29 | + Foo.new.expects(:bar) | ||
30 | + end | ||
31 | + assert_match Regexp.new("#<FailureMessagesTest::Foo:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message | ||
32 | + end | ||
33 | + | ||
34 | + def test_should_display_class_name_and_any_instance_prefix_when_expectation_was_on_any_instance | ||
35 | + test_result = run_as_test do | ||
36 | + Foo.any_instance.expects(:bar) | ||
37 | + end | ||
38 | + assert_match Regexp.new('#<AnyInstance:FailureMessagesTest::Foo>'), test_result.failures[0].message | ||
39 | + end | ||
40 | + | ||
41 | + def test_should_display_mock_name_when_expectation_was_on_named_mock | ||
42 | + test_result = run_as_test do | ||
43 | + foo = mock('foo') | ||
44 | + foo.expects(:bar) | ||
45 | + end | ||
46 | + assert_match Regexp.new('#<Mock:foo>'), test_result.failures[0].message | ||
47 | + end | ||
48 | + | ||
49 | + def test_should_display_mock_address_when_expectation_was_on_unnamed_mock | ||
50 | + test_result = run_as_test do | ||
51 | + foo = mock() | ||
52 | + foo.expects(:bar) | ||
53 | + end | ||
54 | + assert_match Regexp.new("#<Mock:#{OBJECT_ADDRESS_PATTERN}>"), test_result.failures[0].message | ||
55 | + end | ||
56 | + | ||
57 | + def test_should_display_string_when_expectation_was_on_string | ||
58 | + test_result = run_as_test do | ||
59 | + 'Foo'.expects(:bar) | ||
60 | + end | ||
61 | + assert_match Regexp.new("'Foo'"), test_result.failures[0].message | ||
62 | + end | ||
63 | + | ||
64 | +end | ||
0 | \ No newline at end of file | 65 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/minitest_test.rb
0 → 100644
@@ -0,0 +1,146 @@ | @@ -0,0 +1,146 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | + | ||
3 | +begin | ||
4 | + require 'minitest/unit' | ||
5 | +rescue LoadError | ||
6 | + # MiniTest not available | ||
7 | +end | ||
8 | + | ||
9 | +# force load so that MiniTest is suitably monkey-patched | ||
10 | +load 'mocha.rb' | ||
11 | + | ||
12 | +if defined?(MiniTest) | ||
13 | + | ||
14 | + class MiniTestSampleTest < MiniTest::Unit::TestCase | ||
15 | + | ||
16 | + def test_mocha_with_fulfilled_expectation | ||
17 | + mockee = mock() | ||
18 | + mockee.expects(:blah) | ||
19 | + mockee.blah | ||
20 | + end | ||
21 | + | ||
22 | + def test_mocha_with_unfulfilled_expectation | ||
23 | + mockee = mock() | ||
24 | + mockee.expects(:blah) | ||
25 | + end | ||
26 | + | ||
27 | + def test_mocha_with_unexpected_invocation | ||
28 | + mockee = mock() | ||
29 | + mockee.blah | ||
30 | + end | ||
31 | + | ||
32 | + def test_stubba_with_fulfilled_expectation | ||
33 | + stubbee = Class.new { define_method(:blah) {} }.new | ||
34 | + stubbee.expects(:blah) | ||
35 | + stubbee.blah | ||
36 | + end | ||
37 | + | ||
38 | + def test_stubba_with_unfulfilled_expectation | ||
39 | + stubbee = Class.new { define_method(:blah) {} }.new | ||
40 | + stubbee.expects(:blah) | ||
41 | + end | ||
42 | + | ||
43 | + def test_mocha_with_matching_parameter | ||
44 | + mockee = mock() | ||
45 | + mockee.expects(:blah).with(has_key(:wibble)) | ||
46 | + mockee.blah(:wibble => 1) | ||
47 | + end | ||
48 | + | ||
49 | + def test_mocha_with_non_matching_parameter | ||
50 | + mockee = mock() | ||
51 | + mockee.expects(:blah).with(has_key(:wibble)) | ||
52 | + mockee.blah(:wobble => 2) | ||
53 | + end | ||
54 | + | ||
55 | + end | ||
56 | + | ||
57 | + class MiniTestTest < Test::Unit::TestCase | ||
58 | + | ||
59 | + def setup | ||
60 | + @output = StringIO.new | ||
61 | + MiniTest::Unit.output = @output | ||
62 | + @runner = MiniTest::Unit.new | ||
63 | + end | ||
64 | + | ||
65 | + attr_reader :runner | ||
66 | + | ||
67 | + def test_should_pass_mocha_test | ||
68 | + runner.run(%w(-n test_mocha_with_fulfilled_expectation)) | ||
69 | + | ||
70 | + assert_equal 0, runner.failures | ||
71 | + assert_equal 0, runner.errors | ||
72 | + assert_equal 1, runner.assertion_count | ||
73 | + end | ||
74 | + | ||
75 | + def test_should_fail_mocha_test_due_to_unfulfilled_expectation | ||
76 | + runner.run(%w(-n test_mocha_with_unfulfilled_expectation)) | ||
77 | + | ||
78 | + assert_equal 1, runner.failures | ||
79 | + assert_equal 0, runner.errors | ||
80 | + assert_equal 1, runner.assertion_count | ||
81 | + assert_not_all_expectation_were_satisfied | ||
82 | + end | ||
83 | + | ||
84 | + def test_should_fail_mocha_test_due_to_unexpected_invocation | ||
85 | + runner.run(%w(-n test_mocha_with_unexpected_invocation)) | ||
86 | + | ||
87 | + assert_equal 1, runner.failures | ||
88 | + assert_equal 0, runner.errors | ||
89 | + assert_equal 0, runner.assertion_count | ||
90 | + assert_unexpected_invocation | ||
91 | + end | ||
92 | + | ||
93 | + def test_should_pass_stubba_test | ||
94 | + runner.run(%w(-n test_stubba_with_fulfilled_expectation)) | ||
95 | + | ||
96 | + assert_equal 0, runner.failures | ||
97 | + assert_equal 0, runner.errors | ||
98 | + assert_equal 1, runner.assertion_count | ||
99 | + end | ||
100 | + | ||
101 | + def test_should_fail_stubba_test_due_to_unfulfilled_expectation | ||
102 | + runner.run(%w(-n test_stubba_with_unfulfilled_expectation)) | ||
103 | + | ||
104 | + assert_equal 1, runner.failures | ||
105 | + assert_equal 0, runner.errors | ||
106 | + assert_equal 1, runner.assertion_count | ||
107 | + assert_not_all_expectation_were_satisfied | ||
108 | + end | ||
109 | + | ||
110 | + def test_should_pass_mocha_test_with_matching_parameter | ||
111 | + runner.run(%w(-n test_mocha_with_matching_parameter)) | ||
112 | + | ||
113 | + assert_equal 0, runner.failures | ||
114 | + assert_equal 0, runner.errors | ||
115 | + assert_equal 1, runner.assertion_count | ||
116 | + end | ||
117 | + | ||
118 | + def test_should_fail_mocha_test_with_non_matching_parameter | ||
119 | + runner.run(%w(-n test_mocha_with_non_matching_parameter)) | ||
120 | + | ||
121 | + assert_equal 1, runner.failures | ||
122 | + assert_equal 0, runner.errors | ||
123 | + assert_equal 0, runner.assertion_count # unexpected invocation occurs before expectation is verified | ||
124 | + assert_unexpected_invocation | ||
125 | + end | ||
126 | + | ||
127 | + private | ||
128 | + | ||
129 | + def output | ||
130 | + @output.rewind | ||
131 | + @output.read | ||
132 | + end | ||
133 | + | ||
134 | + def assert_unexpected_invocation | ||
135 | + assert_match Regexp.new('unexpected invocation'), output, "MiniTest output:\n#{output}" | ||
136 | + end | ||
137 | + | ||
138 | + def assert_not_all_expectation_were_satisfied | ||
139 | + assert_match Regexp.new('not all expectations were satisfied'), output, "MiniTest output:\n#{output}" | ||
140 | + end | ||
141 | + | ||
142 | + end | ||
143 | + | ||
144 | +else | ||
145 | + warn "MiniTest is not available, so MiniTestAdapterTest has not been run." | ||
146 | +end | ||
0 | \ No newline at end of file | 147 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocha_example_test.rb
0 → 100644
@@ -0,0 +1,98 @@ | @@ -0,0 +1,98 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "..", "test_helper") | ||
2 | +require 'mocha' | ||
3 | + | ||
4 | +class MochaExampleTest < Test::Unit::TestCase | ||
5 | + | ||
6 | + class Rover | ||
7 | + | ||
8 | + def initialize(left_track, right_track, steps_per_metre, steps_per_degree) | ||
9 | + @left_track, @right_track, @steps_per_metre, @steps_per_degree = left_track, right_track, steps_per_metre, steps_per_degree | ||
10 | + end | ||
11 | + | ||
12 | + def forward(metres) | ||
13 | + @left_track.step(metres * @steps_per_metre) | ||
14 | + @right_track.step(metres * @steps_per_metre) | ||
15 | + wait | ||
16 | + end | ||
17 | + | ||
18 | + def backward(metres) | ||
19 | + forward(-metres) | ||
20 | + end | ||
21 | + | ||
22 | + def left(degrees) | ||
23 | + @left_track.step(-degrees * @steps_per_degree) | ||
24 | + @right_track.step(+degrees * @steps_per_degree) | ||
25 | + wait | ||
26 | + end | ||
27 | + | ||
28 | + def right(degrees) | ||
29 | + left(-degrees) | ||
30 | + end | ||
31 | + | ||
32 | + def wait | ||
33 | + while (@left_track.moving? or @right_track.moving?); end | ||
34 | + end | ||
35 | + | ||
36 | + end | ||
37 | + | ||
38 | + def test_should_step_both_tracks_forward_ten_steps | ||
39 | + left_track = mock('left_track') | ||
40 | + right_track = mock('right_track') | ||
41 | + steps_per_metre = 5 | ||
42 | + rover = Rover.new(left_track, right_track, steps_per_metre, nil) | ||
43 | + | ||
44 | + left_track.expects(:step).with(10) | ||
45 | + right_track.expects(:step).with(10) | ||
46 | + | ||
47 | + left_track.stubs(:moving?).returns(false) | ||
48 | + right_track.stubs(:moving?).returns(false) | ||
49 | + | ||
50 | + rover.forward(2) | ||
51 | + end | ||
52 | + | ||
53 | + def test_should_step_both_tracks_backward_ten_steps | ||
54 | + left_track = mock('left_track') | ||
55 | + right_track = mock('right_track') | ||
56 | + steps_per_metre = 5 | ||
57 | + rover = Rover.new(left_track, right_track, steps_per_metre, nil) | ||
58 | + | ||
59 | + left_track.expects(:step).with(-10) | ||
60 | + right_track.expects(:step).with(-10) | ||
61 | + | ||
62 | + left_track.stubs(:moving?).returns(false) | ||
63 | + right_track.stubs(:moving?).returns(false) | ||
64 | + | ||
65 | + rover.backward(2) | ||
66 | + end | ||
67 | + | ||
68 | + def test_should_step_left_track_forwards_five_steps_and_right_track_backwards_five_steps | ||
69 | + left_track = mock('left_track') | ||
70 | + right_track = mock('right_track') | ||
71 | + steps_per_degree = 5.0 / 90.0 | ||
72 | + rover = Rover.new(left_track, right_track, nil, steps_per_degree) | ||
73 | + | ||
74 | + left_track.expects(:step).with(+5) | ||
75 | + right_track.expects(:step).with(-5) | ||
76 | + | ||
77 | + left_track.stubs(:moving?).returns(false) | ||
78 | + right_track.stubs(:moving?).returns(false) | ||
79 | + | ||
80 | + rover.right(90) | ||
81 | + end | ||
82 | + | ||
83 | + def test_should_step_left_track_backwards_five_steps_and_right_track_forwards_five_steps | ||
84 | + left_track = mock('left_track') | ||
85 | + right_track = mock('right_track') | ||
86 | + steps_per_degree = 5.0 / 90.0 | ||
87 | + rover = Rover.new(left_track, right_track, nil, steps_per_degree) | ||
88 | + | ||
89 | + left_track.expects(:step).with(-5) | ||
90 | + right_track.expects(:step).with(+5) | ||
91 | + | ||
92 | + left_track.stubs(:moving?).returns(false) | ||
93 | + right_track.stubs(:moving?).returns(false) | ||
94 | + | ||
95 | + rover.left(90) | ||
96 | + end | ||
97 | + | ||
98 | +end | ||
0 | \ No newline at end of file | 99 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocha_test_result_test.rb
0 → 100644
@@ -0,0 +1,84 @@ | @@ -0,0 +1,84 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | +require 'mocha' | ||
3 | +require 'execution_point' | ||
4 | + | ||
5 | +class MochaTestResultTest < Test::Unit::TestCase | ||
6 | + | ||
7 | + include AcceptanceTest | ||
8 | + | ||
9 | + def setup | ||
10 | + setup_acceptance_test | ||
11 | + end | ||
12 | + | ||
13 | + def teardown | ||
14 | + teardown_acceptance_test | ||
15 | + end | ||
16 | + | ||
17 | + def test_should_include_expectation_verification_in_assertion_count | ||
18 | + test_result = run_as_test do | ||
19 | + object = mock() | ||
20 | + object.expects(:message) | ||
21 | + object.message | ||
22 | + end | ||
23 | + assert_equal 1, test_result.assertion_count | ||
24 | + end | ||
25 | + | ||
26 | + def test_should_include_assertions_in_assertion_count | ||
27 | + test_result = run_as_test do | ||
28 | + assert true | ||
29 | + end | ||
30 | + assert_equal 1, test_result.assertion_count | ||
31 | + end | ||
32 | + | ||
33 | + def test_should_not_include_stubbing_expectation_verification_in_assertion_count | ||
34 | + test_result = run_as_test do | ||
35 | + object = mock() | ||
36 | + object.stubs(:message) | ||
37 | + object.message | ||
38 | + end | ||
39 | + assert_equal 0, test_result.assertion_count | ||
40 | + end | ||
41 | + | ||
42 | + def test_should_include_expectation_verification_failure_in_failure_count | ||
43 | + test_result = run_as_test do | ||
44 | + object = mock() | ||
45 | + object.expects(:message) | ||
46 | + end | ||
47 | + assert_equal 1, test_result.failure_count | ||
48 | + end | ||
49 | + | ||
50 | + def test_should_include_unexpected_verification_failure_in_failure_count | ||
51 | + test_result = run_as_test do | ||
52 | + object = mock() | ||
53 | + object.message | ||
54 | + end | ||
55 | + assert_equal 1, test_result.failure_count | ||
56 | + end | ||
57 | + | ||
58 | + def test_should_include_assertion_failure_in_failure_count | ||
59 | + test_result = run_as_test do | ||
60 | + flunk | ||
61 | + end | ||
62 | + assert_equal 1, test_result.failure_count | ||
63 | + end | ||
64 | + | ||
65 | + def test_should_display_backtrace_indicating_line_number_where_unexpected_method_was_called | ||
66 | + execution_point = nil | ||
67 | + test_result = run_as_test do | ||
68 | + object = mock() | ||
69 | + execution_point = ExecutionPoint.current; object.message | ||
70 | + end | ||
71 | + assert_equal 1, test_result.failure_count | ||
72 | + assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location) | ||
73 | + end | ||
74 | + | ||
75 | + def test_should_display_backtrace_indicating_line_number_where_failing_assertion_was_called | ||
76 | + execution_point = nil | ||
77 | + test_result = run_as_test do | ||
78 | + execution_point = ExecutionPoint.current; flunk | ||
79 | + end | ||
80 | + assert_equal 1, test_result.failure_count | ||
81 | + assert_equal execution_point, ExecutionPoint.new(test_result.failures[0].location) | ||
82 | + end | ||
83 | + | ||
84 | +end | ||
0 | \ No newline at end of file | 85 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mock_test.rb
0 → 100644
@@ -0,0 +1,100 @@ | @@ -0,0 +1,100 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | +require 'mocha' | ||
3 | + | ||
4 | +class MockTest < Test::Unit::TestCase | ||
5 | + | ||
6 | + include AcceptanceTest | ||
7 | + | ||
8 | + def setup | ||
9 | + setup_acceptance_test | ||
10 | + end | ||
11 | + | ||
12 | + def teardown | ||
13 | + teardown_acceptance_test | ||
14 | + end | ||
15 | + | ||
16 | + def test_should_build_mock_and_explicitly_add_an_expectation_which_is_satisfied | ||
17 | + test_result = run_as_test do | ||
18 | + foo = mock() | ||
19 | + foo.expects(:bar) | ||
20 | + foo.bar | ||
21 | + end | ||
22 | + assert_passed(test_result) | ||
23 | + end | ||
24 | + | ||
25 | + def test_should_build_mock_and_explicitly_add_an_expectation_which_is_not_satisfied | ||
26 | + test_result = run_as_test do | ||
27 | + foo = mock() | ||
28 | + foo.expects(:bar) | ||
29 | + end | ||
30 | + assert_failed(test_result) | ||
31 | + end | ||
32 | + | ||
33 | + def test_should_build_named_mock_and_explicitly_add_an_expectation_which_is_satisfied | ||
34 | + test_result = run_as_test do | ||
35 | + foo = mock('foo') | ||
36 | + foo.expects(:bar) | ||
37 | + foo.bar | ||
38 | + end | ||
39 | + assert_passed(test_result) | ||
40 | + end | ||
41 | + | ||
42 | + def test_should_build_named_mock_and_explicitly_add_an_expectation_which_is_not_satisfied | ||
43 | + test_result = run_as_test do | ||
44 | + foo = mock('foo') | ||
45 | + foo.expects(:bar) | ||
46 | + end | ||
47 | + assert_failed(test_result) | ||
48 | + end | ||
49 | + | ||
50 | + def test_should_build_mock_incorporating_two_expectations_which_are_satisifed | ||
51 | + test_result = run_as_test do | ||
52 | + foo = mock(:bar => 'bar', :baz => 'baz') | ||
53 | + foo.bar | ||
54 | + foo.baz | ||
55 | + end | ||
56 | + assert_passed(test_result) | ||
57 | + end | ||
58 | + | ||
59 | + def test_should_build_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed | ||
60 | + test_result = run_as_test do | ||
61 | + foo = mock(:bar => 'bar', :baz => 'baz') | ||
62 | + foo.baz | ||
63 | + end | ||
64 | + assert_failed(test_result) | ||
65 | + end | ||
66 | + | ||
67 | + def test_should_build_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed | ||
68 | + test_result = run_as_test do | ||
69 | + foo = mock(:bar => 'bar', :baz => 'baz') | ||
70 | + foo.bar | ||
71 | + end | ||
72 | + assert_failed(test_result) | ||
73 | + end | ||
74 | + | ||
75 | + def test_should_build_named_mock_incorporating_two_expectations_which_are_satisifed | ||
76 | + test_result = run_as_test do | ||
77 | + foo = mock('foo', :bar => 'bar', :baz => 'baz') | ||
78 | + foo.bar | ||
79 | + foo.baz | ||
80 | + end | ||
81 | + assert_passed(test_result) | ||
82 | + end | ||
83 | + | ||
84 | + def test_should_build_named_mock_incorporating_two_expectations_the_first_of_which_is_not_satisifed | ||
85 | + test_result = run_as_test do | ||
86 | + foo = mock('foo', :bar => 'bar', :baz => 'baz') | ||
87 | + foo.baz | ||
88 | + end | ||
89 | + assert_failed(test_result) | ||
90 | + end | ||
91 | + | ||
92 | + def test_should_build_named_mock_incorporating_two_expectations_the_second_of_which_is_not_satisifed | ||
93 | + test_result = run_as_test do | ||
94 | + foo = mock('foo', :bar => 'bar', :baz => 'baz') | ||
95 | + foo.bar | ||
96 | + end | ||
97 | + assert_failed(test_result) | ||
98 | + end | ||
99 | + | ||
100 | +end | ||
0 | \ No newline at end of file | 101 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mock_with_initializer_block_test.rb
0 → 100644
@@ -0,0 +1,51 @@ | @@ -0,0 +1,51 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | +require 'mocha' | ||
3 | + | ||
4 | +class MockWithInitializerBlockTest < Test::Unit::TestCase | ||
5 | + | ||
6 | + include AcceptanceTest | ||
7 | + | ||
8 | + def setup | ||
9 | + setup_acceptance_test | ||
10 | + end | ||
11 | + | ||
12 | + def teardown | ||
13 | + teardown_acceptance_test | ||
14 | + end | ||
15 | + | ||
16 | + def test_should_expect_two_method_invocations_and_receive_both_of_them | ||
17 | + test_result = run_as_test do | ||
18 | + mock = mock() do | ||
19 | + expects(:method_1) | ||
20 | + expects(:method_2) | ||
21 | + end | ||
22 | + mock.method_1 | ||
23 | + mock.method_2 | ||
24 | + end | ||
25 | + assert_passed(test_result) | ||
26 | + end | ||
27 | + | ||
28 | + def test_should_expect_two_method_invocations_but_receive_only_one_of_them | ||
29 | + test_result = run_as_test do | ||
30 | + mock = mock() do | ||
31 | + expects(:method_1) | ||
32 | + expects(:method_2) | ||
33 | + end | ||
34 | + mock.method_1 | ||
35 | + end | ||
36 | + assert_failed(test_result) | ||
37 | + end | ||
38 | + | ||
39 | + def test_should_stub_methods | ||
40 | + test_result = run_as_test do | ||
41 | + mock = mock() do | ||
42 | + stubs(:method_1).returns(1) | ||
43 | + stubs(:method_2).returns(2) | ||
44 | + end | ||
45 | + assert_equal 1, mock.method_1 | ||
46 | + assert_equal 2, mock.method_2 | ||
47 | + end | ||
48 | + assert_passed(test_result) | ||
49 | + end | ||
50 | + | ||
51 | +end | ||
0 | \ No newline at end of file | 52 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/mocked_methods_dispatch_test.rb
0 → 100644
@@ -0,0 +1,78 @@ | @@ -0,0 +1,78 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | +require 'mocha' | ||
3 | + | ||
4 | +class MockedMethodDispatchTest < Test::Unit::TestCase | ||
5 | + | ||
6 | + include AcceptanceTest | ||
7 | + | ||
8 | + def setup | ||
9 | + setup_acceptance_test | ||
10 | + end | ||
11 | + | ||
12 | + def teardown | ||
13 | + teardown_acceptance_test | ||
14 | + end | ||
15 | + | ||
16 | + def test_should_find_latest_matching_expectation | ||
17 | + test_result = run_as_test do | ||
18 | + mock = mock() | ||
19 | + mock.stubs(:method).returns(1) | ||
20 | + mock.stubs(:method).returns(2) | ||
21 | + assert_equal 2, mock.method | ||
22 | + assert_equal 2, mock.method | ||
23 | + assert_equal 2, mock.method | ||
24 | + end | ||
25 | + assert_passed(test_result) | ||
26 | + end | ||
27 | + | ||
28 | + def test_should_find_latest_expectation_which_has_not_stopped_matching | ||
29 | + test_result = run_as_test do | ||
30 | + mock = mock() | ||
31 | + mock.stubs(:method).returns(1) | ||
32 | + mock.stubs(:method).once.returns(2) | ||
33 | + assert_equal 2, mock.method | ||
34 | + assert_equal 1, mock.method | ||
35 | + assert_equal 1, mock.method | ||
36 | + end | ||
37 | + assert_passed(test_result) | ||
38 | + end | ||
39 | + | ||
40 | + def test_should_keep_finding_later_stub_and_so_never_satisfy_earlier_expectation | ||
41 | + test_result = run_as_test do | ||
42 | + mock = mock() | ||
43 | + mock.expects(:method).returns(1) | ||
44 | + mock.stubs(:method).returns(2) | ||
45 | + assert_equal 2, mock.method | ||
46 | + assert_equal 2, mock.method | ||
47 | + assert_equal 2, mock.method | ||
48 | + end | ||
49 | + assert_failed(test_result) | ||
50 | + end | ||
51 | + | ||
52 | + def test_should_find_later_expectation_until_it_stops_matching_then_find_earlier_stub | ||
53 | + test_result = run_as_test do | ||
54 | + mock = mock() | ||
55 | + mock.stubs(:method).returns(1) | ||
56 | + mock.expects(:method).returns(2) | ||
57 | + assert_equal 2, mock.method | ||
58 | + assert_equal 1, mock.method | ||
59 | + assert_equal 1, mock.method | ||
60 | + end | ||
61 | + assert_passed(test_result) | ||
62 | + end | ||
63 | + | ||
64 | + def test_should_find_latest_expectation_with_range_of_expected_invocation_count_which_has_not_stopped_matching | ||
65 | + test_result = run_as_test do | ||
66 | + mock = mock() | ||
67 | + mock.stubs(:method).returns(1) | ||
68 | + mock.stubs(:method).times(2..3).returns(2) | ||
69 | + assert_equal 2, mock.method | ||
70 | + assert_equal 2, mock.method | ||
71 | + assert_equal 2, mock.method | ||
72 | + assert_equal 1, mock.method | ||
73 | + assert_equal 1, mock.method | ||
74 | + end | ||
75 | + assert_passed(test_result) | ||
76 | + end | ||
77 | + | ||
78 | +end | ||
0 | \ No newline at end of file | 79 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/optional_parameters_test.rb
0 → 100644
@@ -0,0 +1,70 @@ | @@ -0,0 +1,70 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | +require 'mocha' | ||
3 | + | ||
4 | +class OptionalParameterMatcherTest < Test::Unit::TestCase | ||
5 | + | ||
6 | + include AcceptanceTest | ||
7 | + | ||
8 | + def setup | ||
9 | + setup_acceptance_test | ||
10 | + end | ||
11 | + | ||
12 | + def teardown | ||
13 | + teardown_acceptance_test | ||
14 | + end | ||
15 | + | ||
16 | + def test_should_pass_if_all_required_parameters_match_and_no_optional_parameters_are_supplied | ||
17 | + test_result = run_as_test do | ||
18 | + mock = mock() | ||
19 | + mock.expects(:method).with(1, 2, optionally(3, 4)) | ||
20 | + mock.method(1, 2) | ||
21 | + end | ||
22 | + assert_passed(test_result) | ||
23 | + end | ||
24 | + | ||
25 | + def test_should_pass_if_all_required_and_optional_parameters_match_and_some_optional_parameters_are_supplied | ||
26 | + test_result = run_as_test do | ||
27 | + mock = mock() | ||
28 | + mock.expects(:method).with(1, 2, optionally(3, 4)) | ||
29 | + mock.method(1, 2, 3) | ||
30 | + end | ||
31 | + assert_passed(test_result) | ||
32 | + end | ||
33 | + | ||
34 | + def test_should_pass_if_all_required_and_optional_parameters_match_and_all_optional_parameters_are_supplied | ||
35 | + test_result = run_as_test do | ||
36 | + mock = mock() | ||
37 | + mock.expects(:method).with(1, 2, optionally(3, 4)) | ||
38 | + mock.method(1, 2, 3, 4) | ||
39 | + end | ||
40 | + assert_passed(test_result) | ||
41 | + end | ||
42 | + | ||
43 | + def test_should_fail_if_all_required_and_optional_parameters_match_but_too_many_optional_parameters_are_supplied | ||
44 | + test_result = run_as_test do | ||
45 | + mock = mock() | ||
46 | + mock.expects(:method).with(1, 2, optionally(3, 4)) | ||
47 | + mock.method(1, 2, 3, 4, 5) | ||
48 | + end | ||
49 | + assert_failed(test_result) | ||
50 | + end | ||
51 | + | ||
52 | + def test_should_fail_if_all_required_parameters_match_but_some_optional_parameters_do_not_match | ||
53 | + test_result = run_as_test do | ||
54 | + mock = mock() | ||
55 | + mock.expects(:method).with(1, 2, optionally(3, 4)) | ||
56 | + mock.method(1, 2, 4) | ||
57 | + end | ||
58 | + assert_failed(test_result) | ||
59 | + end | ||
60 | + | ||
61 | + def test_should_fail_if_all_required_parameters_match_but_no_optional_parameters_match | ||
62 | + test_result = run_as_test do | ||
63 | + mock = mock() | ||
64 | + mock.expects(:method).with(1, 2, optionally(3, 4)) | ||
65 | + mock.method(1, 2, 4, 5) | ||
66 | + end | ||
67 | + assert_failed(test_result) | ||
68 | + end | ||
69 | + | ||
70 | +end | ||
0 | \ No newline at end of file | 71 | \ No newline at end of file |
vendor/gems/jferris-mocha-0.9.5.0.1241126838/test/acceptance/parameter_matcher_test.rb
0 → 100644
@@ -0,0 +1,209 @@ | @@ -0,0 +1,209 @@ | ||
1 | +require File.join(File.dirname(__FILE__), "acceptance_test_helper") | ||
2 | +require 'mocha' | ||
3 | + | ||
4 | +class ParameterMatcherTest < Test::Unit::TestCase | ||
5 | + | ||
6 | + include AcceptanceTest | ||
7 | + | ||
8 | + def setup | ||
9 | + setup_acceptance_test | ||
10 | + end | ||
11 | + | ||
12 | + def teardown | ||
13 | + teardown_acceptance_test | ||
14 | + end | ||
15 | + | ||
16 | + def test_should_match_hash_parameter_with_specified_key | ||
17 | + test_result = run_as_test do | ||
18 | + mock = mock() | ||
19 | + mock.expects(:method).with(has_key(:key_1)) | ||
20 | + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') | ||
21 | + end | ||
22 | + assert_passed(test_result) | ||
23 | + end | ||
24 | + | ||
25 | + def test_should_not_match_hash_parameter_with_specified_key | ||
26 | + test_result = run_as_test do | ||
27 | + mock = mock() | ||
28 | + mock.expects(:method).with(has_key(:key_1)) | ||
29 | + mock.method(:key_2 => 'value_2') | ||
30 | + end | ||
31 | + assert_failed(test_result) | ||
32 | + end | ||
33 | + | ||
34 | + def test_should_match_hash_parameter_with_specified_value | ||
35 | + test_result = run_as_test do | ||
36 | + mock = mock() | ||
37 | + mock.expects(:method).with(has_value('value_1')) | ||
38 | + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') | ||
39 | + end | ||
40 | + assert_passed(test_result) | ||
41 | + end | ||
42 | + | ||
43 | + def test_should_not_match_hash_parameter_with_specified_value | ||
44 | + test_result = run_as_test do | ||
45 | + mock = mock() | ||
46 | + mock.expects(:method).with(has_value('value_1')) | ||
47 | + mock.method(:key_2 => 'value_2') | ||
48 | + end | ||
49 | + assert_failed(test_result) | ||
50 | + end | ||
51 | + | ||
52 | + def test_should_match_hash_parameter_with_specified_key_value_pair | ||
53 | + test_result = run_as_test do | ||
54 | + mock = mock() | ||
55 | + mock.expects(:method).with(has_entry(:key_1, 'value_1')) | ||
56 | + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') | ||
57 | + end | ||
58 | + assert_passed(test_result) | ||
59 | + end | ||
60 | + | ||
61 | + def test_should_not_match_hash_parameter_with_specified_key_value_pair | ||
62 | + test_result = run_as_test do | ||
63 | + mock = mock() | ||
64 | + mock.expects(:method).with(has_entry(:key_1, 'value_2')) | ||
65 | + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') | ||
66 | + end | ||
67 | + assert_failed(test_result) | ||
68 | + end | ||
69 | + | ||
70 | + def test_should_match_hash_parameter_with_specified_hash_entry | ||
71 | + test_result = run_as_test do | ||
72 | + mock = mock() | ||
73 | + mock.expects(:method).with(has_entry(:key_1 => 'value_1')) | ||
74 | + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') | ||
75 | + end | ||
76 | + assert_passed(test_result) | ||
77 | + end | ||
78 | + | ||
79 | + def test_should_not_match_hash_parameter_with_specified_hash_entry | ||
80 | + test_result = run_as_test do | ||
81 | + mock = mock() | ||
82 | + mock.expects(:method).with(has_entry(:key_1 => 'value_2')) | ||
83 | + mock.method(:key_1 => 'value_1', :key_2 => 'value_2') | ||
84 | + end | ||
85 | + assert_failed(test_result) | ||
86 | + end | ||
87 | + | ||
88 | + def test_should_match_hash_parameter_with_specified_entries | ||
89 | + test_result = run_as_test do | ||
90 | + mock = mock() | ||
91 | + mock.expects(:method).with(has_entries(:key_1 => 'value_1', :key_2 => 'value_2')) | ||
92 | + mock.method(:key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3') | ||
93 | + end | ||
94 | + assert_passed(test_result) | ||
95 | + end | ||
96 | + | ||
97 | + def test_should_not_match_hash_parameter_with_specified_entries | ||
98 | + test_result = run_as_test do | ||
99 | + mock = mock() | ||
100 | + mock.expects(:method).with(has_entries(:key_1 => 'value_1', :key_2 => 'value_2')) | ||
101 | + mock.method(:key_1 => 'value_1', :key_2 => 'value_3') | ||
102 | + end | ||
103 | + assert_failed(test_result) | ||
104 | + end | ||
105 | + | ||
106 | + def test_should_match_parameter_that_matches_regular_expression | ||
107 | + test_result = run_as_test do | ||
108 | + mock = mock() | ||
109 | + mock.expects(:method).with(regexp_matches(/meter/)) | ||
110 | + mock.method('this parameter should match') | ||
111 | + end | ||
112 | + assert_passed(test_result) | ||
113 | + end | ||
114 | + | ||
115 | + def test_should_not_match_parameter_that_does_not_match_regular_expression | ||
116 | + test_result = run_as_test do | ||
117 | + mock = mock() | ||
118 | + mock.expects(:method).with(regexp_matches(/something different/)) | ||
119 | + mock.method('this parameter should not match') | ||
120 | + end | ||
121 | + assert_failed(test_result) | ||
122 | + end | ||
123 | + | ||
124 | + def test_should_match_hash_parameter_with_specified_entries_using_nested_matchers | ||
125 | + test_result = run_as_test do | ||
126 | + mock = mock() | ||
127 | + mock.expects(:method).with(has_entries(:key_1 => regexp_matches(/value_1/), kind_of(Symbol) => 'value_2')) | ||
128 | + mock.method(:key_1 => 'value_1', :key_2 => 'value_2', :key_3 => 'value_3') | ||
129 | + end | ||
130 | + assert_passed(test_result) | ||
131 | + end | ||
132 | + | ||
133 | + def test_should_not_match_hash_parameter_with_specified_entries_using_nested_matchers | ||
134 | + test_result = run_as_test do | ||
135 | + mock = mock() | ||
136 | + mock.expects(:method).with(has_entries(:key_1 => regexp_matches(/value_1/), kind_of(String) => 'value_2')) | ||
137 | + mock.method(:key_1 => 'value_2', :key_2 => 'value_3') | ||
138 | + end | ||
139 | + assert_failed(test_result) | ||
140 | + end | ||
141 | + | ||
142 | + def test_should_match_parameter_that_matches_any_value | ||
143 | + test_result = run_as_test do | ||
144 | + mock = mock() | ||
145 | + mock.expects(:method).with(any_of('value_1', 'value_2')).times(2) | ||
146 | + mock.method('value_1') | ||
147 | + mock.method('value_2') | ||
148 | + end | ||
149 | + assert_passed(test_result) | ||
150 | + end | ||
151 | + | ||
152 | + def test_should_not_match_parameter_that_does_not_match_any_value | ||
153 | + test_result = run_as_test do | ||
154 | + mock = mock() | ||
155 | + mock.expects(:method).with(any_of('value_1', 'value_2')) | ||
156 | + mock.method('value_3') | ||
157 | + end | ||
158 | + assert_failed(test_result) | ||
159 | + end | ||
160 | + | ||
161 | + def test_should_match_parameter_that_matches_all_values | ||
162 | + test_result = run_as_test do | ||
163 | + mock = mock() | ||
164 | + mock.expects(:method).with(all_of('value_1', 'value_1')) | ||
165 | + mock.method('value_1') | ||
166 | + end | ||
167 | + assert_passed(test_result) | ||
168 | + end | ||
169 | + | ||
170 | + def test_should_not_match_parameter_that_does_not_match_all_values | ||
171 | + test_result = run_as_test do | ||
172 | + mock = mock() | ||
173 | + mock.expects(:method).with(all_of('value_1', 'value_2')) | ||
174 | + mock.method('value_1') | ||
175 | + end | ||
176 | + assert_failed(test_result) | ||
177 | + end | ||
178 | + | ||
179 | + def test_should_match_parameter_that_responds_with_specified_value | ||
180 | + klass = Class.new do | ||
181 | + def quack | ||
182 | + 'quack' | ||
183 | + end | ||
184 | + end | ||
185 | + duck = klass.new | ||
186 | + test_result = run_as_test do | ||
187 | + mock = mock() | ||
188 | + mock.expects(:method).with(responds_with(:quack, 'quack')) | ||
189 | + mock.method(duck) | ||
190 | + end | ||
191 | + assert_passed(test_result) | ||
192 | + end | ||
193 | + | ||
194 | + def test_should_not_match_parameter_that_does_not_respond_with_specified_value | ||
195 | + klass = Class.new do | ||
196 | + def quack | ||
197 | + 'woof' | ||
198 | + end | ||
199 | + end | ||
200 | + duck = klass.new | ||
201 | + test_result = run_as_test do | ||
202 | + mock = mock() | ||
203 | + mock.expects(:method).with(responds_with(:quack, 'quack')) | ||
204 | + mock.method(duck) | ||
205 | + end | ||
206 | + assert_failed(test_result) | ||
207 | + end | ||
208 | + | ||
209 | +end |