An opinionated implementation of the Command pattern for Ruby applications. Cuprum wraps your business logic in a consistent, object-oriented interface and features status and error management, composability and control flow management.
Instruments calls to the #call method of any instance of a command class.
This can be used to unobtrusively test the functionality of code that calls a command without providing a reference to the command instance, such methods that create and call a command instance.
Observing calls to instances of a command.
spy = Cuprum::Utils::InstanceSpy.spy_on(CustomCommand)
allow(spy).to receive(:call)
CustomCommand.new.call(1, 2, 3, :four => '4')
expect(spy).to have_received(:call).with(1, 2, 3, :four => '4')Block syntax
Cuprum::Utils::InstanceSpy.spy_on(CustomCommand) do |spy|
allow(spy).to receive(:call)
CustomCommand.new.call
expect(spy).to have_received(:call)
end.clear_spies => Object
Retires all spies.
Subsequent calls to the #call method on command instances will not be mirrored to existing spy objects.
.spy_on(command_class) => Cuprum::Utils::InstanceSpy::Spy.spy_on(command_class, &block) => nilNote: Calling this method for the first time will prepend the Cuprum::Utils::InstanceSpy module to Cuprum::Command.
Finds or creates a spy object for the given module or class.
Each time that the #call method is called for an object of the given type, the spy’s #call method will be invoked with the same arguments and block.
.spy_on(command_class) => Cuprum::Utils::InstanceSpy::Spy
.spy_on(command_class, &block) => nil
Yields the instance spy to the block, and returns nil.
#call(*arguments, **keywords, &block) => Cuprum::Result
Executes the command and returns a Cuprum::Result or compatible object.
Each time #call is invoked, the object performs the following steps:
Back to Documentation | Versions | 1.3 | Reference | Cuprum | Cuprum::Utils