Make sure our new attribute metaclass is being used
[gitmo/MooseX-Role-Parameterized.git] / t / 001-parameters.t
index a5ca29f..53cd430 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
-use Test::More tests => 10;
+use Test::More tests => 14;
 use Test::Exception;
 
 use MooseX::Role::Parameterized::Parameters;
@@ -32,6 +32,7 @@ $parameter_metaclass = MyRole::LengthParameter->meta->parameter_metaclass;
 is($parameter_metaclass->get_all_attributes, 1, "exactly one parameter");
 
 my $parameter = ($parameter_metaclass->get_all_attributes)[0];
+isa_ok($parameter, 'MooseX::Role::Parameterized::Meta::Parameter');
 is($parameter->name, 'length', "parameter name");
 ok($parameter->is_required, "parameter is required");
 
@@ -45,20 +46,26 @@ $p = MyRole::LengthParameter->meta->construct_parameters(
 
 is($p->length, 5, "correct length");
 
+throws_ok {
+    $p->length(10);
+} qr/^Cannot assign a value to a read-only accessor/;
+
 do {
     package MyRole::LengthParameter;
     use MooseX::Role::Parameterized;
 
-    parameter name => (
+    parameter ['first_name', 'last_name'] => (
         is  => 'rw',
         isa => 'Str',
     );
 };
 
 $parameter_metaclass = MyRole::LengthParameter->meta->parameter_metaclass;
-is($parameter_metaclass->get_all_attributes, 2, "two parameters");
+is($parameter_metaclass->get_all_attributes, 3, "three parameters");
 
-my $name_param = $parameter_metaclass->get_attribute('name');
-is($name_param->type_constraint, 'Str', 'parameter type constraint');
-ok(!$name_param->is_required, 'name is optional');
+for my $param_name ('first_name', 'last_name') {
+    my $param = $parameter_metaclass->get_attribute($param_name);
+    is($param->type_constraint, 'Str', "$param_name type constraint");
+    ok(!$param->is_required, "$param_name is optional");
+}