-
Notifications
You must be signed in to change notification settings - Fork 8
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
Alexis Sukrieh
committed
Oct 14, 2010
1 parent
d06fb11
commit 831e62f
Showing
2 changed files
with
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,5 +62,3 @@ for my $test ( @tests ) { | |
is( $response->{content}, $test->{response}, | ||
"\$data has been encoded" ); | ||
} | ||
|
||
|
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,78 @@ | ||
use strict; | ||
use warnings; | ||
use Dancer::ModuleLoader; | ||
use Test::More import => ['!pass']; | ||
|
||
plan skip_all => "JSON is needed for this test" | ||
unless Dancer::ModuleLoader->load('JSON'); | ||
plan skip_all => "YAML is needed for this test" | ||
unless Dancer::ModuleLoader->load('YAML'); | ||
|
||
my $data = { foo => 42 }; | ||
my $json = JSON::encode_json($data); | ||
my $yaml = YAML::Dump($data); | ||
|
||
{ | ||
package Webservice; | ||
use Dancer; | ||
use Dancer::Plugin::REST; | ||
|
||
setting plugins => { | ||
REST => { | ||
serializers => { | ||
'yaml' => 'YAML', | ||
'json' => 'NotExists', | ||
} | ||
} | ||
}; | ||
|
||
prepare_serializer_for_format; | ||
|
||
get '/' => sub { "root" }; | ||
get '/:something.:format' => sub { | ||
$data; | ||
}; | ||
} | ||
|
||
use lib 't'; | ||
use TestUtils; | ||
|
||
my @tests = ( | ||
{ | ||
request => [GET => '/'], | ||
response => 'root', | ||
}, | ||
{ | ||
request => [GET => '/foo.json'], | ||
response => qr/Error 500.*Unable to process your query/ms | ||
}, | ||
{ | ||
request => [GET => '/foo.yaml'], | ||
response => $yaml, | ||
}, | ||
{ | ||
request => [GET => '/foo.foobar'], | ||
response => qr/unsupported format requested: foobar/ms, | ||
}, | ||
{ | ||
request => [GET => '/'], | ||
response => 'root', | ||
}, | ||
); | ||
|
||
plan tests => scalar(@tests); | ||
|
||
for my $test ( @tests ) { | ||
my $response = get_response_for_request(@{$test->{request}}); | ||
if (ref($test->{response})) { | ||
like( $response->{content}, $test->{response}, | ||
"response looks good for '@{$test->{request}}'" ); | ||
} | ||
else { | ||
is( $response->{content}, $test->{response}, | ||
"response looks good for '@{$test->{request}}'" ); | ||
} | ||
} | ||
|
||
|
||
|