Created
February 8, 2012 11:48
-
-
Save tatey/1768472 to your computer and use it in GitHub Desktop.
SimpleMock
This file contains hidden or 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
| # Inspired by "Mocking with MiniTest::Mock and SimpleDelegator" it would be | |
| # great to have a library with no dependancies that gives you the behaviour | |
| # talked about in the blog post without learning a new API. | |
| # http://tatey.com/2012/02/07/mocking-with-minitest-mock-and-simple-delegator/ | |
| # Without an argument, SimpleMock behaves identically to MiniTest::Mock.new | |
| mock = SimpleMock.new | |
| mock.expect :valid?, false | |
| mock.valid? # => false | |
| mock.save # => NoMethodError | |
| # With an argument, SimpleMock instantiates an anonymous class that inherits from SimpleDelegate. | |
| # Except for expectations, all methods are forwarded to the delegate. | |
| mock = SimpleMock.new Post.new | |
| mock.expect :valid?, false | |
| mock.valid? # => false | |
| mock.save # => false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment