X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fmulti_content_type.t;h=097dce9ed0072c0fea513268efd685ed04a7ada1;hb=71896b6e2ad0faf686bfab695a70b89ef15aac4f;hp=2748ebc3b15a239c80de837d8c65f2ff20cc42da;hpb=6bc863629dfa3bec1d938eb5a7af7ef68fd3849f;p=catagits%2FTest-WWW-Mechanize-Catalyst.git diff --git a/t/multi_content_type.t b/t/multi_content_type.t index 2748ebc..097dce9 100644 --- a/t/multi_content_type.t +++ b/t/multi_content_type.t @@ -7,15 +7,14 @@ my $PORT; BEGIN { $PORT = $ENV{TWMC_TEST_PORT} || 7357; - $ENV{CATALYST_SERVER} ||= "http://localhost:$PORT"; } -use Test::More tests => 6; +use Test::More; use Test::Exception; BEGIN { diag( - "###################################################################\n", + "\n###################################################################\n", "Starting an external Catalyst HTTP server on port $PORT\n", "To change the port, please set the TWMC_TEST_PORT env variable.\n", "(The server will be automatically shut-down right after the tests).\n", @@ -27,23 +26,51 @@ BEGIN { $SIG{INT} = sub { warn "INT:$$"; exit }; use_ok 'ExternalCatty'; -my $pid = ExternalCatty->background($PORT); +my $pid; +($pid, $PORT) = ExternalCatty->background($PORT); +$ENV{CATALYST_SERVER} ||= "http://localhost:$PORT"; -use Test::WWW::Mechanize::Catalyst 'ExternalCatty'; +use Test::WWW::Mechanize::Catalyst; my $m = Test::WWW::Mechanize::Catalyst->new; -lives_ok { $m->get_ok( '/', 'Get a multi Content-Type response' ) } -'Survive to a multi Content-Type sting'; +# Yeah, sorry - wait for the forked process to spin up... +sleep 10; -is( $m->ct, 'text/html', 'Multi Content-Type Content-Type' ); -$m->title_is( 'Root', 'Multi Content-Type title' ); -$m->content_contains( "Hello, test \x{263A}!", 'Multi Content-Type body' ); +my $skip = 0; +TRY_CONNECT: { + eval { $m->get('/') }; + + if ($@ || $m->content =~ /Can't connect to \w+:$PORT/) { + $skip = $@ || $m->content; + diag $m; + } +} + +SKIP: { + skip $skip, 9 if $skip; + lives_ok { $m->get_ok( '/', 'Get a multi Content-Type response' ) } + 'Survive to a multi Content-Type sting'; + + is( $m->ct, 'text/html', 'Multi Content-Type Content-Type' ); + $m->title_is( 'Root', 'Multi Content-Type title' ); + $m->content_contains( "Hello, test \x{263A}!", 'Multi Content-Type body' ); + + # Test a redirect with a remote server now too. + $m->get_ok( '/hello' ); + is($m->uri, "$ENV{CATALYST_SERVER}/"); + + $m->get_ok( '/host' ); + $m->content_contains('Host: localhost:$PORT') or diag $m->content; + +} END { - if ( $pid > 0 ) { + if ( $pid && $pid != 0 ) { kill 9, $pid; } } +done_testing; + 1;