Permalink
Browse files

Test the various known/guessed twitter error formats

  • Loading branch information...
1 parent 13a569c commit 40c4291ff21a18ba6ca4c3fb29b355072f3873d6 @semifor committed Sep 5, 2010
Showing with 53 additions and 0 deletions.
  1. +53 −0 t/twitter_error.t
View
@@ -0,0 +1,53 @@
+#!perl
+use warnings;
+use strict;
+use Test::More tests => 4;
+use Net::Twitter::Error;
+use HTTP::Response;
+
+{
+ # old school error
+ my $res = HTTP::Response->new(400);
+
+ my $e = Net::Twitter::Error->new(
+ http_response => $res,
+ twitter_error => { error => "Something wicked" },
+ );
+
+ like $e, qr/Something wicked/, 'old school twitter error';
+}
+
+{
+ # newer variant
+ my $res = HTTP::Response->new(400);
+
+ my $e = Net::Twitter::Error->new(
+ http_response => $res,
+ twitter_error => { error => { message => "Something wicked" } },
+ );
+
+ like $e, qr/Something wicked/, 'twitter error with message/code';
+}
+
+{
+ # array of errors variant
+ my $res = HTTP::Response->new(400);
+
+ my $e = Net::Twitter::Error->new(
+ http_response => $res,
+ twitter_error => { errors => [{ message => "Something wicked" }] },
+ );
+
+ like $e, qr/Something wicked/, 'twitter array of errors';
+}
+
+{
+ # unexpected
+ my $res = HTTP::Response->new(400);
+
+ my $e = Net::Twitter::Error->new(
+ http_response => $res,
+ );
+
+ like $e, qr/Bad Request/, 'twitter array of errors';
+}

0 comments on commit 40c4291

Please sign in to comment.