Skip to content

Commit

Permalink
Don't make assumptions in tests about what's happening on port 80
Browse files Browse the repository at this point in the history
Fixes #276
  • Loading branch information
oalders committed May 22, 2020
1 parent 05524a8 commit d6393fa
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Revision history for WWW::Mechanize

{{$NEXT}}
- Don't make assumptions about port 80 in test (GH#299) (Olaf Alders)

1.97 2020-05-14 00:46:53Z
- Respect CDATA[[ sections when parsing HTML (GH#298) (Max Maischein)
Expand Down
26 changes: 15 additions & 11 deletions t/history.t
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
#!perl -T
#!perl

use warnings;
use strict;
use Test::More;

use lib qw( t/local );

use LocalServer ();
use Path::Tiny qw( path );
use Test::Deep;
use Test::Fatal;
use URI::file;
use Test::More;
use URI::file ();
use WWW::Mechanize ();

BEGIN {
delete @ENV{qw(PATH IFS CDPATH ENV BASH_ENV)}
Expand Down Expand Up @@ -118,22 +124,20 @@ BEGIN {
}

{
my $html = path('t/history_2.html')->slurp;
my $server = LocalServer->spawn( html => $html );
my $mech = WWW::Mechanize->new( cookie_jar => undef, autocheck => 0 );
isa_ok( $mech, 'WWW::Mechanize' );
$mech->get( $server->url );

my $uri = URI::file->new_abs('t/history_2.html')->as_string;

$mech->get($uri);
ok(
$mech->submit_form( form_name => "post_form" ),
"Submit form using 'post' method"
);
is( $mech->history_count, 2, "... and it was recorded in the history" );
like(
$mech->history(0)->{req}->uri, qr/localhost/,
is(
$mech->history(0)->{req}->uri, $server->url,
"... and the correct request was saved"
);

}

{
Expand All @@ -160,4 +164,4 @@ BEGIN {

}

done_testing();
done_testing();
2 changes: 1 addition & 1 deletion t/history_2.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<form action="history_3.html" method="get" name="get_form">
<input type="Submit" name="submit"/>
</form>
<form action="http://localhost/" method="post" name="post_form">
<form action="" method="post" name="post_form">
<input type="Submit" name="submit"/>
</form>
</body>
Expand Down

0 comments on commit d6393fa

Please sign in to comment.