X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fsub-dispatch-args.t;h=71fc4eba44d5f72c42ebfb752037202d0e5c0a5e;hb=24ecd3bd2cf188c1909b62228a55dd6b5eca3d2e;hp=c4b6530a39ec17117b7ad214d2cab8b6264bd069;hpb=69aaa28a5f4d0ed129aae1c4f8a1bf98684a73df;p=catagits%2FWeb-Simple.git diff --git a/t/sub-dispatch-args.t b/t/sub-dispatch-args.t index c4b6530..71fc4eb 100644 --- a/t/sub-dispatch-args.t +++ b/t/sub-dispatch-args.t @@ -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'; @@ -37,6 +34,7 @@ use Test::More ( sub show_landing { my ($self, @args) = @_; local $self->{_dispatcher}; + local $args[-1]->{'Web::Dispatch.original_env'}; return [ 200, ['Content-Type' => 'application/perl' ], [::Dumper \@args], @@ -45,6 +43,7 @@ use Test::More ( sub show_users { my ($self, @args) = @_; local $self->{_dispatcher}; + local $args[-1]->{'Web::Dispatch.original_env'}; return [ 200, ['Content-Type' => 'application/perl' ], [::Dumper \@args], @@ -53,6 +52,7 @@ use Test::More ( sub show_user { my ($self, @args) = @_; local $self->{_dispatcher}; + local $args[-1]->{'Web::Dispatch.original_env'}; return [ 200, ['Content-Type' => 'application/perl' ], [::Dumper \@args], @@ -61,6 +61,7 @@ use Test::More ( sub process_post { my ($self, @args) = @_; local $self->{_dispatcher}; + local $args[-1]->{'Web::Dispatch.original_env'}; return [ 200, ['Content-Type' => 'application/perl' ], [::Dumper \@args], @@ -71,35 +72,28 @@ use Test::More ( 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; -} - -use HTTP::Request::Common qw(GET POST); +sub run_request { $app->run_test_request(@_); } -ok my $get_landing = run_request(GET 'http://localhost/' ), +ok my $get_landing = run_request(GET => 'http://localhost/' ), 'got landing'; -cmp_ok $get_landing->code, '==', 200, +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'), +ok my $get_users = run_request(GET => 'http://localhost/user'), 'got user'; -cmp_ok $get_users->code, '==', 200, +cmp_ok $get_users->code, '==', 200, '200 on GET'; { @@ -107,13 +101,12 @@ 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'), +ok my $get_user = run_request(GET => 'http://localhost/user/42'), 'got user'; -cmp_ok $get_user->code, '==', 200, +cmp_ok $get_user->code, '==', 200, '200 on GET'; { @@ -121,13 +114,12 @@ 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'] ), +ok my $post_user = run_request(POST => 'http://localhost/user/42', [id => '99'] ), 'post user'; -cmp_ok $post_user->code, '==', 200, +cmp_ok $post_user->code, '==', 200, '200 on POST'; { @@ -137,6 +129,4 @@ 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'; } -