Last active
September 18, 2017 14:30
-
-
Save kwakwaversal/2dbaec33edbc590599bd7c62b39ced00 to your computer and use it in GitHub Desktop.
A placeholder rollback role which can be used by other roles to reset state #mojo #perl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package Test::Mojo::Role::Rollback; | |
use Role::Tiny; | |
sub rollback { } | |
1; | |
package Test::Mojo::Role::MyLogin; | |
use Role::Tiny; | |
use Test::More; | |
requires 'rollback'; | |
sub login_ok { | |
my ($t, $user, $password) = @_; | |
diag "Logging in to something"; | |
return $t; | |
} | |
after rollback => sub { | |
my $t = shift; | |
diag "Rollback MyLogin"; | |
return $t; | |
}; | |
1; | |
package Test::Mojo::Role::MyResetState; | |
use Role::Tiny; | |
use Test::More; | |
requires 'rollback'; | |
sub state_ok { | |
my ($t) = @_; | |
diag "Something which changes the state"; | |
return $t; | |
} | |
after rollback => sub { | |
my $t = shift; | |
diag "Rollback MyResetState"; | |
return $t; | |
}; | |
1; | |
package main; | |
use Mojo::Base -strict; | |
use Mojolicious::Lite; | |
get '/' => sub { | |
my $c = shift; | |
return $c->render(text => 'foo'); | |
}; | |
# Tests the lite app above. | |
use strict; | |
use warnings; | |
use Test::More; | |
use Test::Mojo::WithRoles qw/Rollback MyLogin MyResetState/; | |
my $t = Test::Mojo::WithRoles->new; | |
$t->get_ok('/')->login_ok()->state_ok()->rollback(); | |
# Alternatively | |
# END { | |
# $t->rollback(); | |
# } | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment