Add tests for Serialize::View error behavior
Andrew Rodland [Thu, 17 Dec 2009 10:55:44 +0000 (04:55 -0600)]
t/lib/Test/Serialize/Controller/REST.pm
t/lib/Test/Serialize/View/Awful.pm [new file with mode: 0644]
t/view.t

index 74b921c..118e237 100644 (file)
@@ -25,6 +25,7 @@ __PACKAGE__->config(
         'text/x-php-serialization' =>
              [ 'Data::Serializer', 'PHP::Serialization' ],
         'text/view'   => [ 'View', 'Simple' ],
+        'text/explodingview' => [ 'View', 'Awful' ],
         'text/broken' => 'Broken',
     },
 );
diff --git a/t/lib/Test/Serialize/View/Awful.pm b/t/lib/Test/Serialize/View/Awful.pm
new file mode 100644 (file)
index 0000000..9c9abf9
--- /dev/null
@@ -0,0 +1,27 @@
+package Test::Serialize::View::Awful;
+
+use base Catalyst::View;
+
+sub render {
+  my ($self, $c, $template) = @_;
+  die "I don't know how to do that!";
+}
+
+sub process {
+  my ($self, $c) = @_;
+
+  my $output = eval {
+    $self->render($c, "blah");
+  };
+
+  if ($@) {
+    my $error = qq/Couldn't render template. Error: "$@"/;
+    $c->error($error);
+    return 0;
+  }
+
+  $c->res->body($output);
+  return 1;
+}
+
+1;
index a5a379f..07b3974 100644 (file)
--- a/t/view.t
+++ b/t/view.t
@@ -1,6 +1,6 @@
 use strict;
 use warnings;
-use Test::More tests => 4;
+use Test::More tests => 6;
 use FindBin;
 
 use lib ( "$FindBin::Bin/lib", "$FindBin::Bin/../lib" );
@@ -18,4 +18,10 @@ is( $mres->content, $monkey_template, "GET returned the right data" );
 my $mres_post = request( $t->post( url => '/monkey_put', data => 1 ) );
 ok( $mres_post->is_success, "POST to the monkey passed." );
 
+my $t2 = Test::Rest->new( 'content_type' => 'text/explodingview' );
+my $res = request( $t2->get( url => '/monkey_get' ) );
+
+ok (! $res->is_success, 'View errors result in failure');
+like( $res->content, qr/don't know how/, 'The error looks okay');
+
 1;