Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Cainã Costa
committed
Oct 8, 2011
1 parent
4a5818e
commit 5af1fe3
Showing
1 changed file
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
MiniTest::FireMock | ||
================== | ||
|
||
This gem was designed do make isolated tests more resilient. In isolated tests, a FireMock is no different than a common mock. The only difference is when the test is called on a not-isolated environment. It checks for the presence of the method on the mocked class, and fails if it isn't there. This adds another layer of security for suit tests, without compromising the isolation of unit tests. | ||
|
||
It's based on the awesome [rspec-fire](https://github.com/xaviershay/rspec-fire) from [Xavier Shay](http://xaviershay.com/). | ||
|
||
Usage | ||
----- | ||
|
||
```ruby | ||
require 'minitest/autorun' | ||
require 'minitest/fire_mock' | ||
|
||
class MyClass | ||
def my_method | ||
# actual_work goes here | ||
end | ||
end | ||
|
||
class MyOtherClassTest < MiniTest::Unit::TestCase | ||
def test_for_correctness | ||
mock = MiniTest::FireMock('MyClass') | ||
mock.expect(:my_method, 42) | ||
assert_equal 42, mock.my_method | ||
mock.verify | ||
end | ||
end | ||
``` | ||
|
||
The only real difference of using `MiniTest::FireMock` instead of `MiniTest::Mock` is that if `MyClass` is defined, and `my_method` isn't there, it'll raise a `MockExpectationError`. | ||
|
||
TODO | ||
---- | ||
|
||
- Check for the arity of the methods if they are defined. | ||
- Mock class/module methods too. | ||
- Make it work with method_missing (as of now it doesn't, even if the #responds_to? is correct) |