From 810c1b9cec08e7999a2c88b05f177d04792f1558 Mon Sep 17 00:00:00 2001 From: Andy Lester Date: Tue, 5 Jul 2011 14:55:52 -0500 Subject: [PATCH] fixing content_contains bummres --- Mechanize.pm | 13 +++++++------ t/content_contains.t | 10 ++++++++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Mechanize.pm b/Mechanize.pm index 9d1b91f..63e4806 100644 --- a/Mechanize.pm +++ b/Mechanize.pm @@ -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); @@ -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); @@ -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 ); diff --git a/t/content_contains.t b/t/content_contains.t index 76216f6..04c10e6 100644 --- a/t/content_contains.t +++ b/t/content_contains.t @@ -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; @@ -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' ); @@ -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: "\x{0a} \x{0a} Test Page"...) );