switch to Test::Exception, add failing test for MooseX::Method::Signatures
[gitmo/MooseX-AlwaysCoerce.git] / t / 02-mx-m-s.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4
5 use Test::More;
6 use Test::Exception;
7
8 eval { require MooseX::Method::Signatures };
9 plan skip_all => "No MooseX::Method::Signatures" if $@;
10
11 plan tests => 2;
12
13 {
14     package MyClass;
15     use Moose;
16     use MooseX::Method::Signatures;
17     use MooseX::AlwaysCoerce;
18     use Moose::Util::TypeConstraints;
19
20     BEGIN {
21         subtype 'MyType', as 'Int';
22         coerce 'MyType', from 'Str', via { length $_ };
23
24         subtype 'Uncoerced', as 'Int';
25     }
26
27     method foo (MyType :$foo, Uncoerced :$bar) {
28         return "$foo $bar";
29     }
30 }
31
32 ok( (my $instance = MyClass->new), 'instance' );
33
34 lives_and {
35     is $instance->foo(foo => "text", bar => 42), '4 42';
36 } 'method called with coerced and uncoerced parameters';