5 use lib "$FindBin::Bin/../lib";
7 use Test::More tests => 14;
8 use Catalyst::Test 'TestApp';
12 my $uri_base = 'http://localhost/priorities';
16 'Local vs. Path 1', { path => '/loc_vs_path1', expect => 'local' },
17 'Local vs. Path 2', { path => '/loc_vs_path2', expect => 'path' },
20 'index vs. Local', { path => '/loc_vs_index', expect => 'index' },
21 'index vs. Path', { path => '/path_vs_index', expect => 'index' },
23 'multimethod zero', { path => '/multimethod', expect => 'zero' },
24 'multimethod one', { path => '/multimethod/1', expect => 'one 1' },
25 'multimethod two', { path => '/multimethod/1/2',
26 expect => 'two 1 2' },
31 my $name = shift @tests;
32 my $data = shift @tests;
34 # Run tests for path with trailing slash and without
37 join( '' => $uri_base, $data->{ path } ), # Without trailing path
38 join( '' => $uri_base, $data->{ path }, '/' ), # With trailing path
40 my $end_slash = ( $req_uri =~ qr(/$) ? 1 : 0 );
42 # use slash_expect argument if URI ends with slash
43 # and the slash_expect argument is defined
44 my $expect = $data->{ expect } || '';
45 if ( $end_slash and exists $data->{ slash_expect } ) {
46 $expect = $data->{ slash_expect };
49 # Call the URI on the TestApp
50 my $response = request( $req_uri );
52 # Leave expect out to see the result
54 skip 'Nothing expected, winner is ' . $response->content, 1;
57 # Show error if response was no success
58 if ( not $response->is_success ) {
59 diag 'Error: ' . $response->headers->{ 'x-catalyst-error' };
62 # Test if content matches expectations.
63 # TODO This might flood the screen with the catalyst please-come-later
64 # page. So I don't know it is a good idea.
65 is( $response->content, $expect,
66 "$name: @{[ $data->{ expect } ]} wins"
67 . ( $end_slash ? ' (trailing slash)' : '' )