summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-09-15 16:14:40 +0200
committerfranck cuny <franck@lumberjaph.net>2010-09-15 16:14:40 +0200
commit606b117f2c5246eafd5b2001fd211d79aba85447 (patch)
tree1fe59eafe8690d30404437376d429e813ace8a26
parentadd a auth method (diff)
downloadnet-http-spore-606b117f2c5246eafd5b2001fd211d79aba85447.tar.gz
update tests
-rw-r--r--t/spore-request/exception.t9
-rw-r--r--t/spore-request/path_info.t2
-rw-r--r--t/spore-request/request_uri.t25
-rw-r--r--t/spore-request/script_name.t21
-rw-r--r--t/spore-response/body.t21
5 files changed, 73 insertions, 5 deletions
diff --git a/t/spore-request/exception.t b/t/spore-request/exception.t
index 162370a..5d5af38 100644
--- a/t/spore-request/exception.t
+++ b/t/spore-request/exception.t
@@ -4,11 +4,18 @@ use warnings;
 use Test::More;
 use Net::HTTP::Spore;
 
+my $mock_server = {
+    '/test_spore/_all_docs' => sub {
+        my $req = shift;
+        die;
+    },
+};
+
 ok my $client =
   Net::HTTP::Spore->new_from_spec( 't/specs/couchdb.json',
     api_base_url => 'http://localhost:5984' );
 
-$client->enable( 'Test::Response', callback => sub { die } );
+$client->enable( 'Mock', tests => $mock_server );
 
 my $res = $client->get_all_documents(database => 'test_spore');
 is $res->[0], 599;
diff --git a/t/spore-request/path_info.t b/t/spore-request/path_info.t
index 020a958..17645af 100644
--- a/t/spore-request/path_info.t
+++ b/t/spore-request/path_info.t
@@ -22,4 +22,6 @@ is $request->path_info, '/test_spore/foo';
 $env->{'spore.params'} = [qw/database test_spore key foo another key/];
 is $request->path_info, '/test_spore/foo';
 
+is $request->path, '/test_spore/foo';
+
 done_testing;
diff --git a/t/spore-request/request_uri.t b/t/spore-request/request_uri.t
new file mode 100644
index 0000000..84ba0ff
--- /dev/null
+++ b/t/spore-request/request_uri.t
@@ -0,0 +1,25 @@
+use strict;
+use Test::More;
+
+use Net::HTTP::Spore::Request;
+
+my $env = {
+    REQUEST_METHOD  => 'GET',
+    SERVER_NAME     => 'localhost',
+    SERVER_PORT     => '80',
+    SCRIPT_NAME     => '',
+    PATH_INFO       => '/:database/:key',
+    REQUEST_URI     => '',
+    QUERY_STRING    => '',
+    SERVER_PROTOCOL => 'HTTP/1.0',
+};
+
+ok my $request = Net::HTTP::Spore::Request->new($env);
+
+is $request->request_uri, '';
+
+$env->{REQUEST_URI} = '/';
+
+is $request->request_uri, '/';
+
+done_testing;
diff --git a/t/spore-request/script_name.t b/t/spore-request/script_name.t
new file mode 100644
index 0000000..a283c20
--- /dev/null
+++ b/t/spore-request/script_name.t
@@ -0,0 +1,21 @@
+use strict;
+use Test::More;
+
+use Net::HTTP::Spore::Request;
+
+my $env = {
+    REQUEST_METHOD  => 'GET',
+    SERVER_NAME     => 'localhost',
+    SERVER_PORT     => '80',
+    SCRIPT_NAME     => '',
+};
+
+ok my $request = Net::HTTP::Spore::Request->new($env);
+
+is $request->script_name, '';
+
+$env->{SCRIPT_NAME} = '/1/';
+
+is $request->script_name, '/1/';
+
+done_testing;
diff --git a/t/spore-response/body.t b/t/spore-response/body.t
index 2a35d6b..26c7baf 100644
--- a/t/spore-response/body.t
+++ b/t/spore-response/body.t
@@ -10,12 +10,25 @@ sub r($) {
     return $res->finalize->[2];
 }
 
+sub raw($) {
+    my $res = Net::HTTP::Spore::Response->new(200);
+    $res->raw_body(@_);
+    return $res->raw_body;
+}
+
+sub content($) {
+    my $res = Net::HTTP::Spore::Response->new(200);
+    $res->body(@_);
+    return $res->content;
+}
+
 is_deeply r "Hello World", "Hello World";
 is_deeply r [ "Hello", "World" ], [ "Hello", "World" ];
 
-{
-    my $uri = URI->new("foo");    # stringified object
-    is_deeply r $uri, $uri;
-}
+is_deeply raw "Hello World", "Hello World";
+is_deeply raw [ "Hello", "World" ], [ "Hello", "World" ];
+
+is_deeply content "Hello World", "Hello World";
+is_deeply content [ "Hello", "World" ], [ "Hello", "World" ];
 
 done_testing;