From: adam Date: Sun, 3 Dec 2006 20:27:14 +0000 (+0000) Subject: r48@latte: adam | 2006-12-03 11:32:40 -0800 X-Git-Tag: 1.08~284 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Action-Serialize-Data-Serializer.git;a=commitdiff_plain;h=17d910bd120ee243917756ae8c4281e621a4f986 r48@latte: adam | 2006-12-03 11:32:40 -0800 Fixed up YAML tests --- diff --git a/t/01-yaml.t b/t/01-yaml.t index 0f2c1e3..7559615 100644 --- a/t/01-yaml.t +++ b/t/01-yaml.t @@ -1,46 +1,34 @@ use strict; use warnings; use Test::More qw(no_plan); -use YAML::Syck; use FindBin; use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib"); use Test::Rest; -# Should use the default serializer, YAML -my $t = Test::Rest->new('content_type' => 'text/plain'); - -BEGIN { use_ok 'Catalyst::Test', 'SampleREST' } - -my $mres = request($t->get(url => '/monkey')); -# We should find the monkey -ok( $mres->is_success, 'GET the monkey succeeded' ); - -# We should use the default serializer, YAML -my $monkey_template = { - monkey => 'likes chicken!', -}; -my $monkey_data = Load($mres->content); -is_deeply($monkey_data, $monkey_template, "GET returned the right data"); - -$t->{'content_type'} = 'text/x-yaml'; # Try again, with x-yaml -my $mres_yaml = request($t->get(url => '/monkey')); -ok( $mres_yaml->is_success, 'GET the monkey x-yaml succeeded' ); -is_deeply(Load($mres_yaml->content), $monkey_template, "GET x-yaml returned the right data"); +use_ok 'Catalyst::Test', 'Test::Serialize'; -$t->{'content_type'} = 'text/plain'; # Try again, with text/plain -my $post_data = { - 'sushi' => 'is good for monkey', +# Should use the default serializer, YAML +my $t = Test::Rest->new('content_type' => 'text/x-yaml'); + +my $has_serializer = eval "require YAML::Syck"; +SKIP: { + skip "YAML::Syck not available", 4, unless $has_serializer; + + # We should use the default serializer, YAML + my $monkey_template = { + monkey => 'likes chicken!', + }; + my $mres = request($t->get(url => '/monkey_get')); + ok( $mres->is_success, 'GET the monkey succeeded' ); + is_deeply(YAML::Syck::Load($mres->content), $monkey_template, "GET returned the right data"); + + my $post_data = { + 'sushi' => 'is good for monkey', + }; + my $mres_post = request($t->post(url => '/monkey_put', data => YAML::Syck::Dump($post_data))); + ok( $mres_post->is_success, "POST to the monkey succeeded"); + is_deeply($mres_post->content, "is good for monkey", "POST data matches"); }; -my $mres_post = request($t->post(url => '/monkey', data => Dump($post_data))); -ok( $mres_post->is_success, "POST to the monkey succeeded"); -is_deeply($mres_post->content, Dump($post_data), "POST data matches"); - -my $mdel = request($t->delete(url => '/monkey')); -ok(! $mdel->is_success, "DELETE-ing the monkey failed; long live monkey!"); -ok($mdel->code eq "405", "DELETE-ing the monkey returned 405"); -my @allowed = $mdel->header('allow'); -my @rallowed = qw(GET POST); -ok(@allowed eq @rallowed, "Default 405 handler returned proper methods in Allow header"); 1;