Permalink
Browse files

Implement optional way to specify fake data to return from a mock.

  • Loading branch information...
1 parent 6ec9104 commit 2c9739ccc66e36407eca2e0122db88381524cc9a @jnthn committed Jul 16, 2010
Showing with 4 additions and 1 deletion.
  1. +4 −1 lib/Test/Mock.pm
View
@@ -37,7 +37,7 @@ class Test::Mock::Log {
};
module Test::Mock {
- sub mocked($type) is export {
+ sub mocked($type, :%returning = {}) is export {
# Generate a subclass that logs each method call.
my %already-seen = :new;
my $mocker = ClassHOW.new;
@@ -48,6 +48,9 @@ module Test::Mock {
unless %already-seen{$m.name} {
$mocker.^add_method($m.name, method (|$c) {
$!log.log-method-call($m.name, $c);
+ %returning{$m.name} ~~ List ??
+ @(%returning{$m.name}) !!
+ %returning{$m.name}
});
%already-seen{$m.name} = True;
}

0 comments on commit 2c9739c

Please sign in to comment.