summary refs log tree commit diff
path: root/t/02_factory_validate.t
blob: ccd13897a21eedb49650384e2d7affb20a7ca58c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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";