Merge branch 'bare_attribute'
[gitmo/Moose.git] / t / 020_attributes / 012_misc_attribute_tests.t
index 52f6e14..8d02691 100644 (file)
@@ -140,7 +140,7 @@ use Test::Exception;
 
     throws_ok {
         $moose_obj->a_str( $moose_obj )
-    } qr/Attribute \(a_str\) does not pass the type constraint because\: Validation failed for 'Str' failed with value OverloadedStr=HASH\(0x.+?\)/, 
+    } qr/Attribute \(a_str\) does not pass the type constraint because\: Validation failed for 'Str' failed with value OverloadedStr=HASH\(0x.+?\)/,
     '... dies without overloading the string';
 
 }
@@ -155,7 +155,7 @@ use Test::Exception;
 
     throws_ok {
         OverloadBreaker->new;
-    } qr/Attribute \(a_num\) does not pass the type constraint because\: Validation failed for 'Int' failed with value 7\.5/, 
+    } qr/Attribute \(a_num\) does not pass the type constraint because\: Validation failed for 'Int' failed with value 7\.5/,
     '... this doesnt trip overload to break anymore ';
 
     lives_ok {
@@ -184,14 +184,14 @@ use Test::Exception;
     is($instance->foo, 'works', "foo builder works");
 }
 
-{    
+{
     {
         package Test::Builder::Attribute::Broken;
         use Moose;
 
         has 'foo'  => ( required => 1, builder => 'build_foo', is => 'ro');
     }
-    
+
     dies_ok {
         Test::Builder::Attribute::Broken->new;
     } '... no builder, wtf';
@@ -215,7 +215,6 @@ use Test::Exception;
     my $_foo_attr = $meta->get_attribute("_foo");
 
     ok($foo_attr->is_lazy, "foo is lazy");
-    ok($foo_attr->is_required, "foo is required");
     ok($foo_attr->is_lazy_build, "foo is lazy_build");
 
     ok($foo_attr->has_clearer, "foo has clearer");
@@ -228,7 +227,7 @@ use Test::Exception;
     is($foo_attr->predicate, "has_foo",  ".. and it's named has_foo");
 
     ok($_foo_attr->is_lazy, "_foo is lazy");
-    ok($_foo_attr->is_required, "_foo is required");
+    ok(!$_foo_attr->is_required, "lazy_build attributes are no longer automatically required");
     ok($_foo_attr->is_lazy_build, "_foo is lazy_build");
 
     ok($_foo_attr->has_clearer, "_foo has clearer");
@@ -262,3 +261,15 @@ lives_ok { OutOfClassTest->can('has')->('bar'); } 'create attr via can';
 
 ok(OutOfClassTest->meta->get_attribute('foo'), 'attr created from sub call');
 ok(OutOfClassTest->meta->get_attribute('bar'), 'attr created from can');
+
+
+{
+    {
+        package Foo;
+        use Moose;
+
+        ::throws_ok { has 'foo' => ( 'ro', isa => 'Str' ) }
+            qr/^Usage/, 'has throws error with odd number of attribute options';
+    }
+
+}