@@ -6,7 +6,8 @@ use warnings qw(FATAL all NONFATAL misc);
6
6
use FindBin; BEGIN { do " $FindBin::Bin /t_lib.pl" }
7
7
# ----------------------------------------
8
8
9
- use Test::Kantan;
9
+ # use Test::Kantan;
10
+ use Test::More;
10
11
use File::Temp qw/ tempdir/ ;
11
12
12
13
use Plack::Request;
@@ -23,12 +24,27 @@ use Cwd;
23
24
24
25
use YATT::Lite::PSGIEnv;
25
26
27
+ {
28
+ package
29
+ t_call_tester;
30
+ sub new {
31
+ my ($pack , $app ) = @_ ;
32
+ bless [$app ], $pack ;
33
+ }
34
+
35
+ sub psgi_returns {
36
+ my ($self , $psgi , $expect , $it_should ) = @_ ;
37
+ my $got = $self -> [0]-> call($psgi );
38
+ Test::More::is_deeply($got , $expect , $it_should );
39
+ }
40
+ }
41
+
26
42
my $TEMPDIR = tempdir(CLEANUP => 1);
27
43
my $CWD = cwd();
28
44
my $TESTNO = 0;
29
45
my $CT = [" Content-Type" , q{ text/html; charset="utf-8"} ];
30
46
31
- my $TODO = $ENV {TEST_TODO };
47
+ my $TEST_TODO = $ENV {TEST_TODO };
32
48
33
49
# ----------------------------------------
34
50
@@ -60,11 +76,13 @@ my $with_or_without = sub {$_[0] ? "With" : "Without"};
60
76
61
77
foreach my $has_index (1, 0) {
62
78
63
- describe $with_or_without -> ($has_index )." index.yatt" , sub {
79
+ subtest $with_or_without -> ($has_index )." index.yatt" , sub {
64
80
65
- describe " foo.ydo" , sub {
81
+ subtest " foo.ydo" , sub {
66
82
my ($app_root , $html_dir , $site ) = $make_siteapp -> ($make_dirs -> ());
67
83
84
+ my $tester = t_call_tester-> new($site );
85
+
68
86
MY-> mkfile(" $html_dir /index.yatt" , <<'END' ) if $has_index ;
69
87
<h2>Hello</h2>
70
88
@@ -84,37 +102,38 @@ return sub {
84
102
};
85
103
END
86
104
87
- describe " request /foo.ydo" , sub {
105
+ subtest " request /foo.ydo" , sub {
88
106
my Env $psgi = (GET " /foo.ydo" )-> to_psgi;
89
107
90
- it " should invoke action in foo.ydo" , sub {
91
- expect($site -> call($psgi ))-> to_be([200, $CT , [" action in foo.ydo" ]]);
92
- };
108
+ $tester -> psgi_returns($psgi , [200, $CT , [" action in foo.ydo" ]]
109
+ , " it should invoke action in foo.ydo" );
93
110
};
94
111
95
112
# TODO:
96
113
if (1) {
97
- describe " request /foo" , sub {
114
+ subtest " request /foo" , sub {
98
115
my Env $psgi = (GET " /foo" )-> to_psgi;
99
116
100
- it " should invoke action in foo.ydo" , sub {
101
- expect($site -> call($psgi ))-> to_be([200, $CT , [" action in foo.ydo" ]]);
102
- };
117
+ $tester -> psgi_returns($psgi , [200, $CT , [" action in foo.ydo" ]]
118
+ , " it should invoke action in foo.ydo" );
103
119
};
104
120
}
105
121
106
122
if ($has_index ) {
107
- describe " request /bar (for sanity check)" , sub {
123
+ subtest " request /bar (for sanity check)" , sub {
108
124
my Env $psgi = (GET " /bar" )-> to_psgi;
109
125
110
- it " should invoke action bar in index.yatt" , sub {
111
- expect($site -> call($psgi ))-> to_be([200, $CT , [" action bar in index.yatt" ]]);
112
- };
126
+ $tester -> psgi_returns($psgi , [200, $CT , [" action bar in index.yatt" ]]
127
+ , " it should invoke action bar in index.yatt" );
113
128
};
114
129
}
115
130
};
116
131
117
- describe " Action in .htyattrc.pl" , sub {
132
+ TODO:
133
+ $TEST_TODO
134
+ and
135
+ subtest " Action in .htyattrc.pl" , sub {
136
+ local $TODO = $TEST_TODO ? undef : " Not yet solved" ;
118
137
my ($app_root , $html_dir ) = $make_dirs -> ();
119
138
120
139
make_path(my $tmpl_dir = " $app_root /ytmpl" );
@@ -140,31 +159,32 @@ Action foo => sub {
140
159
END
141
160
142
161
my $site = $make_siteapp -> ($app_root , $html_dir , app_base => ' @ytmpl' );
162
+ my $tester = t_call_tester-> new($site );
143
163
144
- if ($has_index or $TODO ) {
145
- describe " request /?!foo=1" , sub {
164
+ if ($has_index or $TEST_TODO ) {
165
+ subtest " request /?!foo=1" , sub {
146
166
my Env $psgi = (GET " /?!foo=1" )-> to_psgi;
147
167
148
- it " should invoke action foo in .htyattrc.pl" , sub {
149
- expect($site -> call($psgi ))-> to_be([200, $CT , [" action foo in .htyattrc.pl" ]]);
150
- };
168
+ $tester -> psgi_returns($psgi , [200, $CT , [" action foo in .htyattrc.pl" ]]
169
+ , " it should invoke action foo in .htyattrc.pl" );
151
170
};
152
171
}
153
172
154
- if ($TODO ) {
155
- describe " request /foo" , sub {
173
+ if ($TEST_TODO ) {
174
+ subtest " request /foo" , sub {
156
175
my Env $psgi = (GET " /foo" )-> to_psgi;
157
176
158
- it " should invoke action foo in .htyattrc.pl" , sub {
159
- expect($site -> call($psgi ))-> to_be([200, $CT , [" action foo in .htyattrc.pl" ]]);
160
- };
177
+ $tester -> psgi_returns($psgi , [200, $CT , [" action foo in .htyattrc.pl" ]]
178
+ , " it should invoke action foo in .htyattrc.pl" );
161
179
};
162
180
}
163
181
};
164
182
165
- ($has_index or $TODO )
183
+ TODO:
184
+ ($has_index )
166
185
and
167
- describe " site->mount_action(URL, subref)" , sub {
186
+ subtest " site->mount_action(URL, subref)" , sub {
187
+ local $TODO = $TEST_TODO ? undef : " Not yet solved" ;
168
188
my ($app_root , $html_dir ) = $make_dirs -> ();
169
189
170
190
make_path($html_dir );
@@ -177,6 +197,7 @@ page bar in index.yatt
177
197
END
178
198
179
199
my $site = $make_siteapp -> ($app_root , $html_dir , app_base => ' @ytmpl' );
200
+ my $tester = t_call_tester-> new($site );
180
201
181
202
$site -> mount_action(
182
203
' /foo' ,
@@ -186,22 +207,20 @@ END
186
207
}
187
208
);
188
209
189
- if ($TODO ) {
190
- describe " request /?!foo=1" , sub {
210
+ if ($TEST_TODO ) {
211
+ subtest " request /?!foo=1" , sub {
191
212
my Env $psgi = (GET " /?!foo=1" )-> to_psgi;
192
213
193
- it " should invoke action foo from mount_action" , sub {
194
- expect($site -> call($psgi ))-> to_be([200, $CT , [" action foo from mount_action" ]]);
195
- };
214
+ $tester -> psgi_returns($psgi , [200, $CT , [" action foo from mount_action" ]]
215
+ , " it should invoke action foo from mount_action" );
196
216
};
197
217
}
198
218
199
- describe " request /foo" , sub {
219
+ subtest " request /foo" , sub {
200
220
my Env $psgi = (GET " /foo" )-> to_psgi;
201
221
202
- it " should invoke action foo from mount_action" , sub {
203
- expect($site -> call($psgi ))-> to_be([200, $CT , [" action foo from mount_action" ]]);
204
- };
222
+ $tester -> psgi_returns($psgi , [200, $CT , [" action foo from mount_action" ]]
223
+ , " it should invoke action foo from mount_action" );
205
224
};
206
225
};
207
226
};
211
230
chdir ($CWD );
212
231
213
232
done_testing();
214
-
0 commit comments