Your IP : 216.73.217.90


Current Path : /proc/self/root/proc/self/root/proc/self/root/usr/share/doc/perl-Moose/t/exceptions/
Upload File :
Current File : //proc/self/root/proc/self/root/proc/self/root/usr/share/doc/perl-Moose/t/exceptions/object.t

use strict;
use warnings;

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

# tests for SingleParamsToNewMustBeHashRef
{
    {
        package Foo;
        use Moose;
    }

    my $exception = exception {
        Foo->new("hello")
    };

    like(
        $exception,
        qr/^\QSingle parameters to new() must be a HASH ref/,
        "A single non-hashref arg to a constructor throws an error");

    isa_ok(
        $exception,
        "Moose::Exception::SingleParamsToNewMustBeHashRef",
        "A single non-hashref arg to a constructor throws an error");
}

# tests for DoesRequiresRoleName
{
    {
        package Foo;
        use Moose;
    }

    my $foo = Foo->new;

    my $exception = exception {
        $foo->does;
    };

    like(
        $exception,
        qr/^\QYou must supply a role name to does()/,
        "Cannot call does() without a role name");

    isa_ok(
        $exception,
        "Moose::Exception::DoesRequiresRoleName",
        "Cannot call does() without a role name");

    is(
        $exception->class_name,
        "Foo",
        "Cannot call does() without a role name");

    $exception = exception {
        Foo->does;
    };

    like(
        $exception,
        qr/^\QYou must supply a role name to does()/,
        "Cannot call does() without a role name");

    isa_ok(
        $exception,
        "Moose::Exception::DoesRequiresRoleName",
        "Cannot call does() without a role name");

    is(
        $exception->class_name,
        "Foo",
        "Cannot call does() without a role name");
}

done_testing;