Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
94 additions
and
4 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
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
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,84 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
use Plack::Test; | ||
use HTTP::Request::Common; | ||
|
||
subtest 'halt with parameter within routes' => sub { | ||
{ | ||
|
||
package App; | ||
use Dancer2; | ||
|
||
get '/' => sub { 'hello' }; | ||
get '/halt' => sub { | ||
header 'X-Foo' => 'foo'; | ||
halt; | ||
}; | ||
get '/shortcircuit' => sub { | ||
halt('halted'); | ||
redirect '/'; # won't get executed as halt returns immediately. | ||
}; | ||
} | ||
|
||
my $app = App->to_app; | ||
is( ref $app, 'CODE', 'Got app' ); | ||
|
||
test_psgi $app, sub { | ||
my $cb = shift; | ||
|
||
{ | ||
my $res = $cb->( GET '/shortcircuit' ); | ||
is( $res->code, 200, '[/shortcircuit] Correct status' ); | ||
is( $res->content, 'halted', '[/shortcircuit] Correct content' ); | ||
|
||
} | ||
|
||
{ | ||
my $res = $cb->( GET '/halt' ); | ||
|
||
is( | ||
$res->server, | ||
"Perl Dancer2 " . Dancer2->VERSION, | ||
'[/halt] Correct Server header', | ||
); | ||
|
||
is( | ||
$res->headers->header('X-Foo'), | ||
'foo', | ||
'[/halt] Correct X-Foo header', | ||
); | ||
} | ||
}; | ||
|
||
}; | ||
|
||
subtest 'halt with parameter in before hook' => sub { | ||
{ | ||
package App; | ||
use Dancer2; | ||
|
||
hook before => sub { | ||
halt('I was halted') if request->dispatch_path eq '/shortcircuit'; | ||
}; | ||
|
||
} | ||
|
||
my $app = App->to_app; | ||
is( ref $app, 'CODE', 'Got app' ); | ||
|
||
test_psgi $app, sub { | ||
my $cb = shift; | ||
my $res = $cb->( GET '/shortcircuit' ); | ||
|
||
is( $res->code, 200, '[/shortcircuit] Correct code with before hook' ); | ||
is( | ||
$res->content, | ||
'I was halted', | ||
'[/shortcircuit] Correct content with before hook', | ||
); | ||
}; | ||
}; | ||
|
||
done_testing; | ||
|