add tests for run_if_script
[catagits/Web-Simple.git] / t / run_if_script.t
CommitLineData
fd8747e5 1use strictures;
2
3use Test::More;
4
5{
6 use Web::Simple 'RunTest';
7
8 package RunTest;
9 use Moo;
10 has test => is => ro => default => sub { 2 };
11 sub to_psgi_app { "to_psgi_app" }
12 sub run { @_, "run" }
13}
14
15is(
16 sub { RunTest->run_if_script }
17 ->(),
18 "to_psgi_app",
19 "to_psgi_app is called when run_if_script is called inside a function"
20);
21
22is(
23 ( RunTest->run_if_script )[0]->test, #
24 2,
25 "calling run_if_script on a class name instantiates it and runs it"
26);
27
28my $rt = RunTest->new( test => 3 );
29
30is_deeply(
31 [ $rt->run_if_script ], #
32 [ $rt, $rt, "run" ],
33 "calling run_if_script on an object runs it directly"
34);
35
36is_deeply(
37 [ $rt->run_if_script( 4 ) ], #
38 [ $rt, $rt, 4, "run" ],
39 "passing arguments to run_if_script has them passed on to the run method"
40);
41
42done_testing;