[Catalyst-commits] r9182 - in Test-WWW-Mechanize-Catalyst/trunk: . lib/Test/WWW/Mechanize t t/lib

ash at dev.catalyst.perl.org ash at dev.catalyst.perl.org
Tue Feb 3 21:18:51 GMT 2009


Author: ash
Date: 2009-02-03 21:18:50 +0000 (Tue, 03 Feb 2009)
New Revision: 9182

Added:
   Test-WWW-Mechanize-Catalyst/trunk/t/two_app.t
Modified:
   Test-WWW-Mechanize-Catalyst/trunk/CHANGES
   Test-WWW-Mechanize-Catalyst/trunk/lib/Test/WWW/Mechanize/Catalyst.pm
   Test-WWW-Mechanize-Catalyst/trunk/t/lib/Catty.pm
   Test-WWW-Mechanize-Catalyst/trunk/t/lib/CattySession.pm
   Test-WWW-Mechanize-Catalyst/trunk/t/simple.t
Log:
Support testing against two apps in same perl interpreter

Modified: Test-WWW-Mechanize-Catalyst/trunk/CHANGES
===================================================================
--- Test-WWW-Mechanize-Catalyst/trunk/CHANGES	2009-02-03 21:16:16 UTC (rev 9181)
+++ Test-WWW-Mechanize-Catalyst/trunk/CHANGES	2009-02-03 21:18:50 UTC (rev 9182)
@@ -1,5 +1,14 @@
 Revision history for Perl module Test::WWW::Mechanize::Catalyst:
 
+0.50
+     - App classname no longer has to be passed to import:
+        $m = T::W::M::C->new(catalyst_app => 'Catty')
+       now works.
+     - Can now use TWMC two test two different apps in the same perl
+       interpreter due to the above change
+     - Removed Test::WWW::Mechanize::Catalyst::Aux package as it isn't needed
+       any more
+
 0.45 Mon Nov 24 20:39:19 GMT 2008
      - be forwards-compatible with Catalyst 5.80's virtual 
        domain testing (thanks Jason Gottshall)

Modified: Test-WWW-Mechanize-Catalyst/trunk/lib/Test/WWW/Mechanize/Catalyst.pm
===================================================================
--- Test-WWW-Mechanize-Catalyst/trunk/lib/Test/WWW/Mechanize/Catalyst.pm	2009-02-03 21:16:16 UTC (rev 9181)
+++ Test-WWW-Mechanize-Catalyst/trunk/lib/Test/WWW/Mechanize/Catalyst.pm	2009-02-03 21:18:50 UTC (rev 9182)
@@ -1,16 +1,43 @@
 package Test::WWW::Mechanize::Catalyst;
+
 use strict;
 use warnings;
+
+use Carp qw/croak/;
+require Catalyst::Test; # Do not call import
 use Encode qw();
 use HTML::Entities;
 use Test::WWW::Mechanize;
+
 use base qw(Test::WWW::Mechanize);
+
 our $VERSION = '0.45';
 my $Test = Test::Builder->new();
 
 # the reason for the auxiliary package is that both WWW::Mechanize and
 # Catalyst::Test have a subroutine named 'request'
 
+our $APP_CLASS;
+sub new {
+  my ($class, %args) = @_;
+
+  my $app;
+  if (exists $args{catalyst_app}) {
+    $app = $args{catalyst_app};
+
+    require Class::Inspector->filename( $app )
+      unless Class::Inspector->loaded( $app );
+  } elsif (!defined $APP_CLASS) {
+    croak 'Please provide a catalyst_app option or import Test::WWW::Mechanize::Catalyst with a class name'; 
+  } else {
+    $app = $APP_CLASS;
+  }
+
+  my $self = $class->SUPER::new(%args);
+  $self->{catalyst_app} = $app;
+  return $self;
+}
+
 sub allow_external {
     my ( $self, $value ) = @_;
     return $self->{allow_external} unless defined $value;
@@ -37,7 +64,7 @@
     my @creds = $self->get_basic_credentials( "Basic", $uri );
     $request->authorization_basic( @creds ) if @creds;
 
-    my $response = Test::WWW::Mechanize::Catalyst::Aux::request($request);
+    my $response = Catalyst::Test::local_request($self->{catalyst_app}, $request);
     $response->header( 'Content-Base', $request->uri );
     $response->request($request);
     if ( $request->uri->as_string =~ m{^/} ) {
@@ -92,20 +119,15 @@
 }
 
 sub import {
-    Test::WWW::Mechanize::Catalyst::Aux::import(@_);
+  my ($class, $app) = @_;
+  if (defined $app) {
+    require Class::Inspector->filename( $app )
+      unless Class::Inspector->loaded( $app );
+    $APP_CLASS = $app; 
+  }
 }
 
-package Test::WWW::Mechanize::Catalyst::Aux;
 
-sub import {
-    my ( $class, @args ) = @_;
-    eval {
-        require Catalyst::Test;
-        Catalyst::Test::import(@_);
-    };
-    warn $@ if $@;
-}
-
 1;
 
 __END__
@@ -356,11 +378,13 @@
 
 =head1 AUTHOR
 
+Current Maintainer: Ash Berlin C<< <ash at cpan.org> >>
+
 Leon Brocard, C<< <acme at astray.com> >>
 
 =head1 COPYRIGHT
 
-Copyright (C) 2005-7, Leon Brocard
+Copyright (C) 2005-8, Leon Brocard
 
 =head1 LICENSE
 

Modified: Test-WWW-Mechanize-Catalyst/trunk/t/lib/Catty.pm
===================================================================
--- Test-WWW-Mechanize-Catalyst/trunk/t/lib/Catty.pm	2009-02-03 21:16:16 UTC (rev 9181)
+++ Test-WWW-Mechanize-Catalyst/trunk/t/lib/Catty.pm	2009-02-03 21:18:50 UTC (rev 9182)
@@ -84,6 +84,14 @@
     die "erk!";
 }
 
+sub name : Global {
+    my ($self, $c) = @_;
+
+    my $html = html( $c->config->{name}, "This is the die page" );
+    $c->response->content_type("text/html");
+    $c->response->output($html);
+}
+
 sub html {
     my ( $title, $body ) = @_;
     return qq{

Modified: Test-WWW-Mechanize-Catalyst/trunk/t/lib/CattySession.pm
===================================================================
--- Test-WWW-Mechanize-Catalyst/trunk/t/lib/CattySession.pm	2009-02-03 21:16:16 UTC (rev 9181)
+++ Test-WWW-Mechanize-Catalyst/trunk/t/lib/CattySession.pm	2009-02-03 21:18:50 UTC (rev 9182)
@@ -35,6 +35,15 @@
     $context->response->output($html);
 }
 
+sub name : Global {
+    my ($self, $c) = @_;
+
+    my $html = html( $c->config->{name}, "This is the die page" );
+    $c->response->content_type("text/html");
+    $c->response->output($html);
+}
+
+
 sub html {
     my ( $title, $body ) = @_;
     return qq{

Modified: Test-WWW-Mechanize-Catalyst/trunk/t/simple.t
===================================================================
--- Test-WWW-Mechanize-Catalyst/trunk/t/simple.t	2009-02-03 21:16:16 UTC (rev 9181)
+++ Test-WWW-Mechanize-Catalyst/trunk/t/simple.t	2009-02-03 21:18:50 UTC (rev 9182)
@@ -1,7 +1,7 @@
 #!perl
 use strict;
 use warnings;
-use lib 'lib';
+
 use Encode qw();
 use Test::More tests => 37;
 use lib 't/lib';

Added: Test-WWW-Mechanize-Catalyst/trunk/t/two_app.t
===================================================================
--- Test-WWW-Mechanize-Catalyst/trunk/t/two_app.t	                        (rev 0)
+++ Test-WWW-Mechanize-Catalyst/trunk/t/two_app.t	2009-02-03 21:18:50 UTC (rev 9182)
@@ -0,0 +1,28 @@
+use strict;
+use warnings;
+
+use Test::More;
+use lib 't/lib';
+
+eval {
+    require Catalyst::Plugin::Session;
+    require Catalyst::Plugin::Session::State::Cookie;
+};
+
+if ($@) {
+    diag($@);
+    plan skip_all => "Need Catalyst::Plugin::Session to run this test";
+} else {
+    plan tests => 4;
+}
+
+use Test::WWW::Mechanize::Catalyst;
+
+my $m1 = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'Catty');
+my $m2 = Test::WWW::Mechanize::Catalyst->new(catalyst_app => 'CattySession');
+
+$m1->get_ok("/name");
+$m1->title_is('Catty');
+
+$m2->get_ok("/name");
+$m2->title_is('CattySession');




More information about the Catalyst-commits mailing list