Test::Mock::Recorder - Record-and-verify style mocking library.
my $rec = Test::Mock::Recorder->new; $rec->expects('print')->with('hello'); $rec->verify_ok( sub { my $io = shift; $io->print('hello'); } ); # If you don't like callback-style interface... my $io = $rec->replay; $io->print('hello'); $rec->verify_ok($io);
Test::Mock::Recorder is a record-and-verify style mocking library.
It wraps Test::MockObject and provides functionality of testing a sequence of method calls.
Constructor.
Append exceptation of calling method named $method and returns new Test::Mock::Recorder::Expectation instance.
Short-form of one-argument "expects" method.
Creates new mock object and pass it.
Without $callback, the method returns new mock object.
With $callback, the method pass a new mock to $callback and verify, returns the result of verification.
Verify $mock and returns true when success.
Verify and call Test::Builder's ok.
With $callback (code reference), the method calls $callback with new mock object.
With $mock (not code reference), the method just verify $mock.
Test::Mock::Recorder is heavily inspired from other language's mock library especially Mox (Python) and Mocha (Ruby).
But it has a little different interface.
Mocha don't need to call "replay" method. But the interface need to reserve some method name such as "expects".
Mox need to call "replay" but it switch pre-created instances. The interface is not straightforward.
Mox has AUTOLOAD-style interface. But the interface need to reserve some method name too. And "Comparator" is difficult to learn I think. http://code.google.com/p/pymox/wiki/MoxDocumentation#Comparators
Kato Kazuyoshi <kato.kazuyoshi@gmail.com>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
http://search.cpan.org/dist/Test-Expectation/
Test::Expectation provides record style interface (expects, with, to_return, ...) but it provides RSpec like interface (it_is_a, it_should, ...) too.
http://search.cpan.org/dist/Test-Mock-Class/
Test::Mock::Class provides record style interface (mock_invoke, mock_return, ...) but it depends Moose!
http://code.google.com/p/pymox/
http://mocha.rubyforge.org/
http://xunitpatterns.com/Test%20Double.html
To install Test::Mock::Recorder, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Mock::Recorder
CPAN shell
perl -MCPAN -e shell install Test::Mock::Recorder
For more information on module installation, please visit the detailed CPAN module installation guide.