Skip to content

Commit

Permalink
fixing content_contains bummres
Browse files Browse the repository at this point in the history
  • Loading branch information
petdance committed Jul 5, 2011
1 parent 06b33bf commit 810c1b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
13 changes: 7 additions & 6 deletions Mechanize.pm
Expand Up @@ -643,8 +643,9 @@ sub content_contains {
my $desc = shift;

local $Test::Builder::Level = $Test::Builder::Level + 1;
if ( ref($str) eq 'REGEX' ) {
diag( 'content_contains takes a string, not a regex' );

if ( ref($str) ) {
return $Test->ok( 0, 'Test::WWW::Mechanize->content_contains called incorrectly. It requires a scalar, not a reference.' );
}
$desc = qq{Content contains "$str"} if !defined($desc);

Expand All @@ -663,8 +664,8 @@ sub content_lacks {
my $desc = shift;

local $Test::Builder::Level = $Test::Builder::Level + 1;
if ( ref($str) eq 'REGEX' ) {
diag( 'content_lacks takes a string, not a regex' );
if ( ref($str) ) {
return $Test->ok( 0, 'Test::WWW::Mechanize->content_lacks called incorrectly. It requires a scalar, not a reference.' );
}
$desc = qq{Content lacks "$str"} if !defined($desc);

Expand Down Expand Up @@ -725,8 +726,8 @@ sub text_contains {
my $desc = shift || qq{Text contains "$str"};

local $Test::Builder::Level = $Test::Builder::Level + 1;
if ( ref($str) eq 'REGEX' ) {
diag( 'text_contains takes a string, not a regex' );
if ( ref($str) ) {
return $Test->ok( 0, 'Test::WWW::Mechanize->text_contains called incorrectly. It requires a scalar, not a reference.' );
}

return contains_string( $self->content(format => "text"), $str, $desc );
Expand Down
10 changes: 8 additions & 2 deletions t/content_contains.t
Expand Up @@ -2,7 +2,7 @@

use strict;
use warnings;
use Test::More tests => 6;
use Test::More tests => 7;
use Test::Builder::Tester;
use URI::file;

Expand All @@ -16,7 +16,12 @@ isa_ok( $mech,'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/goodlinks.html' )->as_string;
$mech->get_ok( $uri );

# test regex
test_out( "not ok 1 - Test::WWW::Mechanize->content_contains called incorrectly. It requires a scalar, not a reference." );
test_fail( +1 );
$mech->content_contains( qr/foo/, "Passing regex fails" );
test_test( "Passing regex fails" );

# test success
test_out( 'ok 1 - Does it say test page?' );
$mech->content_contains( 'Test Page', 'Does it say test page?' );
test_test( 'Finds the contains' );
Expand All @@ -26,6 +31,7 @@ test_out( 'ok 1 - Content contains "Test Page"' );
$mech->content_contains( 'Test Page');
test_test( 'Finds the contains - default desc' );

# test failure
test_out( 'not ok 1 - Where is Mungo?' );
test_fail(+5);
test_diag(q( searched: "<html>\x{0a} <head>\x{0a} <title>Test Page</title>"...) );
Expand Down

0 comments on commit 810c1b9

Please sign in to comment.