File Coverage

blib/lib/KelpX/Symbiosis/Test.pm
Criterion Covered Total %
statement 17 17 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod 1 2 50.0
total 26 28 92.8


line stmt bran cond sub pod time code
1             package KelpX::Symbiosis::Test;
2              
3             our $VERSION = '1.10';
4              
5 5     5   598169 use Kelp::Base;
  5         60142  
  5         37  
6 5     5   3395 use Kelp::Test;
  5         243005  
  5         40  
7              
8             attr "-app" => sub { die "`app` parameter is required" };
9              
10             sub wrap
11             {
12 4     4 1 4437 my ($class, %args) = @_;
13 4         36 my $self = $class->new(%args);
14 4         55 return Kelp::Test->new(app => $self);
15             }
16              
17             sub run
18             {
19 17     17 0 64156 shift->app->run_all(@_);
20             }
21              
22             sub AUTOLOAD
23             {
24 17     17   294347 my ($self) = shift;
25              
26 17         45 my $func = our $AUTOLOAD;
27 17 100       471 return if $func =~ /::DESTROY$/;
28 13         83 $func =~ s/.*:://;
29              
30 13         48 my $method = $self->app->can($func);
31 13 50       113 die "Kelp cannot $func" unless $method;
32 13         33 $method->($self->app, @_);
33             }
34              
35             1;
36             __END__
37              
38             =head1 NAME
39              
40             KelpX::Symbiosis::Test - Allow testing symbiotic environments using Kelp::Test
41              
42             =head1 SYNOPSIS
43              
44             # in test file
45             use KelpX::Symbiosis::Test;
46              
47             my $t = KelpX::Symbiosis::Test->wrap(app => $kelp_app);
48              
49             # continue testing using $t, just like Kelp::Test
50              
51             =head1 DESCRIPTION
52              
53             This module allows testing Kelp apps with Symbiosis using L<Kelp::Test>. The problem with I<Kelp::Test> is that it automatically runs I<run()> on the app without any way to configure this behavior. Symbiotic apps use I<run_all()> to run the whole environment, while I<run()> stays the same and only runs Kelp. This module replaces those two methods and autoloads the rest of the methods from Kelp instance.
54              
55             =head1 USAGE
56              
57             =head2 wrap
58              
59             I<new in 1.10>
60              
61             Instead of using I<Kelp::Test::new> use I<KelpX::Symbiosis::Test::wrap> with the same interface. Then you can create test cases not only for Kelp routes but also for the rest of Plack applications. The I<wrap> method will return a L<Kelp::Test> object, so refer to its documentation for more details.
62              
63             =head1 HOW DOES IT WORK?
64              
65             The main Kelp instance is wrapped in this module class and the resulting object is passed into Kelp::Test instead. I<KelpX::Symbiosis::Test> autoloads Kelp methods and wraps I<run_all> inside I<run>, which allows L<Kelp::Test> to use it.