Stolen from the readme
package Love;
sub new {
return bless {}, Love;
}
sub marry {
my $self = shift;
my $user1 = shift;
my $user2 = shift;
my $db_object = $self->{'db_object'};
if ( $db_object->is_married($user1) == 0
&& $db_object->is_married($user2) == 0 )
{
$db_object->marry( $user1, $user2 );
$db_object->marry( $user2, $user1 );
return 1;
}
return 0;
}
package MyDbClass;
sub is_married {
# do some complicated stuff
}
sub marry {
# do some other complicated stuff
}
#Our test can be
use Test::Pockito;
use Test::Simple;
my $pocket = Test::Pockito->new("MyNamespace");
my $db_mock = $pocket->mock("MyDbClass");
$pocket->when( $db_mock->is_married("bob") )->then(0);
$pocket->when( $db_mock->is_married("alice") )->then(0);
$pocket->when( $db_mock->marry( "alice", "bob" ) )->then();
$pocket->when( $db_mock->marry( "bob", "alice" ) )->then();
my $target = Love->new();
$target->{'db_object'} = $db_mock;
ok( $target->marry( "bob", "alice" ) == 1,
"single to married == success!" );
ok( scalar keys %{ $pocket->expected_calls } == 0,
"No extra cruft calls, huzzah!" );
An easy improvement would be to have a count_expected_calls_outstanding or something silly, but it's a first release. :)
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|