Skip to content

Commit

Permalink
Replaced Test::Exception with Test::Fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
semifor committed Mar 9, 2011
1 parent 60db256 commit eb5346f
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 41 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,3 +1,5 @@
- replaced Test::Exception with Test::Fatal in tests

3.15000 2011-02-25
- added Lists API method members_create_all (alias add_list_members)
- added tests dependency: Test::Exception (closes RT #65786)
Expand Down
2 changes: 1 addition & 1 deletion Makefile.PL
Expand Up @@ -44,7 +44,7 @@ requires 'URI' => 1.40;
requires 'URI::Escape';
requires 'Try::Tiny' => 0.03;

test_requires 'Test::Exception';
test_requires 'Test::Fatal';
test_requires 'Test::More' => 0.88; # for done_testing

# Don't rely on the JSON::Any requirement to pull in a suitable JSON backend.
Expand Down
4 changes: 2 additions & 2 deletions README
Expand Up @@ -1521,8 +1521,8 @@ Search API Methods
search
search(q)

Parameters: q, callback, lang, rpp, page, since_id, geocode,
show_user
Parameters: q, callback, lang, locale, rpp, page, since_id, until,
geocode, show_user, result_type
Required: q

Returns a HASH reference with some meta-data about the query
Expand Down
9 changes: 4 additions & 5 deletions t/02_fails.t
Expand Up @@ -2,7 +2,7 @@
use warnings;
use strict;
use Test::More;
use Test::Exception;
use Test::Fatal;
use lib qw(t/lib);
use Net::Twitter;

Expand All @@ -20,9 +20,8 @@ my $nt = Net::Twitter->new(
my $t = TestUA->new($nt->ua);

# things that should fail
throws_ok { $nt->relationship_exists(qw/one two three/) } qr/expected 2 args/, 'too many args';
throws_ok {
Net::Twitter->new(useragent_class => 'NoSuchModule::Test7701')->verify_credentials
} qr/Can't locate NoSuchModule/, 'bad useragent_class';
like exception { $nt->relationship_exists(qw/one two three/) }, qr/expected 2 args/, 'too many args';
like exception { Net::Twitter->new(useragent_class => 'NoSuchModule::Test7701')->verify_credentials },
qr/Can't locate NoSuchModule/, 'bad useragent_class';

exit 0;
7 changes: 3 additions & 4 deletions t/10_net-twitter-regression.t
Expand Up @@ -2,7 +2,7 @@
use Carp;
use strict;
use Test::More;
use Test::Exception;
use Test::Fatal;
use lib qw(t/lib);

{
Expand Down Expand Up @@ -39,7 +39,7 @@ $t->response->content('true');
my $r;

# back compat: 1.23 accepts scalar args
lives_ok { $r = $nt->relationship_exists('homer', 'marge') } 'relationship_exists scalar args';
is exception { $r = $nt->relationship_exists('homer', 'marge') }, undef, 'relationship_exists scalar args';

ok $r = $nt->relationship_exists({ user_a => 'homer', user_b => 'marge' }),
'relationship_exists hashref';
Expand Down Expand Up @@ -93,8 +93,7 @@ $r = $nt->list_lists('perl_api');
is $t->request->uri->scheme, 'https', 'ssl used for Lists';

### v3.10001 ### netrc used $self->apiurl, which is only available via the API::REST trait
lives_ok { Net::Twitter->new(netrc => 1, traits => [qw/API::Lists/]) }
'netrc with API::Lists lives';
is exception { Net::Twitter->new(netrc => 1, traits => [qw/API::Lists/]) }, undef, 'netrc with API::Lists lives';
### v3.11004 ### single array ref arg to update_profile_image not proprerly handled
$r = $nt->update_profile_image([ undef, 'my_mug.jpg', Content_Type => 'image/jpeg', Content => '' ]);
is $t->request->content_type, 'multipart/form-data', 'multipart/form-data';
Expand Down
4 changes: 2 additions & 2 deletions t/11_useragent.t
Expand Up @@ -4,12 +4,12 @@ use warnings;
use strict;

use Test::More tests => 3;
use Test::Exception;
use Test::Fatal;

use_ok 'Net::Twitter';

my $nt;
lives_ok { $nt = Net::Twitter->new(useragent_args => { timeout => 20 }) }
is exception { $nt = Net::Twitter->new(useragent_args => { timeout => 20 }) }, undef,
'object creation with useragent_args';

is $nt->ua->timeout, 20, 'useragent_args applied';
10 changes: 5 additions & 5 deletions t/14_authenticate.t
Expand Up @@ -2,7 +2,7 @@
use warnings;
use strict;
use Test::More;
use Test::Exception;
use Test::Fatal;
use lib qw(t/lib);
use Net::Twitter;

Expand All @@ -17,11 +17,11 @@ isa_ok $nt, 'Net::Twitter';
$nt = Net::Twitter->new(legacy => 0);
my $t = TestUA->new($nt->ua);

lives_ok { $nt->user_timeline } "lives without credentials";
is exception { $nt->user_timeline }, undef, "lives without credentials";
ok !$t->request->header('Authorization'), "no auth header without credentials";

$nt->credentials(homer => 'doh!');
lives_ok { $nt->user_timeline } "lives with credentials";
is exception { $nt->user_timeline }, undef, "lives with credentials";
like $t->request->header('Authorization'), qr/Basic/, "has Basic Auth header";

$nt->public_timeline;
Expand All @@ -46,9 +46,9 @@ $nt = Net::Twitter->new(
);
$t = TestUA->new($nt->ua);

lives_ok { $nt->user_timeline } "lives without oauth tokens";
is exception { $nt->user_timeline }, undef, "lives without oauth tokens";
ok !$t->request->header('Authorization'), "no auth header without access tokens";

$nt->access_token('1234');
$nt->access_token_secret('5678');
lives_ok { $nt->user_timeline } "lives with access tokens";
is exception { $nt->user_timeline }, undef, "lives with access tokens";
34 changes: 16 additions & 18 deletions t/20_exceptions.t
Expand Up @@ -2,15 +2,13 @@
use warnings;
use strict;
use Test::More;
use Test::Exception;
use Test::Fatal;
use lib qw(t/lib);
use Net::Twitter;

eval 'use TestUA';
plan skip_all => 'LWP::UserAgent 5.819 required for tests' if $@;

plan tests => 11;

my $nt = Net::Twitter->new(
traits => [qw/API::REST/],
username => 'homer',
Expand All @@ -35,25 +33,25 @@ else {
fail $message;
}

dies_ok { $nt->destroy_direct_message(456) } 'TwitterException';
my $e = $@;
isa_ok $e, 'Net::Twitter::Error';
like $e, qr/No direct message/, 'error stringifies';
is $e->http_response->code, 404, "respose code";
is $e->code, 404, 'http_response handles code';
like $e->twitter_error->{request}, qr/456.json/, 'twitter_error request';
is $e, $e->error, 'stringifies to $@->error';


{
my $e = exception { $nt->destroy_direct_message(456) };
isa_ok $e, 'Net::Twitter::Error';
like $e, qr/No direct message/, 'error stringifies';
is $e->http_response->code, 404, "respose code";
is $e->code, 404, 'http_response handles code';
like $e->twitter_error->{request}, qr/456.json/, 'twitter_error request';
is $e, $e->error, 'stringifies to $@->error';
}

# simulate a 500 response returned by LWP::UserAgent when it can't make a connection
$response = HTTP::Response->new(500, "Can't connect to api.twitter.com:80");
$response->content("<html>foo</html>");
$t->response($response);

dies_ok { $nt->friends_timeline({ since_id => 500_000_000 }) } 'HttpException';
$e = $@;
isa_ok $e, 'Net::Twitter::Error';
like $e->http_response->content, qr/html/, 'html content';
{
my $e = exception { $nt->friends_timeline({ since_id => 500_000_000 }) };
isa_ok $e, 'Net::Twitter::Error';
like $e->http_response->content, qr/html/, 'html content';
}

exit 0;
done_testing;
4 changes: 2 additions & 2 deletions t/21_wraperror.t
@@ -1,7 +1,7 @@
#!perl
use warnings;
use strict;
use Test::Exception;
use Test::Fatal;
use Test::More;
use lib qw(t/lib);

Expand All @@ -23,7 +23,7 @@ ok defined $r && !defined $nt->get_error, 'api call success';

$t->response(HTTP::Response->new(500, $msg));

lives_ok { $r = $nt->public_timeline } 'exception trapped';
is exception { $r = $nt->public_timeline }, undef, 'exception trapped';
is $nt->http_message, $msg, 'http_message';
isa_ok $nt->get_error, 'HASH', 'get_error returns a HASH ref';
ok !defined $r, 'result is undef';
Expand Down
4 changes: 2 additions & 2 deletions t/30_legacy.t
@@ -1,7 +1,7 @@
#!perl
use warnings;
use strict;
use Test::Exception;
use Test::Fatal;
use Test::More;
use lib qw(t/lib);

Expand All @@ -26,7 +26,7 @@ ok $nt->update_twittervision(90210), 'update_twittervision called';

$t->response(HTTP::Response->new(500, $msg));

lives_ok { $nt->public_timeline } 'exception trapped';
is exception { $nt->public_timeline }, undef, 'exception trapped';
is $nt->http_message, $msg, 'http_message';

exit 0;

0 comments on commit eb5346f

Please sign in to comment.