Skip to content

jberger/Test-Mojo-WithRoles

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NAME

Test::Mojo::WithRoles - Use Test::Mojo roles cleanly and safely

SYNOPSIS

package Test::Mojo::Role::MyRole;

use Role::Tiny;

sub is_awesome {
  my ($t, ...) = @_;
  # do some test
}

---

# myapp.t

use Test::More;
use Test::Mojo::WithRoles 'MyRole';
my $t = Test::Mojo::WithRoles->new('MyApp');

$t->get_ok(...)
  ->is_awesome(...);

done_testing;

DESCRIPTION

Test::Mojo::WithRoles builds composite subclasses of Test::Mojo based on a lexically specified set of roles. This is easy to use and plays nicely with others.

Of course this is all just sugar for the mechanisms provided by Role::Tiny.

IMPORTING

{
  use Test::Mojo::WithRoles qw/MyRole +Test::MyRole/;
  my $t = Test::Mojo::WithRoles->new('MyApp');
  $t->does('Test::Mojo::Role::MyRole'); # true
  $t->does('Test::MyRole'); # true
}

my $t = Test::Mojo::WithRoles->new;
$t->does('Test::Mojo::Role::MyRole'); # false

Pass a list of roles when you import Test::Mojo::WithRoles. Those roles will be used to construct a subclass of Test::Mojo with those roles when new is called within that lexical scope. After leaving that lexical scope, the roles specified are no longer in effect when constructing a new object.

Roles specified without a leading + sign are assumed to be in the Test::Mojo::Role namespace. Roles specified with a leading + sign are used literally as the fully qualified package name.

SEE ALSO

Test::Mojo
Mojolicious
Role::Tiny

SOURCE REPOSITORY

http://github.com/jberger/Test-Mojo-WithRoles

AUTHOR

Joel Berger, <joel.a.berger@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2015 by Joel Berger

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

About

A role framework for Test::Mojo

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages