1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
#!perl
use 5.14.1;
use warnings;
use HTTP::Response;
use Test::Spec;
use Twitter::API::Context;
use Twitter::API::Error;
sub construct_error {
my ( $http_status_code, $twitter_error_code, $twitter_error_text ) = @_;
my $http_response = HTTP::Response->new($http_status_code);
my $result = {
errors => [
{ code => $twitter_error_code, message => $twitter_error_text },
]
} if defined $twitter_error_code;
my $context = Twitter::API::Context->new(
http_response => $http_response,
$result ? ( result => $result ) : (),
);
return Twitter::API::Error->new(context => $context);
}
describe 'Twitter::API::Error' => sub {
it 'is always true' => sub {
ok !!construct_error(0);
};
describe is_token_error => sub {
for my $code ( 32, 64, 88, 89, 99, 135, 136, 215, 226, 326 ) {
it "recognizes $code as a token error" => sub {
ok construct_error(400, $code)->is_token_error;
};
}
};
describe is_token_error => sub {
for my $code ( 34, 50, 63, 144 ) {
it "does not recognize $code as a token error" => sub {
ok !construct_error(400, $code)->is_token_error;
};
}
};
};
runtests;
|