[dancer-users] Unit testing plugins

Steve Dondley sdondley at gmail.com
Mon Nov 19 00:38:41 GMT 2018


Ive been messing around with figuring out how to unit test plugins. I came
up with something that works but that is very messy and hacky and so it
feels like I'm way off the beaten path. Can someone set me straight on
whether there is an easier way to peek into the inner data structures of a
plugin?

Here's what I came up with to dump the contents of my plugin's "html_cache"
attribute:

my $app = Dancer2::Core::App->new();
$app->with_plugins('Menu');
$app->plugins->[0]->menu_item( { title => 'blah' }, $app->add_route(
    method => 'get',
    regexp => '/test',
    code => sub { $app->template('index.tt', shift) } ));

my $req = Dancer2::Core::Request->new( env => {
        SERVER_NAME       => 'localhost',
        SERVER_PORT       => 8000,
  }  );
my $route = $app->routes->{get}->[0];
$req->{route} = $route;
$req->{cookies} = {  };
$app->{request} = $req;
$route->execute($app);
print Dumper $app->plugins->[0]->html_cache;

Thanks!

-- 
Prometheus Labor Communications, Inc.
http://prometheuslabor.com
413-572-1300

UnionConnect Phone App for Labor Unions
http://unionconnect.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.preshweb.co.uk/pipermail/dancer-users/attachments/20181118/b8832939/attachment.html>


More information about the dancer-users mailing list