Created
October 8, 2018 11:42
-
-
Save j1n3l0/7d60f25e9f9dc5a6a3c21e25b083d2b6 to your computer and use it in GitHub Desktop.
This file contains 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
use 5.026; | |
use Test::Most; | |
{ | |
package Process; | |
use Moo; | |
has state => ( is => 'ro', lazy => 1, default => sub { { } } ); | |
sub at_max_retries { $_[0]->state->{retries} // 0 >= 10 } | |
sub retry { $_[0]->state->{retries}++ } | |
} | |
my $process = new_ok Process => []; | |
cmp_methods( | |
$process, | |
[ | |
at_max_retries => bool(0), | |
state => { }, | |
], | |
'not yet at max retries and state is empty', | |
); | |
$process->retry for 1 .. 10; | |
cmp_methods( | |
$process, | |
[ | |
at_max_retries => bool(1), | |
state => { retries => 10 }, | |
], | |
'at max retries and state contains retries', | |
); | |
done_testing; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment