Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 39 lines (29 sloc) 1.06 kB
69485f9 @zentooo initial commit
authored
1 #!perl -w
2 use strict;
3 use Test::More;
4
d973518 @zentooo upside inside out
authored
5 use Sub::Spy qw/spy inspect/;
69485f9 @zentooo initial commit
authored
6
7 subtest("basic methods about count", sub {
8 my $subref = sub { return shift; };
d973518 @zentooo upside inside out
authored
9 my $spy = spy($subref);
69485f9 @zentooo initial commit
authored
10
11 $spy->();
d973518 @zentooo upside inside out
authored
12 is ( inspect($spy)->call_count, 1, "spy call count = 1" );
13 ok ( inspect($spy)->called, "spy has called!" );
14 ok ( inspect($spy)->called_times(1), "spy has called once" );
69485f9 @zentooo initial commit
authored
15
16 $spy->();
d973518 @zentooo upside inside out
authored
17 is ( inspect($spy)->call_count, 2, "spy call count = 1" );
18 ok ( inspect($spy)->called_times(2), "spy has called twice" );
69485f9 @zentooo initial commit
authored
19 });
20
21 subtest("methods about count", sub {
22 my $subref = sub { return shift; };
d973518 @zentooo upside inside out
authored
23 my $spy = spy($subref);
69485f9 @zentooo initial commit
authored
24
25 $spy->();
d973518 @zentooo upside inside out
authored
26 ok ( inspect($spy)->called_once, "spy called once" );
27 ok ( ! inspect($spy)->called_twice, "spy called once" );
69485f9 @zentooo initial commit
authored
28
29 $spy->();
d973518 @zentooo upside inside out
authored
30 ok ( ! inspect($spy)->called_once, "spy called once" );
31 ok ( inspect($spy)->called_twice, "spy called twice" );
32 ok ( ! inspect($spy)->called_thrice, "spy called once" );
69485f9 @zentooo initial commit
authored
33
34 $spy->();
d973518 @zentooo upside inside out
authored
35 ok ( inspect($spy)->called_thrice, "spy called thrice" );
69485f9 @zentooo initial commit
authored
36 });
37
38 done_testing;
Something went wrong with that request. Please try again.