Caricature - Bringing simple mocking to the DLR
This project aims to make interop between IronRuby objects and .NET objects easier. The idea is that it integrates nicely with bacon and later rspec and that it transparently lets you mock ironruby ojbects as well as CLR objects/interfaces. Caricature handles interfaces, interface inheritance, CLR objects, CLR object instances, Ruby classes and instances of Ruby classes.
From the start I wanted to do away with names like mock, stub, record, replay, verify etc. Instead I took the advice from Roy Osherhove and went with a name of Isolation for creating a mock.
An Isolation will create what in Rhino.Mocks would be called a DynamicMock (but can be a partial too) :) In Moq it would be the Loose mocking strategy.
The naming of the methods for creating mocks is the one that JP Boodhoo proposed WhenToldTo and WasToldTo. To specify a stub/expectation on an isolation you have one and only one way of doing that with the method called when_receiving. Then only if you’re interested in asserting if a method has been called you can use the did_receive? method for this.
isolation = Isolation.for(Ninja) isolation.when_receiving(:attack) do |exp| exp.with(:shuriken) exp.return(3) end Battle.new(mock) battle.combat isolation.did_receive?(:attack).should.be.true?
It may be very important to note that when you’re going to be isolating CLR classes to be used in other CLR classes you still need to obide by the CLR rules. That means if you want to redefine a method you’ll need to make sure it’s marked as virtual. Static types are still governed by static type rules. I’m working on a solution around those problems but for the time being this is how it has to be.
The context for an isolator. This contains the subject, recorder, expectations and messenger
Mock is a synonym for Isolation so you can still use it if you’re that way inclined
Stub is a synonym for Isolation so you can still use it if you’re that way inclined
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.