has 'size' => ( is => 'rw', 'init_arg' => undef );
}
-my @classes = qw( Standard Stricter Subclass StrictSubclass OtherStrictSubclass Tricky InitArg );
+{
+ local $@;
+ eval q[package MyRole; use Moose::Role; use MooseX::StrictConstructor;];
+ like(
+ $@,
+ qr/can only be applied to Moose classes/,
+ "can't apply MXSC to a role"
+ );
+}
+
+{
+ local $@;
+ eval q[package Nothing; use MooseX::StrictConstructor;];
+ like(
+ $@,
+ qr/can only be applied to Moose classes/,
+ "can't apply MXSC to a random package",
+ );
+}
+
+my @classes
+ = qw( Standard Stricter Subclass StrictSubclass OtherStrictSubclass Tricky InitArg );
with_immutable {
is(
);
is(
- exception { StrictSubclass->new( thing => 1, size => 'large', ) }, undef,
- 'subclass that doesn\'t use strict constructor handles known attributes correctly'
+ exception { StrictSubclass->new( thing => 1, size => 'large', ) },
+ undef,
+ q{subclass that doesn't use strict constructor handles known attributes correctly}
);
like(
exception { StrictSubclass->new( thing => 1, bad => 99 ) },
qr/unknown attribute.+: bad/,
- 'subclass that doesn\'t use strict correctly recognizes bad attribute'
+ q{subclass that doesn't use strict correctly recognizes bad attribute}
);
is(
- exception { OtherStrictSubclass->new( thing => 1, size => 'large', ) }, undef,
- 'strict subclass from parent that doesn\'t use strict constructor handles known attributes correctly'
+ exception { OtherStrictSubclass->new( thing => 1, size => 'large', ) },
+ undef,
+ q{strict subclass from parent that doesn't use strict constructor handles known attributes correctly}
);
like(
exception { OtherStrictSubclass->new( thing => 1, bad => 99 ) },
qr/unknown attribute.+: bad/,
- 'strict subclass from parent that doesn\'t use strict correctly recognizes bad attribute'
+ q{strict subclass from parent that doesn't use strict correctly recognizes bad attribute}
);
is(