Skip to content

Commit d2b49d2

Browse files
committed
For [GH #166][GH #117] - Rewrite some tests with Test::More subtest
Although I still love `Test::Kantan` because of its descriptive nature of written test codes and outputs, I found its output reordering makes debugging bit harder. This is why I move back to Test::More.
1 parent b6f34db commit d2b49d2

File tree

1 file changed

+57
-39
lines changed

1 file changed

+57
-39
lines changed

t/psgi_action_in_many_ways.t

+57-39
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ use warnings qw(FATAL all NONFATAL misc);
66
use FindBin; BEGIN { do "$FindBin::Bin/t_lib.pl" }
77
#----------------------------------------
88

9-
use Test::Kantan;
9+
#use Test::Kantan;
10+
use Test::More;
1011
use File::Temp qw/tempdir/;
1112

1213
use Plack::Request;
@@ -23,12 +24,27 @@ use Cwd;
2324

2425
use YATT::Lite::PSGIEnv;
2526

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+
2642
my $TEMPDIR = tempdir(CLEANUP => 1);
2743
my $CWD = cwd();
2844
my $TESTNO = 0;
2945
my $CT = ["Content-Type", q{text/html; charset="utf-8"}];
3046

31-
my $TODO = $ENV{TEST_TODO};
47+
my $TEST_TODO = $ENV{TEST_TODO};
3248

3349
#----------------------------------------
3450

@@ -60,11 +76,13 @@ my $with_or_without = sub {$_[0] ? "With" : "Without"};
6076

6177
foreach my $has_index (1, 0) {
6278

63-
describe $with_or_without->($has_index)." index.yatt", sub {
79+
subtest $with_or_without->($has_index)." index.yatt", sub {
6480

65-
describe "foo.ydo", sub {
81+
subtest "foo.ydo", sub {
6682
my ($app_root, $html_dir, $site) = $make_siteapp->($make_dirs->());
6783

84+
my $tester = t_call_tester->new($site);
85+
6886
MY->mkfile("$html_dir/index.yatt", <<'END') if $has_index;
6987
<h2>Hello</h2>
7088
@@ -84,37 +102,38 @@ return sub {
84102
};
85103
END
86104

87-
describe "request /foo.ydo", sub {
105+
subtest "request /foo.ydo", sub {
88106
my Env $psgi = (GET "/foo.ydo")->to_psgi;
89107

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");
93110
};
94111

95112
# TODO:
96113
if (1) {
97-
describe "request /foo", sub {
114+
subtest "request /foo", sub {
98115
my Env $psgi = (GET "/foo")->to_psgi;
99116

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");
103119
};
104120
}
105121

106122
if ($has_index) {
107-
describe "request /bar (for sanity check)", sub {
123+
subtest "request /bar (for sanity check)", sub {
108124
my Env $psgi = (GET "/bar")->to_psgi;
109125

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");
113128
};
114129
}
115130
};
116131

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";
118137
my ($app_root, $html_dir) = $make_dirs->();
119138

120139
make_path(my $tmpl_dir = "$app_root/ytmpl");
@@ -140,31 +159,32 @@ Action foo => sub {
140159
END
141160

142161
my $site = $make_siteapp->($app_root, $html_dir, app_base => '@ytmpl');
162+
my $tester = t_call_tester->new($site);
143163

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 {
146166
my Env $psgi = (GET "/?!foo=1")->to_psgi;
147167

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");
151170
};
152171
}
153172

154-
if ($TODO) {
155-
describe "request /foo", sub {
173+
if ($TEST_TODO) {
174+
subtest "request /foo", sub {
156175
my Env $psgi = (GET "/foo")->to_psgi;
157176

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");
161179
};
162180
}
163181
};
164182

165-
($has_index or $TODO)
183+
TODO:
184+
($has_index)
166185
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";
168188
my ($app_root, $html_dir) = $make_dirs->();
169189

170190
make_path($html_dir);
@@ -177,6 +197,7 @@ page bar in index.yatt
177197
END
178198

179199
my $site = $make_siteapp->($app_root, $html_dir, app_base => '@ytmpl');
200+
my $tester = t_call_tester->new($site);
180201

181202
$site->mount_action(
182203
'/foo',
@@ -186,22 +207,20 @@ END
186207
}
187208
);
188209

189-
if ($TODO) {
190-
describe "request /?!foo=1", sub {
210+
if ($TEST_TODO) {
211+
subtest "request /?!foo=1", sub {
191212
my Env $psgi = (GET "/?!foo=1")->to_psgi;
192213

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");
196216
};
197217
}
198218

199-
describe "request /foo", sub {
219+
subtest "request /foo", sub {
200220
my Env $psgi = (GET "/foo")->to_psgi;
201221

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");
205224
};
206225
};
207226
};
@@ -211,4 +230,3 @@ END
211230
chdir($CWD);
212231

213232
done_testing();
214-

0 commit comments

Comments
 (0)