line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mojo::Role::PSGI; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
680
|
use Role::Tiny; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
11
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
853
|
use Mojolicious; |
|
1
|
|
|
|
|
55610
|
|
|
1
|
|
|
|
|
15
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
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; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
my $t = Test::Mojo->with_roles('+PSGI')->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
|
|
|
|
|
|
|
=head1 OVERRIDES |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 new |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Overrides the L method to use a PSGI app, instantiating a script or class if necessary. |
57
|
|
|
|
|
|
|
This should feel very similar to the original behavior except that now PSGI apps are the target, rather than Mojolicious apps. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Acceptable arguments are strings that can be used by L or else instantated PSGI applications, including bare code references. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head1 NOTA BENE |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
This module previously recommended L and depended on it. |
64
|
|
|
|
|
|
|
Since that recommendation, proper role handling was added to Mojolicious (see L). |
65
|
|
|
|
|
|
|
This obviates the need for "WithRoles", just use the native one. |
66
|
|
|
|
|
|
|
The translation is as follows: |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
use Test::More; |
69
|
|
|
|
|
|
|
use Test::Mojo; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
my $t = Test::Mojo::WithRoles->new('path/to/app.psgi'); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
becomes |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
use Test::More; |
76
|
|
|
|
|
|
|
use Test::Mojo; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $t = Test::Mojo->with_roles('+PSGI')->new('path/to/app.psgi'); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SEE ALSO |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=over |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=item L |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item L |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=item L |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=item L |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=item L |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=back |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 SOURCE REPOSITORY |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
L |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 AUTHOR |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
Joel Berger, Ejoel.a.berger@gmail.comE |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Copyright (C) 2015 by Joel Berger |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
110
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
111
|
|
|
|
|
|
|
|