summaryrefslogtreecommitdiff
path: root/t/03_check_implementation_class.t
diff options
context:
space:
mode:
authorfranck cuny <franck@lumberjaph.net>2010-08-11 09:59:29 +0200
committerfranck cuny <franck@lumberjaph.net>2010-08-11 09:59:29 +0200
commitafb209cbcfae7b88d8fb23ed04c47e1aee187b2a (patch)
tree6b113aedc62a3ad0548a157d74054ec096720ddd /t/03_check_implementation_class.t
downloadmoosex-abstractfactory-afb209cbcfae7b88d8fb23ed04c47e1aee187b2a.tar.gz
initial commit
Diffstat (limited to '')
-rw-r--r--t/03_check_implementation_class.t51
1 files changed, 51 insertions, 0 deletions
diff --git a/t/03_check_implementation_class.t b/t/03_check_implementation_class.t
new file mode 100644
index 0000000..ccd1389
--- /dev/null
+++ b/t/03_check_implementation_class.t
@@ -0,0 +1,51 @@
+use Test::More tests => 2;
+use Test::Exception;
+
+BEGIN {
+ #----------------------------------------------------
+ # ImplementationA has a tweak() method
+ package My::Factory::ImplementationA;
+ use Moose;
+
+ has connection => (is => 'ro', isa => 'Str');
+
+ sub tweak { 1; }
+
+ #----------------------------------------------------
+ # ImplementationB doesn't have a tweak() method
+
+ package My::Factory::ImplementationB;
+ use Moose;
+
+ sub no_tweak { 1; }
+
+ #----------------------------------------------------
+ # Factory class, has _roles() method that defines
+ # the role(s) (My::Role) all implementations should satisfy
+ package My::Factory;
+ use MooseX::AbstractFactory;
+
+ implementation_does qw/My::Role/;
+
+ #----------------------------------------------------
+ # My::Role requires tweak()
+ package My::Role;
+ use Moose::Role;
+ requires 'tweak';
+}
+
+my $imp;
+
+lives_ok {
+ $imp = My::Factory->create('ImplementationA',
+ {connection => 'Type1'});
+}
+"Factory->new() doesn't die with ImplementationA";
+
+dies_ok {
+ $imp = My::Factory->create(
+ 'ImplementationB',
+ {},
+ );
+}
+"Factory->new() dies with implementationB";