summaryrefslogtreecommitdiff
path: root/t/exceptions/moose-meta-method-accessor.t
blob: f42f4d2761fcff3072d2582ab9beba5ed3ca42aa (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
use strict;
use warnings;

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

use Moose();

{
    {
        package Foo;
        use Moose;
        extends 'Moose::Meta::Method::Accessor';
    }

    my $attr = Class::MOP::Attribute->new("bar");
    Foo->meta->add_attribute($attr);

    my $foo;
    my $exception = exception {
        $foo = Foo->new( name          => "new",
                         package_name  => "Foo",
                         is_inline     => 1,
                         attribute     => $attr,
                         accessor_type => "writer"
                       );
    };

    like(
        $exception,
        qr/\QCould not generate inline writer because : Could not create writer for 'bar' because Can't locate object method "_eval_environment" via package "Class::MOP::Attribute"/,
        "cannot generate writer");

    isa_ok(
        $exception->error,
        "Moose::Exception::CouldNotCreateWriter",
        "cannot generate writer");

    isa_ok(
        $exception,
        "Moose::Exception::CouldNotGenerateInlineAttributeMethod",
        "cannot generate writer");

    is(
        $exception->error->attribute_name,
        'bar',
        "cannot generate writer");

    is(
        ref($exception->error->instance),
        "Foo",
        "cannot generate writer");
}

done_testing;