#!/usr/bin/env perl use Test::More tests => 17; use Data::Dumper; use Test::MockObject::Extends; use WWW::Reddit; my $r = WWW::Reddit->new( username => '', password => '' ); # with no ID, we should get undef $details = $r->details(); ok( ! defined $details, 'details returns undef without ID' ) or diag( Data::Dumper->Dump( [ $details ], [ 'details' ] ) ); my $id = '63iup'; $r->set_id( $id ); my $mech = $r->get_mech(); $mech = Test::MockObject::Extends->new( $mech ); $mech->set_always( 'get', '' ); # stop Mech from actually fetching things $mech->set_always( 'content', ); # return our page from __DATA__ $r->set_mech( $mech ); my $details = $r->details(); # $details = { # 'submitted' => '20 Dec 2007', # 'points' => '6', # 'upvotes' => '6', # 'downvotes' => '0' # 'title' => 'perl module to interact with reddit - WWW::Reddit', # 'url' => 'http://search.cpan.org/~amoore/WWW-Reddit-0.02/', # }; is( scalar( keys %$details ), 6, 'details returned 6 things' ); is( $details->{'submitted'}, '20 Dec 2007', 'submitted' ); is( $details->{'points'}, '6', 'points' ); is( $details->{'upvotes'}, '6', 'upvotes' ); is( $details->{'downvotes'}, '0', 'downvotes' ); is( $details->{'title'}, 'perl module to interact with reddit - WWW::Reddit', 'title' ); is( $details->{'url'}, 'http://search.cpan.org/~amoore/WWW-Reddit-0.02/', 'url' ); # diag( Data::Dumper->Dump( [ $details ], [ 'details' ] ) ); # with no ID, we should get undef $r->set_id( undef ); $details = $r->details(); ok( ! defined $details, 'details returns undef without ID' ); # Now, let's see if it works if we pass in the ID. $details = $r->details( $id ); is( $r->get_id(), $id, 'we have set the ID' ); is( scalar( keys %$details ), 6, 'details returned 6 things' ); is( $details->{'submitted'}, '20 Dec 2007', 'submitted' ); is( $details->{'points'}, '6', 'points' ); is( $details->{'upvotes'}, '6', 'upvotes' ); is( $details->{'downvotes'}, '0', 'downvotes' ); is( $details->{'title'}, 'perl module to interact with reddit - WWW::Reddit', 'title' ); is( $details->{'url'}, 'http://search.cpan.org/~amoore/WWW-Reddit-0.02/', 'url' ); __DATA__; programming: perl module to interact with reddit - WWW::Reddit
programmingback to hotto reddit.com
6 points posted 17 minutes ago by amoore3 comments
submitted20 Dec 2007
points6
up votes6
down votes0