Skip to content

Instantly share code, notes, and snippets.

@tatey
Created February 8, 2012 11:48
Show Gist options
  • Select an option

  • Save tatey/1768472 to your computer and use it in GitHub Desktop.

Select an option

Save tatey/1768472 to your computer and use it in GitHub Desktop.
SimpleMock
# 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