[Jifty-commit] r2111 - in jifty/trunk: lib/Jifty t

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Fri Nov 3 18:17:53 EST 2006


Author: schwern
Date: Fri Nov  3 18:17:52 2006
New Revision: 2111

Added:
   jifty/trunk/t/01-test-web.t
Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Test.pm

Log:
 r25224 at windhund:  schwern | 2006-11-03 14:22:30 -0500
 Add Jifty::Test->web to allow using Jifty->web in tests without a bunch of scaffolding.


Modified: jifty/trunk/lib/Jifty/Test.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Test.pm	(original)
+++ jifty/trunk/lib/Jifty/Test.pm	Fri Nov  3 18:17:52 2006
@@ -227,6 +227,26 @@
     return $server;
 } 
 
+
+=head2 web
+
+Like calling C<<Jifty->web>>.
+
+C<<Jifty::Test->web>> does the necessary Jifty->web initialization for
+it to be usable in a test.
+
+=cut
+
+sub web {
+    my $class = shift;
+
+    Jifty->web->request(Jifty::Request->new)   unless Jifty->web->request;
+    Jifty->web->response(Jifty::Response->new) unless Jifty->web->response;
+
+    return Jifty->web;
+}
+
+
 =head2 mailbox
 
 A mailbox used for testing mail sending.

Added: jifty/trunk/t/01-test-web.t
==============================================================================
--- (empty file)
+++ jifty/trunk/t/01-test-web.t	Fri Nov  3 18:17:52 2006
@@ -0,0 +1,38 @@
+#!/usr/bin/perl -w
+
+use Jifty::Test tests => 5;
+
+my $web = Jifty::Test->web;
+isa_ok( $web->request,  "Jifty::Request"  );
+isa_ok( $web->response, "Jifty::Response" );
+
+{
+    {
+        package JiftyApp::Action::Foo;
+        use base 'Jifty::Action';
+    }
+
+    # Fool Jifty into thinking this is already loaded.
+    local $INC{"JiftyApp/Action/Foo.pm"} = 1;
+
+    my $action = $web->new_action( class => "Foo" );
+    isa_ok( $action, "JiftyApp::Action::Foo" );
+}
+
+
+{
+    package Jifty::Request::Subclass;
+    use base qw(Jifty::Request);
+
+    package Jifty::Response::Subclass;
+    use base qw(Jifty::Response);
+}
+
+
+# Make sure Jifty::Test->web doesn't blow over existing requests and reponses.
+Jifty->web->request (Jifty::Request::Subclass->new );
+Jifty->web->response(Jifty::Response::Subclass->new);
+
+$web = Jifty::Test->web;
+isa_ok( $web->request,  "Jifty::Request::Subclass"  );
+isa_ok( $web->response, "Jifty::Response::Subclass" );


More information about the Jifty-commit mailing list