Permalink
Browse files

Ported 2args.t from Plack::Test to P::T::Agent.

  • Loading branch information...
1 parent 0111061 commit 8901e2cd33a0f83c0065a8992465cf87ed416aad @chromatic committed Sep 22, 2011
Showing with 47 additions and 1 deletion.
  1. +28 −1 lib/Plack/Test/Agent.pm
  2. +19 −0 t/2args.t
View
@@ -1,6 +1,33 @@
-package Plack::Test::Agent
+package Plack::Test::Agent;
+# ABSTRACT: OO interface for testing low-level Plack/PSGI apps
use strict;
use warnings;
+use HTTP::Request;
+use HTTP::Response;
+use HTTP::Message::PSGI;
+
+use Plack::Util::Accessor qw( app );
+
+sub new
+{
+ my ($class, %args) = @_;
+
+ my $self = bless {}, $class;
+ $self->app( delete $args{app} );
+
+ return $self;
+}
+
+sub get
+{
+ my ($self, $uri) = @_;
+ my $req = HTTP::Request->new( GET => $uri );
+ my $env = $req->to_psgi;
+ my $app = $self->app;
+
+ return HTTP::Response->from_psgi( $app->( $env ) );
+}
+
1;
View
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use Test::More;
+use Plack::Test::Agent;
+
+my $app = sub { return [ 200, [], [ 'Hello' ] ] };
+
+my $agent = Plack::Test::Agent->new(
+ server => 'HTTP::Server::PSGI',
+ app => $app,
+);
+
+my $res = $agent->get( '/' );
+is $res->content, 'Hello';
+
+done_testing;

0 comments on commit 8901e2c

Please sign in to comment.