File Coverage

blib/lib/Test/Mojo/Role/PSGI.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


line stmt bran cond sub pod time code
1             package Test::Mojo::Role::PSGI;
2              
3 1     1   899 use Role::Tiny;
  1         2  
  1         7  
4              
5 1     1   978 use Mojolicious;
  1         114544  
  1         12  
6              
7             our $VERSION = '0.05';
8             $VERSION = eval $VERSION;
9              
10             around new => sub {
11             my ($orig, $self, $psgi) = @_;
12             my $t = $self->$orig;
13             if ($psgi) {
14             my $app = Mojolicious->new;
15             $app->plugin('Mojolicious::Plugin::MountPSGI' => { '/' => $psgi }) if $psgi;
16             $t->app($app);
17             }
18             return $t;
19             };
20              
21             1;
22              
23             =head1 NAME
24              
25             Test::Mojo::Role::PSGI - Test PSGI apps using Test::Mojo
26              
27             =head1 SYNOPSIS
28              
29             use strict;
30             use warnings;
31              
32             use Test::More;
33             use Test::Mojo::WithRoles 'PSGI';
34              
35             my $t = Test::Mojo::WithRoles->new('path/to/app.psgi');
36              
37             $t->get_ok('/some/path')
38             ->status_is(200)
39             ->content_type_like(qr/html/)
40             ->text_is('.some-class:nth-child(5)' => 'content of 5th some-class');
41              
42             ...
43              
44             done_testing;
45              
46             =head1 DESCRIPTION
47              
48             L makes testing L applications easy and fun.
49             Wouldn't it be nice if there was some way to use it for non-Mojolicious apps?
50             L does just that.
51              
52             The author suggests using L to make instances of the tester with (possibly multiple) roles applied in a sane way.
53              
54             =head1 OVERRIDES
55              
56             =head2 new
57              
58             Overrides the L method to use a PSGI app, instantiating a script or class if necessary.
59             This should feel very similar to the original behavior except that now PSGI apps are the target, rather than Mojolicious apps.
60              
61             Acceptable arguments are strings that can be used by L or else instantated PSGI applications, including bare code references.
62              
63             =head1 SEE ALSO
64              
65             =over
66              
67             =item L
68              
69             =item L
70              
71             =item L
72              
73             =item L
74              
75             =item L
76              
77             =back
78              
79             =head1 SOURCE REPOSITORY
80              
81             L
82              
83             =head1 AUTHOR
84              
85             Joel Berger, Ejoel.a.berger@gmail.comE
86              
87             =head1 COPYRIGHT AND LICENSE
88              
89             Copyright (C) 2015 by Joel Berger
90              
91             This library is free software; you can redistribute it and/or modify
92             it under the same terms as Perl itself.
93