Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Test::Double is a Perl extension for Test Double. See: http://xunitpatterns.com/Test%20Double.html
Perl
branch: master

Checking in changes prior to tagging of version 0.05.

Changelog diff is:

diff --git a/Changes b/Changes
index c228d29..48323e7 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,9 @@
 Revision history for Perl extension Test::Double

+0.05
+        - added at_least, at_most, times, and with for mock expectation (ka2u)
+        - added verify, verify_result, and reset methods (ka2u)
+
 0.04
         - remove Test::Flatten dependency
         - mentioned Test::Stub
latest commit 64b790cb7e
@masaki authored

README.pod

NAME

Test::Double - Perl extension for Test Double.

SYNOPSIS

  package Foo;
  sub new { bless {}, shift }
  sub bar { 'bar' }
  
  # in your tests
  use Test::More;
  use Test::Double;
  
  my $foo = Foo->new;
  is $foo->bar, 'bar', 'bar() returns "bar"';
  
  # stub out
  stub($foo)->bar('BAR');
  is $foo->bar, 'BAR', 'stubbed bar() returns "BAR"';
  
  # mock out
  mock($foo)->expects('bar')->at_most(2)->returns('BAR');
  is $foo->bar, 'BAR', 'mocked bar() returns "BAR"';

  my $result = Test::Double->verify_result;
  ok $result->{bar}->{at_most};

  Test::Double->verify;
  Test::Double->reset;
  
  done_testing;

DESCRIPTION

Test::Double is a Perl extension for Test Double.

METHODS

stub($object)

Returns stub object. This object accepts any methods for stubbing using AUTOLOAD mechanism.

  stub($object)->some_method($expected_value);
  # after, $object->some_method() returns $expected_value

See http://xunitpatterns.com/Test%20Stub.html

mock($object)

Returns mock object. This object can be defined expectation by calling expects() method.

  mock($object)->expects('some_method');
  # after, $object->some_method() returns $expected_value

See Test::Double::Mock

verify

Verify how many times method calling, and method calling with what args.

verify_result

Returns verified result.

  my $result = Test::Double->verify_result;
  $result->{some_method}->{at_least};
  # result->{what method}->{what expectation}
reset

Reset mocking objects.

AUTHOR

NAKAGAWA Masaki <masaki@cpan.org>

LICENSE

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

SEE ALSO

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

Test::Stub, Class::Monadic

Something went wrong with that request. Please try again.