Default parameters to read-only
[gitmo/MooseX-Role-Parameterized.git] / t / 003-apply.t
index 989764b..43ae9a9 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
-use Test::More tests => 14;
+use Test::More tests => 15;
 use Test::Exception;
 
 do {
@@ -10,20 +10,17 @@ do {
     use Moose::Util::TypeConstraints;
 
     parameter format => (
-        is       => 'ro',
         isa      => (enum ['Dumper', 'Storable']),
         required => 1,
     );
 
     parameter freeze_method => (
-        is      => 'ro',
         isa     => 'Str',
         lazy    => 1,
         default => sub { "freeze_" . shift->format },
     );
 
     parameter thaw_method => (
-        is      => 'ro',
         isa     => 'Str',
         lazy    => 1,
         default => sub { "thaw_" . shift->format },
@@ -55,12 +52,6 @@ do {
     };
 };
 
-throws_ok {
-    package MyClass::Error;
-    use Moose;
-    with 'MyRole::Storage';
-} qr/^Attribute \(format\) is required/;
-
 do {
     package MyClass::Dumper;
     use Moose;
@@ -119,6 +110,20 @@ do {
 
 can_ok('MyClass::Three' => qw(freeze_Dumper freeze_Storable thaw_Dumper thaw_Storable store dump));
 
+throws_ok {
+    package MyClass::Error::Required;
+    use Moose;
+    with 'MyRole::Storage';
+} qr/^Attribute \(format\) is required/;
+
+throws_ok {
+    package MyClass::Error::Invalid;
+    use Moose;
+    with 'MyRole::Storage' => {
+        format => 'YAML',
+    };
+} qr/^Attribute \(format\) does not pass the type constraint/;
+
 sub cant_ok {
     local $Test::Builder::Level = $Test::Builder::Level + 1;
     my $instance = shift;