summary refs log tree commit diff
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2009-11-26 17:44:33 +0100
committerfranck cuny <franck@lumberjaph.net>2009-11-26 17:44:33 +0100
commitc15ce1be5e8ac6789bcbdb17d0b2b05fa14f574b (patch)
tree520e21ce2fe553071405433eca02bc984f0c1416
parentstart POD, add new method net_api_declare, check nearly everything (diff)
downloadmoosex-net-api-c15ce1be5e8ac6789bcbdb17d0b2b05fa14f574b.tar.gz
move class to lib
-rw-r--r--t/01_basic.t79
1 files changed, 19 insertions, 60 deletions
diff --git a/t/01_basic.t b/t/01_basic.t
index cc6c606..9c108d2 100644
--- a/t/01_basic.t
+++ b/t/01_basic.t
@@ -1,73 +1,32 @@
 use strict;
 use warnings;
 use Test::More;
-use YAML::Syck;
+use Test::Exception;
+use lib ('t/lib');
+use FakeAPI;
 
-{
+my $obj = FakeAPI->new;
+ok $obj, "... object created";
+ok $obj->meta->has_attribute('useragent'),
+    "... useragent attribute have been added";
 
-    package fake::api;
-    use Moose;
-    use MooseX::Net::API;
+ok my $method = $obj->meta->find_method_by_name('bar'),
+    '... method bar have been created';
 
-    has api_base_url => (
-        is      => 'ro',
-        isa     => 'Str',
-        default => 'http://identi.ca/api',
-    );
-    has format => ( is => 'ro', isa => 'Str', default => 'json', );
-    has api_username => ( is => 'rw', isa => 'Str', );
-    has api_password => ( is => 'rw', isa => 'Str', );
-    has api_key      => ( is => 'rw', isa => 'Str', );
+ok $method->meta->has_attribute('path'), '... method bar have attribute path';
 
-    format_query 'format' => ( mode => 'content-type' );
+throws_ok { $obj->baz } qr/bla is declared as required, but is not present/,
+    "... check required params";
 
-    net_api_method foo => (
-        description => 'this does foo',
-        method      => 'GET',
-        path        => '/foo/',
-        code        => sub { my $self = shift; $self->get_foo },
-    );
-
-    net_api_method public => (
-        description => 'this does bar',
-        method      => 'GET',
-        path        => '/statuses/public_timeline',
-    );
-
-    sub get_foo { return 1; }
+throws_ok {
+    $obj->bar( bar => 1, );
 }
+qr/baz is declared as required, but is not present/,
+    "... check required params are present";
 
-{
-
-    package test::fake::api;
-    use Moose;
-    use MooseX::Net::API::Test;
-    extends 'fake::api';
-
-    test_api_method foo => (
-        arguments => [qw//],
-        expect    => sub {
-            my $self = shift;
-            warn Dump \@_;
-        }
-    );
+throws_ok {
+    $obj->bar( bar => 1, foo => 2, );
 }
+qr/foo is not declared as a param/, "... check declared params";
 
-my $obj = fake::api->new();
-ok $obj, '... object created';
-is $obj->foo, 1, '... get foo returns 1';
-ok my $res = $obj->public, '... get public';
-
-my $test_obj = test::fake::api->new();
-
-#my @methods = $obj->meta->get_all_methods;
-#foreach (@methods) {
-    #if ( $_->name =~ /foo/ ) {
-        #my @foo = $_->meta->get_attribute_list;
-        #warn $_->name . " : " . Dump \@foo;
-    #}
-#}
-
-#is $res->code, 200, '... request ok';
-#warn $res->content;
 done_testing;