File Coverage

lib/Test/Mojo/Role/Routes.pm
Criterion Covered Total %
statement 11 57 19.3
branch n/a
condition 0 3 0.0
subroutine 4 19 21.0
pod 0 14 0.0
total 15 93 16.1


line stmt bran cond sub pod time code
1             package Test::Mojo::Role::Routes;
2              
3 1     1   66507 use strict;
  1         10  
  1         25  
4 1     1   22 use 5.008_005;
  1         3  
5             our $VERSION = '0.02';
6              
7 1     1   512 use Mojo::Base -role;
  1         178760  
  1         8  
8 1     1   532 use Mojo::Util qw(encode);
  1         3  
  1         909  
9              
10             ## make requests for named routes
11              
12             sub delete_route_ok {
13 0     0 0   my $self = shift;
14 0           my $route = shift;
15 0           return $self->delete_ok($self->app->url_for($route), @_);
16             }
17              
18             sub get_route_ok {
19 0     0 0   my $self = shift;
20 0           my $route = shift;
21 0           return $self->get_ok($self->app->url_for($route), @_);
22             }
23              
24             sub head_route_ok {
25 0     0 0   my $self = shift;
26 0           my $route = shift;
27 0           return $self->head_ok($self->app->url_for($route), @_);
28             }
29              
30             sub options_route_ok {
31 0     0 0   my $self = shift;
32 0           my $route = shift;
33 0           return $self->options_ok($self->app->url_for($route), @_);
34             }
35              
36             sub patch_route_ok {
37 0     0 0   my $self = shift;
38 0           my $route = shift;
39 0           return $self->patch_ok($self->app->url_for($route), @_);
40             }
41              
42             sub post_route_ok {
43 0     0 0   my $self = shift;
44 0           my $route = shift;
45 0           return $self->post_ok($self->app->url_for($route), @_);
46             }
47              
48             sub put_route_ok {
49 0     0 0   my $self = shift;
50 0           my $route = shift;
51 0           return $self->put_ok($self->app->url_for($route), @_);
52             }
53              
54             ## testing current url path and named route
55              
56             sub path_is {
57 0     0 0   my ($self, $path, $desc) = @_;
58 0           $desc = _desc($desc, 'url path '. $self->tx->req->url->path ." is $path");
59 0           return $self->test('is', $self->tx->req->url->path => $path, $desc);
60             }
61              
62             sub path_isnt {
63 0     0 0   my ($self, $path, $desc) = @_;
64 0           $desc = _desc($desc, 'url path '. $self->tx->req->url->path ." isn't $path");
65 0           return $self->test('ok', !($self->tx->req->url->path eq $path), $desc);
66             }
67              
68             sub path_like {
69 0     0 0   my ($self, $path, $desc) = @_;
70 0           $desc = _desc($desc, 'url path '. $self->tx->req->url->path ." like $path");
71 0           return $self->test('like', $self->tx->req->url->path => $path, $desc);
72             }
73              
74             sub path_unlike {
75 0     0 0   my ($self, $path, $desc) = @_;
76 0           $desc = _desc($desc, 'url path '. $self->tx->req->url->path ." unlike $path");
77 0           return $self->test('unlike', $self->tx->req->url->path => $path, $desc);
78             }
79              
80             sub path_starts_with {
81 0     0 0   my ($self, $path, $desc) = @_;
82 0           $desc = _desc($desc, 'url path '. $self->tx->req->url->path ." starts with $path");
83 0           my $length = length($path);
84 0           return $self->test('is', substr($self->tx->req->url->path, 0, $length) => $path, $desc);
85             }
86              
87             sub route_is {
88 0     0 0   my ($self, $route, $desc) = @_;
89 0           my $path = $self->app->url_for($route);
90 0           $desc = _desc($desc, 'url path '. $self->tx->req->url->path ." is route $route -> $path");
91 0           return $self->test('is', $self->tx->req->url->path => $path, $desc);
92             }
93              
94             sub route_isnt {
95 0     0 0   my ($self, $route, $desc) = @_;
96 0           my $path = $self->app->url_for($route);
97 0           $desc = _desc($desc, 'url path '. $self->tx->req->url->path ." isn't route $route -> $path");
98 0           return $self->test('ok', !($self->tx->req->url->path eq $path), $desc);
99             }
100              
101             # if no $desc is provided to test then use the default that each method defines
102 0   0 0     sub _desc { encode 'UTF-8', shift || shift }
103              
104             1;
105             __END__