Skip to content

Commit

Permalink
Added some more test
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Sergeant committed Apr 19, 2012
1 parent 0db0024 commit a199466
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/WWW/Mechanize/Boilerplate.pm
Original file line number Diff line number Diff line change
Expand Up @@ -578,10 +578,12 @@ option and show the result of Mech's C<success()>.

sub note_status {
my ( $self ) = @_;
my $success = $self->mech->success;

$self->indent_note("is_success() returned " . (
$self->mech->success ? 'true' : 'false'
$success ? 'true' : 'false'
), 1 );
return $self->mech->success;
return $success;
}

=head2 assert_location
Expand Down
71 changes: 71 additions & 0 deletions t/020_create_methods.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!perl

use strict;
use warnings;

use Test::More;
use Test::MockObject;
use WWW::Mechanize::Boilerplate;

# Happy-path tests for method creation

# Set up to capture all diagnostic output
our @notes;
{
no warnings qw/redefine once/;
*WWW::Mechanize::Boilerplate::indent_note = sub {
my ( $class, $note ) = @_;
push( @notes, $note );
}
}

# Set up a fake mech, and instantiate a new client
my $mech = Test::MockObject->new();
$mech->set_isa('WWW::Mechanize');
my $client = WWW::Mechanize::Boilerplate->new({ mech => $mech });
my $uri = Test::MockObject->new();
$uri->set_always( path_query => '/foo/bar' );
$mech->set_always( uri => $uri );

# Capture stuff sent to various mechanize methods
our @mech_actions;
sub add_action { my $type = shift; my $class = shift; push( @mech_actions, [$type, @_] ) }
$mech->mock( get => sub { add_action('get', @_) } );
$mech->mock( success => sub { add_action('success', @_); return 1 } );

# Set up a simple fetch method
$client->create_fetch_method(
method_name => 'new_fetch',
page_description => 'some page',
page_url => 'http://foo/bar',
);

# Check it showed up and works
{
local @notes;
local @mech_actions;

$client->new_fetch();

# Check diagnostic outputs
is_deeply(
\@notes,
[split(/\n/,
"->new_fetch()
Retrieving the some page: [http://foo/bar]
Retrieved the some page : [/foo/bar]
is_success() returned true"
)],
"Output as expected from new_fetch"
);

# Check action outputs
is_deeply(
\@mech_actions,
[
[ get => 'http://foo/bar' ],
[ 'success' ]
],
"Actions as expected from new_fetch"
);
}

0 comments on commit a199466

Please sign in to comment.