b0VIM 7.3      Q=V2 &  davidp                                  supernova                               ~davidp/dev/github/Dancer/lib/Dancer/Test.pm                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       3210#"! U                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     tp                r         e   
     {   o     g        V   Q                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             ad     x                    z  g  A  @  6  #                r  \  G  3                          p  Y  X  B  *                n  m  [  Z  N  K  J  =              q  K  J  %  
  
  
  
  
  {
  X
  W
  8
  
  	  	  	  	  	  	  	  l	  j	  i	  R	  =	  <	  	              r  q  3              Y  W  V  C  #            ^  	                G  F                `  K  &                T              y  x  w           $test_name ||= "response status is $status for " . _req_label($req);     my ($req, $status, $test_name) = @_; sub response_status_is {  }     );        reason  => 'Use response_status_is and check for status 404.',        feature => 'response_doesnt_exist',        fatal   => 1,     Dancer::Deprecation->deprecated( sub response_doesnt_exist {  }     );        reason  => 'Use response_status_isnt and check for status 404.'        feature => 'response_exists',        fatal   => 1,     Dancer::Deprecation->deprecated( sub response_exists {  # Response status  }     return $tb->ok(!defined(Dancer::App->find_route_through_apps($req)), $test_name);     $req = Dancer::Request->new_for_request($method => $path);      $test_name ||= "no route exists for $method $path";     my ($method, $path) = expand_req($req);      my $tb = Test::Builder->new;     my ($req, $test_name) = @_; sub route_doesnt_exist {  }     return $tb->ok(defined(Dancer::App->find_route_through_apps($req)), $test_name);     $req = Dancer::Request->new_for_request($method => $path);      $test_name ||= "a route exists for $method $path";     my ($method, $path) = expand_req($req);      my $tb = Test::Builder->new;     my ($req, $test_name) = @_; sub route_exists {  }     return ref $req eq 'ARRAY' ? @$req : ( 'GET', $req );     my $req = shift; sub expand_req {  }          :                                  "GET $req";          : ref $req eq 'ARRAY'            ? join( ' ', @$req )     return _isa($req, 'Dancer::Response') ? 'response object'      my $req = shift; sub _req_label {  }     return dancer_response( ref $req eq 'ARRAY' ? @$req : ( 'GET', $req ) );      return $req if _isa($req, 'Dancer::Response');     # already a response object      my $req = shift; sub _req_to_response {  }     return blessed $reference && $reference->isa($classname);     my ( $reference, $classname ) = @_; sub _isa {  # Route Registry  }     setting 'log'     => 'debug';     setting 'logger'  => 'capture';     # capture logs for testing      setting 'session' => 'simple';     # set a default session engine for tests      Dancer::Config->load;     Dancer::_init_script_dir($options{appdir});      $class->export_to_level(1, $class, @EXPORT);     my ($package, $script) = caller;      $ENV{'psgi.url_scheme'} = 'http';     $ENV{SERVER_PORT}       = 80;     $ENV{HTTP_HOST}         = 'localhost';     $ENV{SERVERNAME}        = 'localhost';     # mimic PSGI env      $options{appdir} ||= '.';     my ($class, %options) = @_; sub import {  );   read_logs    dancer_response    response_redirect_location_is   response_headers_include   response_headers_are_deeply   response_is_file    response_content_unlike   response_content_like   response_content_is_deeply   response_content_isnt   response_content_is    response_status_isnt   response_status_is    response_doesnt_exist   response_exists    route_doesnt_exist   route_exists @EXPORT = qw(  use vars '@EXPORT'; use base 'Exporter';  use Dancer::FileUtils qw(open_file); use Dancer::Config; use Dancer::Handler; use Dancer::Renderer; use Dancer::SharedData; use Dancer::Request::Upload; use Dancer::Request; use Dancer::Deprecation; use Dancer::App; use Dancer ':syntax', ':tests';  use Scalar::Util 'blessed'; use HTTP::Headers; use Carp;  use Test::More import => [ '!pass' ]; use Test::Builder; use warnings; use strict;  # test helpers for Dancer apps  #ABSTRACT: Test helpers to test a Dancer application package Dancer::Test; ad  2       V                     L        |  {  0          4        p  *  
  
  
  l
  &
  	  	  	  w	  v	  7	  6	      }  |  4              {  z  5                  s  9  2  1              }  |  m  l                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          =cut  L<Test::More>  =head1 SEE ALSO  This module has been written by Alexis Sukrieh <sukria@sukria.net>  =head1 AUTHOR  itself. This module is free software and is distributed under the same terms as Perl  =head1 LICENSE  See L<Dancer::Logger::Capture> for more details.      ];         { level => "error", message => "Put out the light." },     is_deeply read_logs, [      error "Put out the light.";      ];         { level => "debug",   message => "I like pie.", }         { level => "warning", message => "Danger!  Warning!" },     is_deeply read_logs, [      debug   "I like pie.";     warning "Danger!  Warning!";  For example:  last call to C<read_logs>. Returns an array ref of all log messages issued by the app since the      my $logs = read_logs;  =head2 read_logs      });         files => [{name => 'test', filename => "filename.ext", data => $data}]     $response = dancer_response(POST => '/upload', {     my $data  = 'A test string that will pretend to be file contents.';  In addition, you can supply the file contents as the C<data> key:      $response = dancer_response(POST => '/upload', {files => [{name => 'image', filename => '/path/to/image.jpg'}]});      post '/upload' => sub { return upload('image')->content };  It's possible to test file uploads:          "response content looks good for second POST /widgets";     is $response->{content}, "Widget #2 has been scheduled for creation",     is $response->{status}, 202, "response for POST /widgets is 202";     $response = dancer_response POST => '/widgets';          "response content looks good for first POST /widgets";     is $response->{content}, "Widget #1 has been scheduled for creation",     is $response->{status}, 202, "response for POST /widgets is 202";     my $response = dancer_response POST => '/widgets';  state of the application and cause Schrodinger's cat to die. functions in succession would make two requests, each of which could alter the status in one shot. Calling the response_status_is and response_content_is requests may not be idempotent, it is necessary to capture the content and A good reason to use this function is for testing POST requests. Since POST  passed in the same call. Currently, Dancer::Test cannot cope with both I<< body >> and I<< files >>  always populates the request body. $params always populates the query string, even for POST requests.  $body  a L<< HTTP::Headers >> object, $files is an arrayref of hashref, containing some files to upload. $params is a hashref, $body can be a string or a hashref and $headers can be an arrayref or  Only $method and $path are required.  Returns a L<< Dancer::Response >> object for the given request.  =head2 dancer_response($method, $path, { params => $params, body => $body, headers => $headers, files => [{filename => '/path/to/file', name => 'my_file'}] })      response_redirect_location_is [GET => '/'], 'http://localhost/index.html';  