Permalink
Browse files

convert the test to subtests

  • Loading branch information...
1 parent 41040e8 commit c61338d8e9f36b2a00a58508e4a6f77fdc5c3671 @petdance committed Apr 13, 2012
Showing with 39 additions and 25 deletions.
  1. +39 −25 t/scrape-text-by-id.t
View
64 t/scrape-text-by-id.t
@@ -12,38 +12,52 @@ use URI::file ();
use Test::WWW::Mechanize ();
subtest scrape_text_by_id => sub {
- plan tests => 12;
+ plan tests => 7;
my $mech = Test::WWW::Mechanize->new( autolint => 0 );
isa_ok( $mech, 'Test::WWW::Mechanize' );
my $uri = URI::file->new_abs( 't/goodlinks.html' )->as_string;
$mech->get_ok( $uri, 'Get a dummy page just to have one' );
- # nothing to find
- $mech->update_html( '<html><head><title></title></head><body></body></html>' );
- is_deeply( [$mech->scrape_text_by_id('asdf')], [], 'not found: empty list returned in list context' );
- is( $mech->scrape_text_by_id('asdf'), undef, 'not found: undef returned in scalar context' );
-
- # find one
- $mech->update_html( '<html><head><title></title></head><body><p id="asdf">contents</p></body></html>' );
- is_deeply( [$mech->scrape_text_by_id('asdf')], ['contents'], 'find one: list context' );
- is( $mech->scrape_text_by_id('asdf'), 'contents', 'find one: scalar context' );
-
- # find multiple
- $mech->update_html( '<html><head><title></title></head><body><p id="asdf">contents</p><p id="asdf">further</p></body></html>' );
- is_deeply( [$mech->scrape_text_by_id('asdf')], ['contents', 'further'], 'find multiple: empty list returned in list context' );
- is( $mech->scrape_text_by_id('asdf'), 'contents', 'find multiple: first string returned in scalar context' );
-
- # present but empty
- $mech->update_html( '<html><head><title></title></head><body><p id="asdf"></p></body></html>' );
- is_deeply( [$mech->scrape_text_by_id('asdf')], [''], 'present but empty: list context' );
- is( $mech->scrape_text_by_id('asdf'), '', 'present but empty: scalar context' );
-
- # present but emptier
- $mech->update_html( '<html><head><title></title></head><body><p id="asdf" /></body></html>' );
- is_deeply( [$mech->scrape_text_by_id('asdf')], [''], 'present but emptier: list context' );
- is( $mech->scrape_text_by_id('asdf'), '', 'present but emptier: scalar context' );
+ subtest 'nothing to find' => sub {
+ plan tests => 2;
+ $mech->update_html( '<html><head><title></title></head><body></body></html>' );
+
+ is_deeply( [$mech->scrape_text_by_id( 'asdf' )], [], 'empty list returned in list context' );
+ is( $mech->scrape_text_by_id( 'asdf' ), undef, 'undef returned in scalar context' );
+ };
+
+ subtest 'find one' => sub {
+ plan tests => 2;
+ $mech->update_html( '<html><head><title></title></head><body><p id="asdf">contents</p></body></html>' );
+ is_deeply( [$mech->scrape_text_by_id( 'asdf' )], ['contents'], 'list context' );
+ is( $mech->scrape_text_by_id( 'asdf' ), 'contents', 'scalar context' );
+ };
+
+ subtest 'find multiple' => sub {
+ plan tests => 2;
+
+ $mech->update_html( '<html><head><title></title></head><body><p id="asdf">contents</p><p id="asdf">further</p></body></html>' );
+ is_deeply( [$mech->scrape_text_by_id( 'asdf' )], ['contents', 'further'], 'empty list returned in list context' );
+ is( $mech->scrape_text_by_id( 'asdf' ), 'contents', 'first string returned in scalar context' );
+ };
+
+ subtest 'present but empty' => sub {
+ plan tests => 2;
+
+ $mech->update_html( '<html><head><title></title></head><body><p id="asdf"></p></body></html>' );
+ is_deeply( [$mech->scrape_text_by_id( 'asdf' )], [''], 'list context' );
+ is( $mech->scrape_text_by_id( 'asdf' ), '', 'scalar context' );
+ };
+
+ subtest 'present but emptier' => sub {
+ plan tests => 2;
+
+ $mech->update_html( '<html><head><title></title></head><body><p id="asdf" /></body></html>' );
+ is_deeply( [$mech->scrape_text_by_id( 'asdf' )], [''], 'list context' );
+ is( $mech->scrape_text_by_id( 'asdf' ), '', 'scalar context' );
+ };
};
done_testing();

0 comments on commit c61338d

Please sign in to comment.