1Test::Roo::Role(3)    User Contributed Perl Documentation   Test::Roo::Role(3)
2
3
4

NAME

6       Test::Roo::Role - Composable role for Test::Roo
7

VERSION

9       version 1.004
10

SYNOPSIS

12       A testing role:
13
14           # t/lib/MyTestRole.pm
15           package MyTestRole;
16           use Test::Roo::Role; # loads Moo::Role and Test::More
17
18           requires 'class';
19
20           test 'object creation' => sub {
21               my $self = shift;
22               require_ok( $self->class );
23               my $obj  = new_ok( $self->class );
24           };
25
26           1;
27

DESCRIPTION

29       This module defines test behaviors as a Moo::Role.
30

USAGE

32       Importing Test::Roo::Role also loads Moo::Role (which gives you
33       strictures with fatal warnings and other goodies).
34
35       Importing also loads Test::More.  Any import arguments are passed
36       through to Test::More's "import" method.
37
38   Creating and requiring fixtures
39       You can create fixtures with normal Moo syntax.  You can even make them
40       lazy if you want and require the composing class to provide the
41       builder:
42
43           has fixture => (
44               is => 'lazy'
45           );
46
47           requires '_build_fixture';
48
49       Because this is a Moo::Role, you can require any method you like, not
50       just builders.
51
52       See Moo::Role and Role::Tiny for everything you can do with roles.
53
54   Setup and teardown
55       You can add method modifiers around the "setup" and "teardown" methods
56       and these will be run before tests begin and after tests finish
57       (respectively).
58
59           before  setup     => sub { ... };
60
61           after   teardown  => sub { ... };
62
63       You can also add method modifiers around "each_test", which will be run
64       before and after every individual test.  You could use these to prepare
65       or reset a fixture.
66
67           has fixture => ( is => 'lazy, clearer => 1, predicate => 1 );
68
69           after  each_test => sub { shift->clear_fixture };
70
71       Roles may also modify "setup", "teardown", and "each_test", so the
72       order that modifiers will be called will depend on when roles are
73       composed.  Be careful with "each_test", though, because the global
74       effect may make composition more fragile.
75
76       You can call test functions in modifiers. For example, you could
77       confirm that something has been set up or cleaned up.
78
79           before each_test => sub { ok( ! shift->has_fixture ) };
80

EXPORTED FUNCTIONS

82       Loading Test::Roo::Role exports a single subroutine into the calling
83       package to declare tests.
84
85   test
86           test $label => sub { ... };
87
88       The "test" function adds a subtest.  The code reference will be called
89       with the test object as its only argument.
90
91       Tests are run in the order declared, so the order of tests from roles
92       will depend on when they are composed relative to other test
93       declarations.
94

AUTHOR

96       David Golden <dagolden@cpan.org>
97
99       This software is Copyright (c) 2013 by David Golden.
100
101       This is free software, licensed under:
102
103         The Apache License, Version 2.0, January 2004
104
105
106
107perl v5.28.0                      2014-08-05                Test::Roo::Role(3)
Impressum