Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alindeman/mock_proc
https://github.com/alindeman/mock_proc
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/alindeman/mock_proc
- Owner: alindeman
- License: mit
- Created: 2012-05-29T19:06:55.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-05-29T19:28:43.000Z (over 12 years ago)
- Last Synced: 2024-11-18T01:43:01.722Z (about 1 month ago)
- Language: Ruby
- Size: 97.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MockProc
[![Build Status](https://secure.travis-ci.org/alindeman/mock_proc.png)](http://travis-ci.org/alindeman/mock_proc)
An attempt to create a mock `Proc` object, so expectations can be set on how
it is called.Ideal for testing callbacks; alternatives are discussed in [Avdi's blog
post](http://devblog.avdi.org/2011/12/12/testing-that-a-block-is-called/).`mock_proc` is meant to plug into other mocking libraries. Right now it
supports rspec-mocks.## rspec-mocks
```ruby
describe MockProc do
it "expects an exact number of calls" do
block = MockProc.new
block.should_be_called.twice2.times { block.call }
end
end
```You can use all of the same predicates you expect:
```ruby
describe MockProc do
it "expects arguments" do
block = MockProc.new
block.should_be_called.with(:foo)block.call(:foo)
end
end
```It works any way you invoke the block:
```ruby
describe MockProc do
it "allows all methods that invoke a block" do
block = MockProc.new
block.should_be_called.exactly(2).timesblock[:foo]
block === :foo
end
end
```## TODO
* Other mocking frameworks: mocha, ...?