summaryrefslogtreecommitdiff
path: root/t/exceptions/moose-meta-method-accessor-native-grep.t
blob: 6f20cb41bab0f955989bdeaf7905c938e8dd6a75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use strict;
use warnings;

use Test::More;
use Test::Fatal;

use Moose();

{
    {
        package Foo;
        use Moose;

        has 'foo' => (
            is      => 'ro',
            isa     => 'ArrayRef',
            traits  => ['Array'],
            handles => {
                grep => 'grep'
            },
            required => 1
        );
    }

    my $foo_obj = Foo->new( foo => [1, 2, 3] );
    my $arg = [12];

    my $exception = exception {
        $foo_obj->grep( $arg );
    };

    like(
        $exception,
        qr/The argument passed to grep must be a code reference/,
        "an ArrayRef passed to grep");

    isa_ok(
        $exception,
        'Moose::Exception::InvalidArgumentToMethod',
        "an ArrayRef passed to grep");

    is(
        $exception->method_name,
        "grep",
        "an ArrayRef passed to grep");

    is(
        $exception->argument,
        $arg,
        "an ArrayRef passed to grep");

    is(
        $exception->type_of_argument,
        "code reference",
        "an ArrayRef passed to grep");

    is(
        $exception->type,
        "CodeRef",
        "an ArrayRef passed to grep");
}

done_testing;