Dancer2-Plugin-TemplateFlute
view release on metacpan or search on metacpan
use strict;
use warnings;
use Test::More;
use Test::Deep;
use Test::Fatal;
use Dancer2::Core::Session;
use Hash::MultiValue;
use aliased 'Dancer2::Plugin::TemplateFlute::Form';
my ( $form, $log, @logs );
# fixtures
{
package TestObjNoMethods;
use Moo;
}
{
package TestObjReadOnly;
use Moo;
sub read { }
}
{
package TestObjWriteOnly;
use Moo;
sub write { }
}
{
package TestObjReadAndWrite;
use Moo;
sub read { }
sub write { }
}
my $log_cb = sub {
my $level = shift;
my $message = join( '', @_ );
push @logs, { $level => $message };
};
my $session = Dancer2::Core::Session->new( id => 1 );
subtest 'form attribute types and coercion' => sub {
like exception { Form->new }, qr/Missing required arguments: session at/,
"Form->new with no args dies";
like exception { Form->new( session => 'string' ) },
qr/string.+did not pass type constraint.+HasMethods/,
"Form->new with string as session value dies";
like exception { Form->new( session => TestObjNoMethods->new ) },
qr/bless.+TestObjNoMethods.+did not pass type constraint.+HasMethods/,
"Form->new with session TestObjNoMethods dies";
like exception { Form->new( session => TestObjReadOnly->new ) },
qr/bless.+TestObjReadOnly.+did not pass type constraint.+HasMethods/,
"Form->new with session TestObjReadOnly dies";
like exception { Form->new( session => TestObjWriteOnly->new ) },
qr/bless.+TestObjWriteOnly.+did not pass type constraint.+HasMethods/,
( run in 1.367 second using v1.01-cache-2.11-cpan-54e63673c56 )