eliminate HTTP::Request::AsCGI in favour of Plack::Test
Matt S Trout [Mon, 3 Oct 2011 11:43:45 +0000 (11:43 +0000)]
Changes
lib/Web/Simple/Application.pm
t/env.t
t/post.t
t/sub-dispatch-args.t

diff --git a/Changes b/Changes
index f86d70c..83e0959 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
 Change log for Web::Simple
 
+  - Complete port from HTTP::Request::AsCGI to Plack::Test
   - Add experimental upload support
   - Update Plack usage to call ::Handler:: classes not ::Server::
   - Assume FastCGI mode if STDIN is a socket (works some places env vars fail)
index 8382116..a6b1df4 100644 (file)
@@ -269,12 +269,7 @@ calls ->new, or as an object method ... in which case it doesn't.
 
 =head2 run
 
-Used for running your application under stand-alone CGI and FCGI modes. Also
-useful for testing:
-
-    my $app = MyWebSimpleApp::Web->new;
-    my $c = HTTP::Request::AsCGI->new(@args)->setup;
-    $app->run;
+Used for running your application under stand-alone CGI and FCGI modes.
 
 =head1 AUTHORS
 
diff --git a/t/env.t b/t/env.t
index d566671..47bde37 100644 (file)
--- a/t/env.t
+++ b/t/env.t
@@ -1,11 +1,8 @@
 use strict;
 use warnings FATAL => 'all';
 
-use Test::More (
-  eval { require HTTP::Request::AsCGI }
-    ? 'no_plan'
-    : (skip_all => 'No HTTP::Request::AsCGI')
-);
+use Test::More 'no_plan';
+use Plack::Test;
 
 {
   use Web::Simple 'EnvTest';
@@ -27,10 +24,7 @@ my $app = EnvTest->new;
 
 sub run_request {
   my $request = shift;
-  my $c = HTTP::Request::AsCGI->new($request)->setup;
-  $app->run;
-  $c->restore;
-  return $c->response;
+  return test_psgi $app->to_psgi_app, sub { shift->($request) };
 }
 
 ok run_request(GET 'http://localhost/')->is_success;
index 3390f63..805e57b 100644 (file)
--- a/t/post.t
+++ b/t/post.t
@@ -30,10 +30,7 @@ my $app = PostTest->new;
 
 sub run_request {
   my $request = shift;
-  my $response = test_psgi($app->to_psgi_app, sub {
-    shift->($request);
-  });
-  return $response;
+  return test_psgi $app->to_psgi_app, sub { shift->($request) };
 }
 
 my $get = run_request(GET 'http://localhost/');
index c4b6530..c68b059 100644 (file)
@@ -2,11 +2,8 @@ use strict;
 use warnings FATAL => 'all';
 
 use Data::Dumper::Concise;
-use Test::More (
-  eval { require HTTP::Request::AsCGI }
-    ? 'no_plan'
-    : (skip_all => 'No HTTP::Request::AsCGI')
-);
+use Test::More 'no_plan';
+use Plack::Test;
 
 {
     use Web::Simple 't::Web::Simple::SubDispatchArgs';
@@ -72,11 +69,8 @@ ok my $app = t::Web::Simple::SubDispatchArgs->new,
   'made app';
 
 sub run_request {
-  my @args = (shift, SCRIPT_NAME=> $0);
-  my $c = HTTP::Request::AsCGI->new(@args)->setup;
-  $app->run;
-  $c->restore;
-  return $c->response;
+  my $request = shift;
+  return test_psgi $app->to_psgi_app, sub { shift->($request) };
 }
 
 use HTTP::Request::Common qw(GET POST);
@@ -87,13 +81,14 @@ ok my $get_landing = run_request(GET 'http://localhost/' ),
 cmp_ok $get_landing->code, '==', 200, 
   '200 on GET';
 
+no strict 'refs';
+
 {
-    my ($self, $env, @noextra) = @{eval $get_landing->content};
+    my ($self, $env, @noextra) = @{eval($get_landing->content)||[]};
     die $@ if $@;
     is scalar(@noextra), 0, 'No extra stuff';
     is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
     is ref($env), 'HASH', 'Got hashref';
-    is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
 }
 
 ok my $get_users = run_request(GET 'http://localhost/user'),
@@ -107,7 +102,6 @@ cmp_ok $get_users->code, '==', 200,
     is scalar(@noextra), 0, 'No extra stuff';
     is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
     is ref($env), 'HASH', 'Got hashref';
-    is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
 }
 
 ok my $get_user = run_request(GET 'http://localhost/user/42'),
@@ -121,7 +115,6 @@ cmp_ok $get_user->code, '==', 200,
     is scalar(@noextra), 0, 'No extra stuff';
     is ref($self), 't::Web::Simple::SubDispatchArgs', 'got object';
     is ref($env), 'HASH', 'Got hashref';
-    is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
 }
 
 ok my $post_user = run_request(POST 'http://localhost/user/42', [id => '99'] ),
@@ -137,6 +130,5 @@ cmp_ok $post_user->code, '==', 200,
     is ref($params), 'HASH', 'Got POST hashref';
     is $params->{id}, 99, 'got expected value for id';
     is ref($env), 'HASH', 'Got hashref';
-    is $env->{SCRIPT_NAME}, $0, 'correct scriptname';
 }