4
package Test::Roo::Class;
5
# ABSTRACT: Base class for Test::Roo test classes
6
our $VERSION = '1.002'; # VERSION
9
use MooX::Types::MooseLike::Base qw/Str/;
10
use Test::More 0.96 import => [qw/subtest/];
12
#--------------------------------------------------------------------------#
14
#--------------------------------------------------------------------------#
24
sub _build_description {
25
my $class = ref $_[0];
26
return "testing with $class";
29
#--------------------------------------------------------------------------#
30
# class or object methods
31
#--------------------------------------------------------------------------#
36
# get hashref from end of args
37
# if any args are left, it must be description
39
$args = pop if @_ && ref $_[-1] eq 'HASH';
42
# create an object if needed and possibly update description
43
$self = $self->new( $args || {} )
45
$self->description($desc)
48
# execute tests wrapped in a subtest
49
subtest $self->description => sub {
56
#--------------------------------------------------------------------------#
57
# private methods and stubs
58
#--------------------------------------------------------------------------#
65
my ( $self, $code ) = @_;
72
# anchor for tests as method modifiers
78
# vim: ts=4 sts=4 sw=4 et:
88
Test::Roo::Class - Base class for Test::Roo test classes
96
This module is the base class for L<Test::Roo> test classes. It provides
97
methods to run tests and anchor modifiers. Generally, you should not extend
98
this class yourself, but use L<Test::Roo> to do so instead.
104
A description for a subtest block wrapping all tests by the object. It is a
105
'lazy' attribute. Test classes may implement their own C<_build_description>
106
method to create a description from object attributes. Otherwise, the default
107
is "testing with CLASS".
115
$class->run_tests($description);
116
$class->run_tests($init_args);
117
$class->run_tests($description $init_args);
119
# as an object method
121
$self->run_tests($description);
123
If called as a class method, this creates a test object using an optional hash
124
reference of initialization arguments.
126
When called as an object method, or after an object has been generated, this
127
method sets an optional description and runs tests. It will call the C<setup>
128
method (triggering any method modifiers), will run all tests (triggering any
129
method modifiers on C<each_test>) and will call the C<teardown> method
130
(triggering any method modifiers).
132
If a description is provided, it will override any initialized or generated
133
C<description> attribute.
135
The setup, tests and teardown will be executed in a L<Test::More> subtest
140
This is an empty method used to anchor method modifiers. It should not
141
be overridden by subclasses.
145
This method wraps the code references set by the C<test> function
146
from L<Test::Roo> or L<Test::Roo::Role> in a L<Test::More> subtest block.
148
It may also be used to anchor modifiers that should run before or after
149
each test block, though this can lead to brittle design as modifiers
150
will globally affect every test block, including composed ones.
154
This is an empty method used to anchor method modifiers. It should not
155
be overridden by subclasses.
157
=for Pod::Coverage each_test setup teardown
161
David Golden <dagolden@cpan.org>
163
=head1 COPYRIGHT AND LICENSE
165
This software is Copyright (c) 2013 by David Golden.
167
This is free software, licensed under:
169
The Apache License, Version 2.0, January 2004