From: Christian Walde Date: Fri, 24 Oct 2014 17:37:07 +0000 (+0200) Subject: add tests for run_if_script X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FWeb-Simple.git;a=commitdiff_plain;h=fd8747e504c32074e49b1514b39418c32bd22a32 add tests for run_if_script --- diff --git a/t/run_if_script.t b/t/run_if_script.t new file mode 100644 index 0000000..ede9d89 --- /dev/null +++ b/t/run_if_script.t @@ -0,0 +1,42 @@ +use strictures; + +use Test::More; + +{ + use Web::Simple 'RunTest'; + + package RunTest; + use Moo; + has test => is => ro => default => sub { 2 }; + sub to_psgi_app { "to_psgi_app" } + sub run { @_, "run" } +} + +is( + sub { RunTest->run_if_script } + ->(), + "to_psgi_app", + "to_psgi_app is called when run_if_script is called inside a function" +); + +is( + ( RunTest->run_if_script )[0]->test, # + 2, + "calling run_if_script on a class name instantiates it and runs it" +); + +my $rt = RunTest->new( test => 3 ); + +is_deeply( + [ $rt->run_if_script ], # + [ $rt, $rt, "run" ], + "calling run_if_script on an object runs it directly" +); + +is_deeply( + [ $rt->run_if_script( 4 ) ], # + [ $rt, $rt, 4, "run" ], + "passing arguments to run_if_script has them passed on to the run method" +); + +done_testing;