add tests for run_if_script run_if_script_tests
Christian Walde [Fri, 24 Oct 2014 17:37:07 +0000 (19:37 +0200)]
t/run_if_script.t [new file with mode: 0644]

diff --git a/t/run_if_script.t b/t/run_if_script.t
new file mode 100644 (file)
index 0000000..ede9d89
--- /dev/null
@@ -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;