ede9d89b9fa514a344e8cf4b26c36b59bf46506f
[catagits/Web-Simple.git] / t / run_if_script.t
1 use strictures;
2
3 use 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
15 is(
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
22 is(
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
28 my $rt = RunTest->new( test => 3 );
29
30 is_deeply(
31     [ $rt->run_if_script ],                 #
32     [ $rt, $rt, "run" ],
33     "calling run_if_script on an object runs it directly"
34 );
35
36 is_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
42 done_testing;