summaryrefslogtreecommitdiffstats
path: root/t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-04-16 15:37:47 -0500
committerJesse Luehrs <doy@tozt.net>2011-04-16 15:37:47 -0500
commit64b0df203441b83a6601371bfadb1aac634e5d20 (patch)
tree45da2548067703a679b2e964ad0b72a6d3871e13 /t
parent7acd1a61c5b1768f157dbaa4b7beb32456012b4b (diff)
downloadbread-board-declare-64b0df203441b83a6601371bfadb1aac634e5d20.tar.gz
bread-board-declare-64b0df203441b83a6601371bfadb1aac634e5d20.zip
fix this test up a bit
Diffstat (limited to 't')
-rw-r--r--t/50-infer.t145
1 files changed, 55 insertions, 90 deletions
diff --git a/t/50-infer.t b/t/50-infer.t
index 88fcb68..bae915d 100644
--- a/t/50-infer.t
+++ b/t/50-infer.t
@@ -7,6 +7,12 @@ use Test::Fatal;
{
package Foo;
use Moose;
+
+ has data => (
+ is => 'ro',
+ isa => 'Str',
+ default => 'FOO',
+ );
}
{
@@ -29,6 +35,11 @@ use Test::Fatal;
isa => 'Bar',
required => 1,
);
+
+ has thing => (
+ is => 'ro',
+ isa => 'Str',
+ );
}
{
@@ -36,17 +47,6 @@ use Test::Fatal;
use Moose;
use Bread::Board::Declare;
- has foo => (
- is => 'ro',
- isa => 'Foo',
- block => sub { Foo->new },
- );
-
- has bar => (
- is => 'ro',
- isa => 'Bar',
- );
-
has baz => (
is => 'ro',
isa => 'Baz',
@@ -58,6 +58,11 @@ use Test::Fatal;
isa_ok($c->baz, 'Baz');
isa_ok($c->baz->foo, 'Foo');
isa_ok($c->baz->bar, 'Bar');
+
+ is($c->baz->thing, undef, "right thing");
+ is($c->baz->foo->data, 'FOO', "right data");
+
+ isa_ok($c->resolve(type => 'Baz'), 'Baz');
}
{
@@ -66,9 +71,7 @@ use Test::Fatal;
extends 'Baz';
- has thing => (
- is => 'ro',
- isa => 'Str',
+ has '+thing' => (
required => 1,
);
}
@@ -78,16 +81,6 @@ use Test::Fatal;
use Moose;
use Bread::Board::Declare;
- has foo => (
- is => 'ro',
- isa => 'Foo',
- );
-
- has bar => (
- is => 'ro',
- isa => 'Bar',
- );
-
has baz => (
is => 'ro',
isa => 'Baz2',
@@ -107,22 +100,18 @@ use Test::Fatal;
use Moose;
use Bread::Board::Declare;
- has foo => (
- is => 'ro',
- isa => 'Foo',
- );
-
- has bar => (
- is => 'ro',
- isa => 'Bar',
- );
-
has thing => (
is => 'ro',
isa => 'Str',
value => 'THING',
);
+ has foo => (
+ is => 'ro',
+ isa => 'Foo',
+ dependencies => { data => 'thing' },
+ );
+
has baz => (
is => 'ro',
isa => 'Baz2',
@@ -135,89 +124,65 @@ use Test::Fatal;
isa_ok($c->baz, 'Baz2');
isa_ok($c->baz->foo, 'Foo');
isa_ok($c->baz->bar, 'Bar');
+ is($c->baz->foo->data, 'THING',
+ "inference finds services in the container");
is($c->baz->thing, 'THING', "partial dependency specification works");
}
{
- package My::Container4;
+ package Quux;
use Moose;
- use Bread::Board::Declare;
- has foo => (
- is => 'ro',
- isa => 'Foo',
+ has baz => (
+ is => 'ro',
+ isa => 'Baz',
+ required => 1,
);
- has other_foo => (
+ has foo => (
is => 'ro',
isa => 'Foo',
);
-
- has bar => (
- is => 'ro',
- isa => 'Bar',
- );
-
- has baz => (
- is => 'ro',
- isa => 'Baz',
- );
-}
-
-{
- like(
- exception { My::Container4->new },
- qr/^You have already declared a typemap for type Foo/,
- "correct error when inferring is ambiguous"
- );
-}
-
-{
- package Foo2;
- use Moose;
-
- extends 'Foo';
-
- has bar => (
- is => 'ro',
- isa => 'Bar',
- required => 1,
- );
}
{
- package My::Container5;
+ package My::Container4;
use Moose;
use Bread::Board::Declare;
- has foo => (
- is => 'ro',
- isa => 'Foo2',
+ has data => (
+ is => 'ro',
+ isa => 'Str',
+ value => 'DATA',
);
- has other_foo => (
- is => 'ro',
- isa => 'Foo2',
- typemap => 0,
+ has quux => (
+ is => 'ro',
+ isa => 'Quux',
);
- has bar => (
- is => 'ro',
- isa => 'Bar',
+ has foo => (
+ is => 'ro',
+ isa => 'Foo',
+ dependencies => ['data'],
);
- has baz => (
- is => 'ro',
- isa => 'Baz',
+ has quux2 => (
+ is => 'ro',
+ isa => 'Quux',
+ dependencies => ['foo'],
);
}
{
- my $c = My::Container5->new;
- isa_ok($c->baz, 'Baz');
- isa_ok($c->baz->foo, 'Foo');
- isa_ok($c->baz->bar, 'Bar');
- isa_ok($c->other_foo->bar, 'Bar');
+ my $c = My::Container4->new;
+ isa_ok($c->quux, 'Quux');
+ isa_ok($c->quux->baz, 'Baz');
+ isa_ok($c->quux->baz->foo, 'Foo');
+ isa_ok($c->quux->baz->bar, 'Bar');
+
+ is($c->quux->foo, undef, "non-required attrs are not inferred");
+ is($c->quux2->foo->data, 'DATA', "but can be explicitly specified");
}
done_testing;