File Coverage

blib/lib/RapidApp/Test.pm
Criterion Covered Total %
statement 56 57 98.2
branch 2 2 100.0
condition 2 3 66.6
subroutine 16 17 94.1
pod 0 5 0.0
total 76 84 90.4


line stmt bran cond sub pod time code
1             package RapidApp::Test;
2 4     4   2447414 use base 'Catalyst::Test';
  4         10  
  4         1652  
3              
4 4     4   129059 use strict;
  4         14  
  4         72  
5 4     4   18 use warnings;
  4         7  
  4         87  
6 4     4   2286 use Import::Into;
  4         1623  
  4         112  
7              
8 4     4   495 use Time::HiRes qw(gettimeofday tv_interval);
  4         1195  
  4         34  
9 4     4   2159 use HTTP::Request::Common;
  4         7301  
  4         227  
10 4     4   2679 use JSON qw(decode_json);
  4         30576  
  4         22  
11 4     4   472 use Catalyst::Utils;
  4         22  
  4         82  
12 4     4   1827 use RapidApp::Test::Client;
  4         16  
  4         511  
13              
14             my $target;
15             my $app_class;
16              
17             sub import {
18 4     4   38 $target = caller;
19 4         11 my ($self, $class, @args) = @_;
20            
21             # Since apps might take a while to start-up:
22 4         41 pass("[RapidApp::Test]: loading testapp '$class'...");
23            
24 4         1927 my $start = [gettimeofday];
25            
26 4         20 require_ok($class);
27 4         3836 Catalyst::Test->import::into($target,$class,@args);
28            
29             my @funcs = grep {
30 4 100       4658 $_ ne 'import' && $_ ne 'AUTOLOAD'
  28         4648  
31             } Class::MOP::Class->initialize(__PACKAGE__)->get_method_list;
32            
33             # Manually export our functions:
34             {
35 4     4   28 no strict 'refs';
  4         9  
  4         1655  
  4         10  
36 4         11 *{ join('::',$target,$_) } = \*{ $_ } for (@funcs);
  20         93  
  20         40  
37             }
38            
39             ok(
40 4   66     27 $class->setup_finished || $class->setup,
41             sprintf("$class loaded/started (%0.4f seconds)",tv_interval($start))
42             );
43            
44 4         37457 $app_class = $class;
45             };
46              
47             our $AUTOLOAD;
48             sub AUTOLOAD {
49 82     82   1784 my $method = (reverse(split('::',$AUTOLOAD)))[0];
50 82         779 $target->can($method)->(@_);
51             }
52              
53             ## Setup the "client" object
54 88     88 0 17097 my $Client; sub client { $Client }
55             $Client = RapidApp::Test::Client->new({ request_caller => sub {
56             my $req = shift;
57             ok(
58             my $res = client->record_response( request($req) ),
59             client->describe_request
60             );
61             return $res;
62             }});
63             ##
64              
65 6     6 0 157 sub app_class { $app_class }
66 3     3 0 12 sub app_version { eval(join('','$',app_class(),'::VERSION')) }
67 0     0 0 0 sub app_prefix { Catalyst::Utils::appprefix(app_class()) }
68              
69             # These are tests which should pass for all RapidApp applications:
70             # TODO: refactor into Test::Client
71             sub run_common_tests {
72              
73 3     3 0 456 ok($RapidApp::VERSION, 'RapidApp $VERSION ('.$RapidApp::VERSION.')');
74            
75 3         1596 my $ver = app_version;
76 3         12 ok($ver, 'App (' . app_class(). ') $VERSION ('.$ver.')');
77              
78 3         852 action_ok(
79             '/assets/rapidapp/misc/static/images/rapidapp_powered_logo_tiny.png',
80             "Fetched RapidApp logo from the Misc asset controller"
81             );
82            
83 3         4055 action_ok(
84             '/any/prefix/path/_ra-rel-mnt_/assets/rapidapp/misc/static/images/rapidapp_powered_logo_tiny.png',
85             "Fetched RapidApp logo from the Misc asset controller (via _ra-rel-mnt_)"
86             );
87              
88 3         4013 action_notfound(
89             '/assets/rapidapp/misc/static/some/bad/file.txt',
90             "Invalid asset path not found as expected"
91             );
92            
93 3         1388 action_notfound(
94             '/any/prefix/path/_ra-rel-mnt_/assets/rapidapp/misc/static/some/bad/file.txt',
95             "Invalid asset path not found as expected (via _ra-rel-mnt_)"
96             );
97              
98             }
99              
100              
101             1;