[Catalyst] setting/getting session data from within tests
Yuval Kogman
nothingmuch at woobling.org
Mon Jun 5 19:08:03 CEST 2006
On Mon, Jun 05, 2006 at 16:08:57 +0200, Daniel McBrearty wrote:
> I might try the $c approach, but I haven't figured out how yet.
my $c = Test::MockObject->new;
$c->set_always( request => my $req = Test::MockObject->new );
$c->set_always( response => my $res = Test::MockObject->new );
$c->set_always( session => \( my %session ) );
$c->set_always( stash => \( my %stash ) );
# now play with $req, $res and $session...
# it might be hard, to do well. I suggest writing your own
# Catalyst::Mock::Request stuff and sharing with CPAN if you go
# by this route - inherit Catalyst::Request and simply provide
# more means of specifying the input params that don't rely on
# the engine.
my $controller = MyApp::Controller::Root->new;
$session{moose} = "ulf";
$controller->private_action( $c );
is( $stash{greeting}, "hello ulf" );
$response->called_ok( ... ); # also useful
This approach is either a blessing or a curse depending on many
factors. Some best practices:
rely on a well defined style in your code to ease mocking - if
you use request/response you don't need to alias req/res.
make sure you test small things - for example, don't test the
forward to the view - this is a broad test that will probably
need much more extensive mocking. This helps you remember to
keep your actions small, too.
Don't rely on this too much - maybe Selinium or
Test::WWW::Mechanize::Catalyst for bigger "behavioral" tests
that reallyh excercise full link paths are better.
Good luck!
P.S. As a service to the community please write your experiences on
the wiki when you're done.
--
Yuval Kogman <nothingmuch at woobling.org>
http://nothingmuch.woobling.org 0xEBD27418
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: not available
Url : http://lists.rawmode.org/pipermail/catalyst/attachments/20060605/280e55da/attachment.pgp
More information about the Catalyst
mailing list