Test::Spec::RMock - a mocking library for Test::Spec
version 0.006
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;
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.
$name
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.
This creates method stubs for each message defined in %spec.
$mock->stub( message1 => 'foo', message2 => 'bar', ); $mock->message1; # 'foo' $mock->message2; # 'bar'
Creates a chain of two or more method stubs in one statement.
$mock->stub_chain(qw(one two three))->and_return('four'); $mock->one->two->three; # 'four'
Mocking methods allows you to set expectations on the messages that the mocked object should receive.
Use a null object when you don't care about the object's behavior or interaction, and don't want to explicitly stub everything out that's needed.
All return $self so that you can chain them.
$expectation->at_least(4)->times
$expectation->exactly(4)->times
Noop
Test::Spec
Test::Spec::Mock
Kjell-Magne Øierud <kjellm@cpan.org>
This software is Copyright (c) 2012 by Kjell-Magne Øierud.
This is free software, licensed under:
The MIT (X11) License
To install Test::Spec::RMock, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Spec::RMock
CPAN shell
perl -MCPAN -e shell install Test::Spec::RMock
For more information on module installation, please visit the detailed CPAN module installation guide.