Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cfcosta/minitest-firemock
Makes your MiniTest mocks more resilient.
https://github.com/cfcosta/minitest-firemock
Last synced: 25 days ago
JSON representation
Makes your MiniTest mocks more resilient.
- Host: GitHub
- URL: https://github.com/cfcosta/minitest-firemock
- Owner: cfcosta
- Created: 2011-10-08T22:01:22.000Z (about 13 years ago)
- Default Branch: master
- Last Pushed: 2015-04-23T04:14:56.000Z (over 9 years ago)
- Last Synced: 2024-10-09T17:54:56.063Z (about 1 month ago)
- Language: Ruby
- Homepage:
- Size: 251 KB
- Stars: 30
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
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/).
[![Build Status](https://travis-ci.org/cfcosta/minitest-firemock.svg?branch=master)](https://travis-ci.org/cfcosta/minitest-firemock)
Usage
-----```ruby
require 'minitest/autorun'
require 'minitest/fire_mock'class MyClass
def my_method
# actual_work goes here
end
endclass MyOtherClassTest < MiniTest::Unit::TestCase
def test_for_correctness
mock = MiniTest::FireMock.new('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`. It checks also for the arity of the method, so it'll raise a `MockExpectationError` if the real method have a different arity than the expectation.
TODO
----- Mock class/module methods too.
- Make it work with method_missing (as of now it doesn't, even if the #responds_to? is correct)