From: Graham Knop Date: Fri, 30 Mar 2012 20:36:11 +0000 (-0400) Subject: basic tests for create_class_with_roles X-Git-Tag: v1.000_900~20 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a8cc11227cfb1b89d52fb3002354d51bc92ec249;p=gitmo%2FRole-Tiny.git basic tests for create_class_with_roles --- diff --git a/t/role-tiny.t b/t/role-tiny.t index cf221ab..fdc23fd 100644 --- a/t/role-tiny.t +++ b/t/role-tiny.t @@ -54,6 +54,13 @@ BEGIN { sub req1 { } } +BEGIN { + package ExtraRole; + use Role::Tiny; + + sub extra1 { 'role extra' } +} + sub try_apply_to { my $to = shift; exception { Role::Tiny->apply_role_to_package($to, 'MyRole') } @@ -64,6 +71,7 @@ is(MyClass->foo, 'role foo class foo', 'method modifier'); is(MyClass->bar, 'role bar', 'method from role'); is(MyClass->baz, 'class baz', 'method from class'); ok(MyClass->does('MyRole'), 'class does role'); +ok(!MyClass->does('IntermediaryRole'), 'class does not do non-applied role'); ok(!MyClass->does('Random'), 'class does not do non-role'); like(try_apply_to('NoMethods'), qr/req1, req2/, 'error for both methods'); @@ -79,5 +87,13 @@ ok(ExtraClass->does('IntermediaryRole'), 'ExtraClass does IntermediaryRole'); is(ExtraClass->bar, 'role bar', 'method from role'); is(ExtraClass->baz, 'class baz', 'method from class'); +my $new_class; +is exception { + $new_class = Role::Tiny->create_class_with_roles('MyClass', 'ExtraRole'); +}, undef, 'No errors creating class with roles'; + +isa_ok($new_class, 'MyClass'); +is($new_class->extra1, 'role extra', 'method from role'); + done_testing;