-
Notifications
You must be signed in to change notification settings - Fork 214
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
let an http-exception object that ->can("as_psgi") recieve the psgi $…
…env as its first argument
- Loading branch information
Showing
2 changed files
with
44 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
use strict; | ||
use warnings; | ||
use Plack::Test; | ||
use HTTP::Request::Common; | ||
use Plack::Middleware::HTTPExceptions; | ||
use Test::More; | ||
|
||
{ | ||
package MyApp::Exception::Tuple; | ||
|
||
sub new { | ||
my ($class, @args) = @_; | ||
return bless +{res => \@args}, $class; | ||
} | ||
|
||
sub as_psgi { | ||
my ($self, $env) = @_; | ||
Test::More::ok $env && $env->{'psgi.version'}, | ||
'has $env and its a psgi $env'; | ||
return $self->{res}; | ||
} | ||
} | ||
|
||
ok my $psgi_app = sub { | ||
my $env = shift; | ||
die MyApp::Exception::Tuple->new( | ||
404, ['content-type'=>'text/plain'], ['Not Found']); | ||
}; | ||
|
||
ok $psgi_app = Plack::Middleware::HTTPExceptions->wrap($psgi_app); | ||
|
||
test_psgi $psgi_app, sub { | ||
my $cb = shift; | ||
my $res = $cb->(GET "/"); | ||
is $res->code, 404; | ||
is $res->content, 'Not Found'; | ||
}; | ||
|
||
# need to list the expected test number because of the test case in the | ||
# exception class. | ||
done_testing(5); |