changed type validation error to 404
[catagits/CatalystX-Declare.git] / t / 060_exception_handling.t
CommitLineData
392e5076 1#!/usr/bin/env perl
2use strict;
3use warnings;
4
5no warnings 'redefine';
6
7use FindBin;
8use lib "$FindBin::Bin/lib";
9
10use Test::More;
11use Test::Output;
12use Catalyst::Test 'TestApp';
13
14my $get = sub { get(join '/', '/errors/signature_error_on_foo', @_) };
15my $subget = sub { get(join '/', '/sub_errors/signature_error_on_foo', @_) };
16my $modget = sub { get(join '/', '/sub_errors/signature_error_on_foo_modify', @_) };
17
18
19local *TestApp::debug = sub { 0 };
20
67f39940 21is $get->('foo'), 'Not found', 'detected action signature error';
22is $subget->('foo'), 'Not found', 'detected action signature error (child)';
23is $modget->('foo'), 'Not found', 'detected action signature error (modified)';
392e5076 24
25stderr_like {
26
27 like $get->('bar'), qr/come back later/i, 'normal handling of method validation error';
28
29} qr/Validation failed/, 'method error throws validation error to error log';
30
31stderr_like {
32
33 like $subget->('bar'), qr/come back later/i, 'normal handling of method validation error (child)';
34
35} qr/Validation failed/, 'method error throws validation error to error log (child)';
36
37stderr_like {
38
39 like $modget->('bar'), qr/come back later/i, 'normal handling of method validation error (modified)';
40
41} qr/Validation failed/, 'method error throws validation error to error log (modified)';
42
43is $get->('baz'), 'FOO BAR', 'make sure all works without any errors happening';
44is $subget->('baz'), 'FOO BAR', 'make sure all works without any errors happening (child)';
45is $modget->('baz'), 'FOO_MODIFY BAR', 'make sure all works without any errors happening (child)';
46
47
48local *TestApp::debug = sub { 1 };
49
50stderr_like {
51
52 my $foo_err = $get->('foo');
53 like $foo_err, qr/BAD REQUEST: /, 'debug version of bad request error';
54 like $foo_err, qr/Validation failed/i, 'debug version of bad request contains error message';
55
56} qr/BAD REQUEST:.+Validation failed/i, 'debug output with bad request note and error message';
57
58stderr_like {
59
60 my $foo_err = $subget->('foo');
61 like $foo_err, qr/BAD REQUEST: /, 'debug version of bad request error (child)';
62 like $foo_err, qr/Validation failed/i, 'debug version of bad request contains error message (child)';
63
64} qr/BAD REQUEST:.+Validation failed/i, 'debug output with bad request note and error message (child)';
65
66stderr_like {
67
68 my $foo_err = $modget->('foo');
69 like $foo_err, qr/BAD REQUEST: /, 'debug version of bad request error (modified)';
70 like $foo_err, qr/Validation failed/i, 'debug version of bad request contains error message (modified)';
71
72} qr/BAD REQUEST:.+Validation failed/i, 'debug output with bad request note and error message (modified)';
73
74stderr_like {
75
76 my $bar_err = $get->('bar');
77 unlike $bar_err, qr/BAD REQUEST: /, 'debug version of method error contains no bad request note';
78 like $bar_err, qr/Validation failed/i, 'we got the right error message';
79
80} qr/Validation failed/i, 'error message reaches stdout';
81
82stderr_like {
83
84 my $bar_err = $subget->('bar');
85 unlike $bar_err, qr/BAD REQUEST: /, 'debug version of method error contains no bad request note (child)';
86 like $bar_err, qr/Validation failed/i, 'we got the right error message (child)';
87
88} qr/Validation failed/i, 'error message reaches stdout (child)';
89
90stderr_like {
91
92 my $bar_err = $modget->('bar');
93 unlike $bar_err, qr/BAD REQUEST: /, 'debug version of method error contains no bad request note (modified)';
94 like $bar_err, qr/Validation failed/i, 'we got the right error message (modified)';
95
96} qr/Validation failed/i, 'error message reaches stdout (modified)';
97
98stderr_unlike {
99
100 is $get->('baz'), 'FOO BAR', 'make sure all works without any errors happening in debug mode';
101
102} qr/\[error\]/i, 'no errors in output';
103
104stderr_unlike {
105
106 is $subget->('baz'), 'FOO BAR', 'make sure all works without any errors happening in debug mode (child)';
107
108} qr/\[error\]/i, 'no errors in output (child)';
109
110stderr_unlike {
111
112 is $modget->('baz'), 'FOO_MODIFY BAR', 'make sure all works without any errors happening in debug mode (modified)';
113
114} qr/\[error\]/i, 'no errors in output (modified)';
115
116
117done_testing;