1cac6712ce2a08d82bdc76e4c2358baad5d3f679
[catagits/Web-Simple.git] / t / response-filter.t
1 use strictures 1;
2 use Test::More;  
3 use Plack::Test;
4 use HTTP::Request::Common qw(GET POST);
5
6 {
7   package t::Web::Simple::ResponseFilter;
8   use Web::Simple;
9   sub dispatch_request {
10     my $self = shift;
11     sub (.html) {
12       response_filter {
13         return [
14           200,
15           [ 'Content-Type' => 'text/html' ], 
16           [ shift->{name} ],
17         ];
18       }
19     },
20     sub (GET + /index) {
21       bless {name=>'john'}, 'CrazyHotWildWet';
22     },
23   }
24 }
25
26 ok my $app = t::Web::Simple::ResponseFilter->new->to_psgi_app,
27   'Got a plack app';
28
29 test_psgi $app, sub {
30     my $cb = shift;
31     my $res = $cb->(GET "/index.html");
32     like $res->content, qr/john/,
33       'Got Expected Content';
34 };
35
36 done_testing;