加藤 和良 > Test-Mock-Recorder > Test::Mock::Recorder

Download:
Test-Mock-Recorder-0.01.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 0.01   Source  

NAME ^

Test::Mock::Recorder - Record-and-verify style mocking library.

SYNOPSIS ^

  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);

DESCRIPTION ^

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.

CLASS METHODS ^

new()

Constructor.

INSTANCE METHODS ^

expects($method)

Append exceptation of calling method named $method and returns new Test::Mock::Recorder::Expectation instance.

expects($method1 => $ret1, $method2 => $ret2, ...)

Short-form of one-argument "expects" method.

replay(), replay($callback)

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)

Verify $mock and returns true when success.

verify_ok($callback), verify_ok($mock)

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.

DESIGN ^

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.

Need to call "replay" method but it returns object

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.

Need to call "excepts", not AUTOLOAD hack

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

AUTHOR ^

Kato Kazuyoshi <kato.kazuyoshi@gmail.com>

LICENSE ^

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

SEE ALSO ^

Test::Expectation

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.

Test::Mock::Class

http://search.cpan.org/dist/Test-Mock-Class/

Test::Mock::Class provides record style interface (mock_invoke, mock_return, ...) but it depends Moose!

Mox

http://code.google.com/p/pymox/

Mocha

http://mocha.rubyforge.org/

Test Double

http://xunitpatterns.com/Test%20Double.html

syntax highlighting: