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