CGI-Application-Dispatch

 view release on metacpan or  search on metacpan

t/psgi.t  view on Meta::CPAN

# make sure we can get to our modules
use lib 't/lib';
use Test::More 'no_plan';
use Plack::Test;
use HTTP::Request::Common;
use CGI::Application::Dispatch::PSGI;
use Module::Name;
use MyApp::Module::Name;
use MyApp::DispatchPSGI;
use MyApp::DispatchTablePSGI;

my $output = '';

# to capture and junk STDERR
my $junk;
{
    no strict;
    open SAVE_ERR, ">&STDERR";
    close STDERR;
    open STDERR, ">", \$junk
      or warn "Could not redirect STDERR?\n";

}

  # module name
  test_psgi
      app => CGI::Application::Dispatch::PSGI->as_psgi,
      client => sub {
              my $cb = shift;
              my $res = $cb->(GET "/module_name/rm1");
              like($res->content, qr/\QModule::Name->rm1/, 'as_psgi(): module_name');
      };
  
  # prefix
  test_psgi
       app => CGI::Application::Dispatch::PSGI->as_psgi(prefix => 'MyApp'),
       client => sub {
           my $cb = shift;
           my $res = $cb->(GET '/module_name/rm2');
           like($res->content, qr/\QMyApp::Module::Name->rm2/, 'as_psgi(): prefix');
       };
  
  # extra things passed to dispatch() get passed into new()
  # Not supported anymore.
  # test_psgi
  #     app => CGI::Application::Dispatch::PSGI->as_psgi(
  #         prefix => 'MyApp',
  #         PARAMS => {my_param => 'testing'},
  #     ),
  #     client => sub {
  #         my $cb = shift;
  #         my $res = $cb->(GET '/module_name/rm3');
  #         like($res->content, qr/\QMyApp::Module::Name->rm3 my_param=testing/, 'PARAMS passed through')
  #     };
  
  
  # use default, with shortcut name
  test_psgi
      app => CGI::Application::Dispatch::PSGI->as_psgi(
          prefix  => 'MyApp',
          default => '/module_name/rm2'),
      client => sub {
          my $cb = shift;
          my $res = $cb->(GET '');
          like($res->content,qr/\QMyApp::Module::Name->rm2/, 'default, with shortcut name');



( run in 1.312 second using v1.01-cache-2.11-cpan-3c2a17b8caa )