summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-09-15 15:21:24 +0200
committerfranck cuny <franck@lumberjaph.net>2010-09-15 15:21:24 +0200
commit954976ce006715b249088bfc2314ab2afb571a1e (patch)
treeb5aa29e63dfee3121df81c0ab0ef01d231b4357a
parentfoo (diff)
downloadnet-http-spore-954976ce006715b249088bfc2314ab2afb571a1e.tar.gz
remove useless files
-rw-r--r--lib/Net/HTTP/Spore/Middleware/Mock.pm38
-rw-r--r--lib/Net/HTTP/Spore/Middleware/Test/Response.pm28
2 files changed, 38 insertions, 28 deletions
diff --git a/lib/Net/HTTP/Spore/Middleware/Mock.pm b/lib/Net/HTTP/Spore/Middleware/Mock.pm
new file mode 100644
index 0000000..12568bf
--- /dev/null
+++ b/lib/Net/HTTP/Spore/Middleware/Mock.pm
@@ -0,0 +1,38 @@
+package Net::HTTP::Spore::Middleware::Mock;
+
+# ABSTRACT: Simple Mocker for Spore middlewares
+
+use Moose;
+extends 'Net::HTTP::Spore::Middleware';
+
+has tests => ( isa => 'HashRef', is => 'ro', required => 1 );
+
+sub call {
+    my ( $self, $req ) = @_;
+
+    foreach my $r ( keys %{ $self->tests } ) {
+        next unless $r eq $req->path;
+        my $res = $self->tests->{$r}->($req);
+        return $res if defined $res;
+    }
+}
+
+1;
+
+=head1 SYNOPSIS
+
+    my $mock_server = {
+        '/path/i/want/to/match' => sub {
+            my $req = shift;
+            ...
+            $req->new_response(200, ['Content-Type' => 'text/plain'], 'ok');
+        }
+    };
+
+    my $client = Net::HTTP::Spore->new_from_spec('spec.json');
+    $client->enable('Mock', tests => $mock_server);
+    my $res = $client->my_rest_method();
+    is $res->status, 200;
+    is $res->body, 'ok';
+
+=head1 DESCRIPTION
diff --git a/lib/Net/HTTP/Spore/Middleware/Test/Response.pm b/lib/Net/HTTP/Spore/Middleware/Test/Response.pm
deleted file mode 100644
index ca216c5..0000000
--- a/lib/Net/HTTP/Spore/Middleware/Test/Response.pm
+++ /dev/null
@@ -1,28 +0,0 @@
-package Net::HTTP::Spore::Middleware::Test::Response;
-
-use Moose;
-extends 'Net::HTTP::Spore::Middleware';
-
-has status => ( isa => 'Int', is => 'ro', lazy => 1, default => 200 );
-has headers => ( isa => 'ArrayRef', is => 'ro', default => sub { [] } );
-has callback => (
-    isa     => 'CodeRef',
-    is      => 'ro',
-    lazy    => 1,
-    default => sub {
-        sub {
-            my ( $self, $req ) = @_;
-            $req->new_response( $self->status, $self->headers, $self->body, );
-        }
-    }
-);
-
-has body =>
-  ( isa => 'HashRef', is => 'ro', lazy => 1, default => sub { { foo => 1 } } );
-
-sub call {
-    my ( $self, $req ) = @_;
-    $self->callback->($self, $req);
-}
-
-1;