Skip to content

Commit

Permalink
Fix brittle tests that rely on XPATH.
Browse files Browse the repository at this point in the history
  • Loading branch information
oalders committed Apr 16, 2015
1 parent 9cade8f commit 3f73766
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
11 changes: 8 additions & 3 deletions t/controller/pod.t
Expand Up @@ -5,23 +5,27 @@ use MetaCPAN::Web::Test;

test_psgi app, sub {
my $cb = shift;

ok( my $res = $cb->( GET '/pod/DOESNTEXIST' ), 'GET /pod/DOESNTEXIST' );
is( $res->code, 404, 'code 404' );
ok( $res = $cb->( GET '/pod/Moose' ), 'GET /pod/Moose' );
is( $res->code, 200, 'code 200' );

my $tx = tx($res);
$tx->like( '/html/head/title', qr/Moose/, 'title includes Moose' );
ok( $tx->find_value('//a[@href="/pod/Moose"]'),
'contains permalink to resource' );

ok(
my $this = $tx->find_value(
'//li[text()="Permalinks"]/following-sibling::li[1]/a[text()="This version"]/@href'
'//li[text()="Permalinks"]/following-sibling::li[2]/a[text()="This version"]/@href'
),
'contains link to "this" version'
);

my $latest = $res->content;
ok( $res = $cb->( GET $this ), "GET $this" );

my $tx2 = tx($res);
ok( $tx->find_value('//div[contains(@class, "content")]'),
'page has content' );
Expand All @@ -35,8 +39,9 @@ test_psgi app, sub {
( my $lc_this = $this )
=~ s{(/pod/release/)([^/]+)}{$1\L$2}; # lc author name
ok( $res = $cb->( GET $lc_this ), "GET $lc_this" );
is( $res->code, 301, 'code 301' );
is( $res->headers->header('location'), $this, 'redirect to original' );
is( $res->code, 301, '301 on lowercase author name' );
is( $res->headers->header('location'),
$this, 'redirect to uppercase author name' );
};

done_testing;
3 changes: 2 additions & 1 deletion t/controller/release.t
Expand Up @@ -19,6 +19,7 @@ test_psgi app, sub {

ok( $res = $cb->( GET '/release/Moose' ), 'GET /release/Moose' );
is( $res->code, 200, 'code 200' );

my $tx = tx($res);
$tx->like( '/html/head/title', qr/Moose/, 'title includes Moose' );
ok( $tx->find_value('//a[@href="/release/Moose"]'),
Expand All @@ -32,7 +33,7 @@ test_psgi app, sub {
# '//li[text()="Permalinks"]/following-sibling::li/a[text()="This version" and not(@rel="nofollow")]/@href'
ok(
my $this = $tx->find_value(
'//li[text()="Permalinks"]/following-sibling::li[1]/a[text()="This version"]/@href'
'//li[text()="Permalinks"]/following-sibling::li[2]/a[text()="This version"]/@href'
),
'contains link to "this" version'
);
Expand Down

0 comments on commit 3f73766

Please sign in to comment.