Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Made okay.t run multiple tests against the server.

This eases my paranoia somewhat; the server can handle multiple requests, not
one-and-done.
  • Loading branch information...
commit 3b64c1cfd8a49c31958a559dd0cb811909e22ff9 1 parent 488f806
@chromatic authored
Showing with 34 additions and 25 deletions.
  1. +34 −25 t/okay.t
View
59 t/okay.t
@@ -25,30 +25,39 @@ my $app = sub
return [ $code, [ 'Content-Type' => 'text/plain' ], [ $output ] ];
};
-my $agent = Plack::Test::Agent->new( app => $app );
-my $res = $agent->get( '/?have=foo;want=foo' );
-ok $res->is_success, 'Request should succeed when values match';
-is $res->decoded_content, 'ok', '... with descriptive success message';
-
-$res = $agent->get( '/?have=10;want=20' );
-ok ! $res->is_success, 'Request should fail when values do not match';
-is $res->decoded_content, 'not ok', '... with descriptive error';
-
-my $uri = URI->new( '/' );
-$uri->query_form( have => 'cow', want => 'cow', desc => 'Cow Comparison' );
-$res = $agent->get( $uri );
-
-ok $res->is_success, 'Request should succeed when values do';
-is $res->decoded_content, 'ok - Cow Comparison',
- '... including description when provided';
-is $res->content_type, 'text/plain', '... with plain text content';
-is $res->content_charset, 'US-ASCII', '... in ASCII';
-
-$res = $agent->post( '/', [ have => 'cow', want => 'pig', desc => 'æ' ] );
-ok ! $res->is_success, 'Request should fail given different values';
-is $res->decoded_content, "not ok - \x{00E6}",
- '... including description when provided';
-is $res->content_type, 'text/plain', '... with plain text content';
-is $res->content_charset, 'UTF-8', '... in ASCII';
+my $bare_agent = Plack::Test::Agent->new( app => $app );
+my $server_agent = Plack::Test::Agent->new( app => $app,
+ server => 'HTTP::Server::PSGI' );
+run_tests_with_agent( $bare_agent );
+run_tests_with_agent( $server_agent );
+
+sub run_tests_with_agent
+{
+ my $agent = shift;
+ my $res = $agent->get( '/?have=foo;want=foo' );
+ ok $res->is_success, 'Request should succeed when values match';
+ is $res->decoded_content, 'ok', '... with descriptive success message';
+
+ $res = $agent->get( '/?have=10;want=20' );
+ ok ! $res->is_success, 'Request should fail when values do not match';
+ is $res->decoded_content, 'not ok', '... with descriptive error';
+
+ my $uri = URI->new( '/' );
+ $uri->query_form( have => 'cow', want => 'cow', desc => 'Cow Comparison' );
+ $res = $agent->get( $uri );
+
+ ok $res->is_success, 'Request should succeed when values do';
+ is $res->decoded_content, 'ok - Cow Comparison',
+ '... including description when provided';
+ is $res->content_type, 'text/plain', '... with plain text content';
+ is $res->content_charset, 'US-ASCII', '... in ASCII';
+
+ $res = $agent->post( '/', [ have => 'cow', want => 'pig', desc => 'æ' ] );
+ ok ! $res->is_success, 'Request should fail given different values';
+ is $res->decoded_content, "not ok - \x{00E6}",
+ '... including description when provided';
+ is $res->content_type, 'text/plain', '... with plain text content';
+ is $res->content_charset, 'UTF-8', '... in ASCII';
+}
done_testing;

0 comments on commit 3b64c1c

Please sign in to comment.
Something went wrong with that request. Please try again.