NAME
Test::Spec::RMock - a mocking library for Test::Spec
VERSION
version 0.003
SYNOPSIS
use Test::Spec;
use Test::Spec::RMock;
describe "Something" => sub {
it "should do something" => {
my $foo = rmock('Foo');
$foo->should_receive('bar')->twice->and_return('baz');
Something->new->do_something_with($foo);
};
};
runtests unless caller;
EXPORTED METHODS
- rmock($name)
-
Creates a mock object with the given name.
$name
is used in error messages. Often a good choice is the name of the class or role you are mocking.
USING MOCK OBJECTS
Method stubs
You want to use method stubs on all messages that you don't care to set expectations on. Any interactions that don't are important for the test you are writing.
- $mock->stub($message_name => $return_value)
-
This creates a method stub on the mock object returning
$return_value
each time it is called.
Method mocks
Mocking methods allows you to set expectations on the messages that the mocked object should receive.
Message expectations
All return $self so that you can chain them.
- $expectation->and_return(...)
- $expectation->and_raise($exception)
- $expectation->with(...)
- $expectation->any_number_of_times()
- $expectation->at_least_once()
- $expectation->at_least($n)
-
$expectation->at_least(4)->times
- $expectation->once()
- $expectation->exactly($n)
-
$expectation->exactly(4)->times
- $expectation->times
-
Noop
SEE ALSO
AUTHOR
Kjell-Magne Øierud <kjellm@cpan.org>
COPYRIGHT AND LICENSE
This software is Copyright (c) 2012 by Kjell-Magne Øierud.
This is free software, licensed under:
The MIT (X11) License
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 142:
Non-ASCII character seen before =encoding in 'Øierud'. Assuming UTF-8