Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: How to test a Moose Role?

by jandrew (Chaplain)
on Mar 30, 2012 at 19:19 UTC ( #962672=note: print w/replies, xml ) Need Help??

in reply to How to test a Moose Role?

Since I keep coming back to this node when I do a Super Search for this question I thought this might be a good place to add a new possible solution

use Test::Most; use Test::Moose; use MooseX::ClassCompositor; use MyCoolNewRole v1.0;#To test for version availability my @attributes = qw( first_attribute ); my @methods = qw( important_method ); my ( $instance ); my $class = MooseX::ClassCompositor->new({ class_basename => 'Test', })->class_for( 'MyCoolNewRole', ); map has_attribute_ok( $class, $_ ), @attributes; map can_ok( $class, $_ ), @methods; lives_ok{ $instance = $class->new( first_attribute => 'cool', )} 'Test creation of an instance'; # other cool tests, for example; # is( 42, $instance->important_method( '?' ), 'The answer') ) done_testing();

This solution was not available on CPAN at the time of the original post. MooseX::ClassCompositor++

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://962672]
[stevieb]: I just received full professional license for ALL of JetBrains software due to requesting their opensource request form! I wanted only CLion, but they give them all
[stevieb]: I stated I use IDEA for Perl work, and at work, licensed version of PyCharm
[beech]: is that a good thing?
[stevieb]: absolutely. Free professional IDEs and related software for all the langs I write in, and I wanted CLion because it's a C IDE that can communicate directly with an Arduino

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (12)
As of 2017-02-20 20:17 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (302 votes). Check out past polls.