[libdancer-plugin-rest-perl] 26/63: t/02_prepare_serializer_for_format.t: more tests, refactored
Jonas Smedegaard
dr at jones.dk
Wed Jul 2 11:44:51 UTC 2014
This is an automated email from the git hooks/post-receive script.
js pushed a commit to annotated tag 0.07
in repository libdancer-plugin-rest-perl.
commit 3f8993604fa514bad9f1a759a4a0ee2b2a9a8e16
Author: Alexis Sukrieh <sukria at sukria.net>
Date: Thu Oct 14 10:31:11 2010 +0200
t/02_prepare_serializer_for_format.t: more tests, refactored
---
t/02_prepare_serializer_for_format.t | 47 ++++++++++++++++++++++++++++++------
1 file changed, 39 insertions(+), 8 deletions(-)
diff --git a/t/02_prepare_serializer_for_format.t b/t/02_prepare_serializer_for_format.t
index 5217970..bc4a57b 100644
--- a/t/02_prepare_serializer_for_format.t
+++ b/t/02_prepare_serializer_for_format.t
@@ -5,10 +5,12 @@ use Test::More import => ['!pass'];
plan skip_all => "JSON is needed for this test"
unless Dancer::ModuleLoader->load('JSON');
-plan tests => 3;
+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;
@@ -17,7 +19,8 @@ my $json = JSON::encode_json($data);
prepare_serializer_for_format;
- get '/foo.:format' => sub {
+ get '/' => sub { "root" };
+ get '/:something.:format' => sub {
$data;
};
}
@@ -25,11 +28,39 @@ my $json = JSON::encode_json($data);
use lib 't';
use TestUtils;
-my $response = get_response_for_request(GET => '/foo.json');
-ok(defined($response), "response found for /foo.json");
+my @tests = (
+ {
+ request => [GET => '/'],
+ content_type => 'text/html',
+ response => 'root',
+ },
+ {
+ request => [GET => '/foo.json'],
+ content_type => 'application/json',
+ response => $json
+ },
+ {
+ request => [GET => '/foo.yml'],
+ content_type => 'text/x-yaml',
+ response => $yaml,
+ },
+ {
+ request => [GET => '/'],
+ content_type => 'text/html',
+ response => 'root',
+ },
+);
+
+plan tests => scalar(@tests) * 2;
+
+for my $test ( @tests ) {
+ my $response = get_response_for_request(@{$test->{request}});
+ is_deeply( $response->{headers},
+ [ 'Content-Type' => $test->{content_type}],
+ "headers have content_type set to ".$test->{content_type});
+
+ is( $response->{content}, $test->{response},
+ "\$data has been encoded" );
+}
-is_deeply( $response->{headers}, [ 'Content-Type' => 'application/json'],
- "headers have content_type set to application/json" );
-is( $response->{content}, $json,
- "\$data has been encoded to JSON");
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libdancer-plugin-rest-perl.git
More information about the Pkg-perl-cvs-commits
mailing list