summaryrefslogtreecommitdiffstats
path: root/t/35-no-service.t
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-03-02 22:28:34 -0600
committerJesse Luehrs <doy@tozt.net>2011-03-02 22:35:01 -0600
commit565afc7a56c520e8bf20dd8415d72481e861ed31 (patch)
tree3a31738c0f0dbe8bc4f2447102d30430269fc4ca /t/35-no-service.t
parent2b95f03cda1e9f719624e253a8ed24a2aac5a143 (diff)
downloadbread-board-declare-565afc7a56c520e8bf20dd8415d72481e861ed31.tar.gz
bread-board-declare-565afc7a56c520e8bf20dd8415d72481e861ed31.zip
more useful handling of attributes with no services defined
Diffstat (limited to 't/35-no-service.t')
-rw-r--r--t/35-no-service.t72
1 files changed, 72 insertions, 0 deletions
diff --git a/t/35-no-service.t b/t/35-no-service.t
new file mode 100644
index 0000000..c6a9226
--- /dev/null
+++ b/t/35-no-service.t
@@ -0,0 +1,72 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More;
+use Test::Fatal;
+
+{
+ package Bar;
+ use Moose;
+}
+
+{
+ package Foo;
+ use Moose;
+ use Bread::Board::Declare;
+
+ has foo => (
+ is => 'ro',
+ isa => 'Str',
+ );
+
+ has bar => (
+ is => 'ro',
+ isa => 'Bar',
+ service => 0,
+ );
+
+ has baz => (
+ is => 'ro',
+ isa => 'Str',
+ block => sub { shift->param('foo') },
+ dependencies => ['foo'],
+ );
+
+ has quux => (
+ is => 'ro',
+ isa => 'Bar',
+ block => sub { shift->param('bar') },
+ dependencies => ['bar'],
+ );
+}
+
+{
+ my $foo = Foo->new;
+ ok($foo->has_service($_), "has service $_") for qw(foo baz);
+ ok(!$foo->has_service($_), "doesn't have service $_") for qw(bar);
+}
+
+{
+ my $foo = Foo->new;
+ like(
+ exception { $foo->baz },
+ qr/^Attribute foo did not specify a service\. It must be given a value through the constructor or writer method before it can be resolved\./,
+ "got the right error when foo isn't set"
+ );
+}
+
+{
+ my $foo = Foo->new(foo => 'bar');
+ is($foo->baz, 'bar', "didn't get an error when foo is set");
+}
+
+{
+ my $foo = Foo->new;
+ like(
+ exception { $foo->quux },
+ qr/^Could not find container or service for bar in Foo/,
+ "can't depend on attrs with no service"
+ );
+}
+
+done_testing;