Skip to content

Commit

Permalink
Improved tests for bools; added test for end_session
Browse files Browse the repository at this point in the history
  • Loading branch information
semifor committed Jun 6, 2009
1 parent a3f16f8 commit c06ca4c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ t/12_identica.t
t/20_exceptions.t
t/20_generated.t
t/21_wraperror.t
t/22_twitter_insanity.t
t/30_legacy.t
t/99-pod_coverage.t
t/99-pod_spelling.t
Expand Down
2 changes: 1 addition & 1 deletion lib/Net/Twitter/Core.pm
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ sub _parse_result {
die Net::Twitter::Error->new(twitter_error => $obj, http_response => $res);
}

return $obj if $res->is_success && $obj;
return $obj if $res->is_success && defined $obj;

my $error = Net::Twitter::Error->new(http_response => $res);
$error->twitter_error($obj) if $obj;
Expand Down
2 changes: 1 addition & 1 deletion t/10_net-twitter-regression.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ok $r = $nt->relationship_exists({ user_a => 'homer', user_b => 'marge' })
'relationship_exists hashref';

# back compat: 1.23 returns bool
cmp_ok $r, '==', 1, 'relationship_exists returns bool';
ok $r, 'relationship_exists returns true';
$nt->ua->clear_response;


Expand Down
8 changes: 4 additions & 4 deletions t/12_identica.t
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ use_ok 'Net::Twitter';

# Net really dependent upon identica => 1, which fouls Mock::LWP::UserAgent,
# anyway.
my $nt = Net::Twitter->new;
my $nt = Net::Twitter->new(legacy => 0);
my $ua = $nt->ua;

$ua->set_response({ code => 200, message => 'OK', content => '"true"' });
my $r = $nt->follows('night', 'day');
is $r, 1, 'string "true" is 1';
ok $r, 'string "true" is true';

$ua->set_response({ code => 200, message => 'OK', content => '"false"' });
$r = $nt->follows('night', 'day');
ok !defined $r, 'string "false" is undef';
ok !$r, 'string "false" is false';

# and when they finally get it right:
$ua->set_response({ code => 200, message => 'OK', content => 'true' });
$r = $nt->follows('night', 'day');
is $r, 1, 'bool true is 1';
ok $r, 'bool true is true';
28 changes: 28 additions & 0 deletions t/22_twitter_insanity.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!perl
use warnings;
use strict;

use Test::More tests => 1;

use Net::Twitter;

# For end_session, on success, twitter returns status code 200 and an ERROR
# payload!!!

my $nt = Net::Twitter->new(legacy => 0);
$nt->ua->add_handler(request_send => sub {
my ($request, $ua, $h) = @_;

my $res = HTTP::Response->new(200, 'OK');
$res->content('{"error":"Logged out.","request":"/account/end_session.json"}');
$res->request($request);

return $res;
});


# This test will always succeed since we're spoofing the response
# from Twitter. It's simply meant to demonstrate Twitter's behavior.
# Should we thorw an error, or should we return the HASH?
my $r = eval { $nt->end_session };
like $@, qr/Logged out/, 'error on success';

0 comments on commit c06ca4c

Please sign in to comment.