Test::Mojo::Role::PSGI - Test PSGI apps using Test::Mojo
use strict; use warnings; use Test::More; use Test::Mojo; my $t = Test::Mojo->with_roles('+PSGI')->new('path/to/app.psgi'); $t->get_ok('/some/path') ->status_is(200) ->content_type_like(qr/html/) ->text_is('.some-class:nth-child(5)' => 'content of 5th some-class'); ... done_testing;
Test::Mojo makes testing Mojolicious applications easy and fun. Wouldn't it be nice if there was some way to use it for non-Mojolicious apps? Test::Mojo::Role::PSGI does just that.
Overrides the "new" in Test::Mojo method to use a PSGI app, instantiating a script or class if necessary. This should feel very similar to the original behavior except that now PSGI apps are the target, rather than Mojolicious apps.
Acceptable arguments are strings that can be used by "load_psgi" in Plack::Util or else instantated PSGI applications, including bare code references.
This module previously recommended Test::Mojo::WithRoles and depended on it. Since that recommendation, proper role handling was added to Mojolicious (see "Extending Test::Mojo" in Mojolicious::Guides::Testing). This obviates the need for "WithRoles", just use the native one. The translation is as follows:
use Test::More; use Test::Mojo; my $t = Test::Mojo::WithRoles->new('path/to/app.psgi');
becomes
use Test::More; use Test::Mojo; my $t = Test::Mojo->with_roles('+PSGI')->new('path/to/app.psgi');
http://github.com/jberger/Test-Mojo-Role-PSGI
Joel Berger, <joel.a.berger@gmail.com>
Copyright (C) 2015 by Joel Berger
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Test::Mojo::Role::PSGI, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Mojo::Role::PSGI
CPAN shell
perl -MCPAN -e shell install Test::Mojo::Role::PSGI
For more information on module installation, please visit the detailed CPAN module installation guide.