Test that simple contexts are passed to wrapped methods
[gitmo/Moose.git] / t / 033_attribute_triggers.t
index 66b0861..b595177 100644 (file)
@@ -5,7 +5,7 @@ use warnings;
 
 use Scalar::Util 'isweak';
 
-use Test::More tests => 24;
+use Test::More tests => 27;
 use Test::Exception;
 
 BEGIN {
@@ -14,8 +14,6 @@ BEGIN {
 
 {
     package Foo;
-    use strict;
-    use warnings;
     use Moose;
     
     has 'bar' => (is      => 'rw', 
@@ -35,15 +33,11 @@ BEGIN {
      
                   
     package Bar;
-    use strict;
-    use warnings;
     use Moose;
     
     has 'foo' => (is => 'rw', isa => 'Foo', weak_ref => 1);           
     
     package Baz;
-    use strict;
-    use warnings;
     use Moose;
     
     has 'foo' => (is => 'rw', isa => 'Foo', weak_ref => 1);           
@@ -108,3 +102,28 @@ BEGIN {
     ok(isweak($baz->{foo}), '... baz.foo is a weak reference');
 }
 
+# some errors
+
+{
+    package Bling;
+    use Moose;
+    
+    ::dies_ok { 
+        has('bling' => (is => 'ro', trigger => sub { 0 }));
+    } '... cannot create trigger on a read-only attr';
+}
+
+{
+    package Bling::Bling;
+    use Moose;
+    
+    ::dies_ok { 
+        has('bling' => (is => 'rw', trigger => 'Fail'));
+    } '... a trigger must be a CODE ref';
+    
+    ::dies_ok { 
+        has('bling' => (is => 'rw', trigger => []));
+    } '... a trigger must be a CODE ref';    
+}
+
+