Skip to content

Commit

Permalink
100% cover rate
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Sukrieh committed Oct 14, 2010
1 parent d06fb11 commit 831e62f
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 2 deletions.
2 changes: 0 additions & 2 deletions t/02_prepare_serializer_for_format.t
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,3 @@ for my $test ( @tests ) {
is( $response->{content}, $test->{response},
"\$data has been encoded" );
}


78 changes: 78 additions & 0 deletions t/04_plugin_settings.t
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}}'" );
}
}



0 comments on commit 831e62f

Please sign in to comment.