X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F100_bugs%2F030_coerce_without_coercion.t;fp=t%2F100_bugs%2F030_coerce_without_coercion.t;h=eec4424095f2228a92f4bb5f373b83b724c96c08;hb=ee5e6a034b6aeaed7819138193288eb249d9380b;hp=0000000000000000000000000000000000000000;hpb=6217087ac410ed5f4b7f19d689f113f3a6765be2;p=gitmo%2FMouse.git diff --git a/t/100_bugs/030_coerce_without_coercion.t b/t/100_bugs/030_coerce_without_coercion.t new file mode 100644 index 0000000..eec4424 --- /dev/null +++ b/t/100_bugs/030_coerce_without_coercion.t @@ -0,0 +1,41 @@ +use strict; +# This is automatically generated by author/import-moose-test.pl. +# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!! +use t::lib::MooseCompat; +use warnings; + +use Test::More; +use Test::Exception; +use Test::Mouse; + +{ + package Foo; + + use Mouse::Deprecated -api_version => '1.07'; + use Mouse; + + has x => ( + is => 'rw', + isa => 'HashRef', + coerce => 1, + ); +} + +with_immutable { + lives_ok { Foo->new( x => {} ) } + 'Setting coerce => 1 without a coercion on the type does not cause an error in the constructor'; + + lives_ok { Foo->new->x( {} ) } + 'Setting coerce => 1 without a coercion on the type does not cause an error when setting the attribut'; + + throws_ok { Foo->new( x => 42 ) } + qr/\QAttribute (x) does not pass the type constraint because/, + 'Attempting to provide an invalid value to the constructor for this attr still fails'; + + throws_ok { Foo->new->x(42) } + qr/\QAttribute (x) does not pass the type constraint because/, + 'Attempting to provide an invalid value to the accessor for this attr still fails'; +} +'Foo'; + +done_testing;