Full Mojolicious application have routes command which will dump application routes:
script/my_app.pl routes
How can I do same thing from testing script for Lite application?
use Mojo::Base -strict;
use Test::Mojo;
use Test::More;
use Mojolicious::Lite;
... # Routes defined here
my $t = Test::Mojo->new;
$t->dump_all_routes # What should I do here?
A Mojolicous::Lite app is a fully fledged Mojolicious application, just with more convenient syntax.
You can use /app.pl routes to print routes on the command line for Lite apps as well.
You can programmatically access the routes via the app->routes object, which is a Mojolicious::Routes object that contains individual Mojolicious::Routes::Route objects.
Unfortunately, the Routes object does not document an API for enumerating all routes. You will therefore have to traverse the route tree yourself. The corresponding source code for the Mojolicious::Command::routes command is rather convoluted. Alternatively, you can ->find($name) specific routes by name.
The app is accessible from a Test::Mojo object as $test->app. Note that the docs for that method include a test that verifies routing:
ok $t->app->routes->find('echo')->is_websocket, 'WebSocket route';
Note that you must initialize the test object with the app name, or assign it an app instance later in order to access the app through the test object.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With