Subject: | [TEST ATTACHED] Error messages should be consistant if there is no coercion |
I would like if the error messages were consistent when I was omitting
coercions... The run time setter error is elegant, the instantiation
error is crufty.
Subject: | moose_coercion_error_messages.t |
#!/usr/bin/env perl
## Not sure why these two should return different errors
## Personally, I like "Cannot coerce without a type coercion" better
## Evan Carroll <me@evancarroll.com>
##
package Class;
use Moose;
use Moose::Util::TypeConstraints;
subtype 'Type' , as 'Str';
has 'foo' => ( isa => 'Type', is => 'rw' , coerce => 1 );
package main;
use Test::More tests => 4;
eval {
my $o = Class->new->foo( \my $foo );
};
unlike ( $@, qr/Validation failed for 'Type' failed with value/, 'Runtime: No stupid error message' );
like ( $@, qr/Cannot coerce without a type coercion/, 'Runtime: Good error message' );
eval {
my $o = Class->new({ foo => \my $foo });
};
unlike ( $@, qr/Validation failed for 'Type' failed with value/, 'Constructor: No stupid error message' );
like ( $@, qr/Cannot coerce without a type coercion/, 'Constructor: Good error message' );