diff options
Diffstat (limited to 't')
-rw-r--r-- | t/spore-middleware/format-json.t | 21 | ||||
-rw-r--r-- | t/spore-middleware/format-xml.t | 18 | ||||
-rw-r--r-- | t/spore-middleware/format-yaml.t | 19 | ||||
-rw-r--r-- | t/spore-middleware/runtime.t | 11 | ||||
-rw-r--r-- | t/spore-middleware/useragent.t | 9 |
5 files changed, 53 insertions, 25 deletions
diff --git a/t/spore-middleware/format-json.t b/t/spore-middleware/format-json.t index 3e3b59b..61a557f 100644 --- a/t/spore-middleware/format-json.t +++ b/t/spore-middleware/format-json.t @@ -6,18 +6,25 @@ use JSON; use Net::HTTP::Spore; +my $content = { keys => [qw/1 2 3/] }; + +my $mock_server = { + '/test_spore/_all_docs' => sub { + my $req = shift; + $req->new_response( + 200, + [ 'Content-Type' => 'application/json' ], + JSON::encode_json( $content ) + ); + }, +}; + ok my $client = Net::HTTP::Spore->new_from_spec( 't/specs/couchdb.json', api_base_url => 'http://localhost:5984' ); -my $content = { keys => [qw/1 2 3/] }; - $client->enable('Format::JSON'); -$client->enable( - 'Test::Response', - body => JSON::encode_json($content), - headers => [ 'Content-Type' => 'application/json' ] -); +$client->enable('Mock', tests => $mock_server); my $res = $client->get_all_documents( database => 'test_spore' ); is $res->[0], 200; diff --git a/t/spore-middleware/format-xml.t b/t/spore-middleware/format-xml.t index 0a01633..623e281 100644 --- a/t/spore-middleware/format-xml.t +++ b/t/spore-middleware/format-xml.t @@ -6,18 +6,22 @@ use XML::Simple; use Net::HTTP::Spore; +my $content = { keys => [qw/1 2 3/] }; + +my $mock_server = { + '/test_spore/_all_docs' => sub { + my $req = shift; + $req->new_response( 200, [ 'Content-Type' => 'text/xml' ], + XMLout($content) ); + }, +}; + ok my $client = Net::HTTP::Spore->new_from_spec( 't/specs/couchdb.json', api_base_url => 'http://localhost:5984' ); -my $content = { keys => [qw/1 2 3/] }; - $client->enable('Format::XML'); -$client->enable( - 'Test::Response', - body => XMLout($content), - headers => [ 'Content-Type' => 'text/xml' ] -); +$client->enable( 'Mock', tests => $mock_server ); my $res = $client->get_all_documents( database => 'test_spore' ); is $res->[0], 200; diff --git a/t/spore-middleware/format-yaml.t b/t/spore-middleware/format-yaml.t index c104cc5..db9629d 100644 --- a/t/spore-middleware/format-yaml.t +++ b/t/spore-middleware/format-yaml.t @@ -6,18 +6,22 @@ use YAML; use Net::HTTP::Spore; +my $content = { keys => [qw/1 2 3/] }; + +my $mock_server = { + '/test_spore/_all_docs' => sub { + my $req = shift; + $req->new_response( 200, [ 'Content-Type' => 'text/x-yaml' ], + Dump($content) ); + }, +}; + ok my $client = Net::HTTP::Spore->new_from_spec( 't/specs/couchdb.json', api_base_url => 'http://localhost:5984' ); -my $content = { keys => [qw/1 2 3/] }; - $client->enable('Format::YAML'); -$client->enable( - 'Test::Response', - body => Dump($content), - headers => [ 'Content-Type' => 'text/x-yaml' ] -); +$client->enable( 'Mock', tests => $mock_server ); my $res = $client->get_all_documents( database => 'test_spore' ); is $res->[0], 200; @@ -28,3 +32,4 @@ my $req = $res->request; is $req->header('Accept'), 'text/x-yaml'; done_testing; + diff --git a/t/spore-middleware/runtime.t b/t/spore-middleware/runtime.t index d6c9b55..e7509d6 100644 --- a/t/spore-middleware/runtime.t +++ b/t/spore-middleware/runtime.t @@ -4,14 +4,19 @@ use warnings; use Test::More; use Net::HTTP::Spore; +my $mock_server = { + '/test_spore/_all_docs' => sub { + my $req = shift; + $req->new_response( 200, [ 'Content-Type' => 'text/plan' ], 'ok'); + }, +}; + ok my $client = Net::HTTP::Spore->new_from_spec( 't/specs/couchdb.json', api_base_url => 'http://localhost:5984' ); -my $ua_str = 'Test::Spore middleware'; - $client->enable('Runtime'); -$client->enable('Test::Response'); +$client->enable('Mock', tests => $mock_server); my $res = $client->get_all_documents(database => 'test_spore'); ok $res->header('X-Spore-Runtime'); diff --git a/t/spore-middleware/useragent.t b/t/spore-middleware/useragent.t index 14dc9a6..92af94b 100644 --- a/t/spore-middleware/useragent.t +++ b/t/spore-middleware/useragent.t @@ -4,6 +4,13 @@ use warnings; use Test::More; use Net::HTTP::Spore; +my $mock_server = { + '/test_spore/_all_docs' => sub { + my $req = shift; + $req->new_response( 200, [ 'Content-Type' => 'text/plain' ], 'ok'); + }, +}; + ok my $client = Net::HTTP::Spore->new_from_spec( 't/specs/couchdb.json', api_base_url => 'http://localhost:5984' ); @@ -11,7 +18,7 @@ ok my $client = my $ua_str = 'Test::Spore middleware'; $client->enable('UserAgent', useragent => $ua_str); -$client->enable('Test::Response'); +$client->enable('Mock', tests => $mock_server); my $res = $client->get_all_documents(database => 'test_spore'); is $res->request->header('User-Agent'), $ua_str; |