/
computing.t
65 lines (58 loc) · 1.26 KB
/
computing.t
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use Test;
use Test::Mock;
plan 6;
class Yak {
has $.shaved;
}
class Shaver {
method shave($yak) {
...
}
}
class YakStore {
method get-all-yaks() {
...
}
}
class YakShaving {
has $.yak-store;
has $.yak-shaver;
method proccess() {
for $!yak-store.get-all-yaks() -> $yak {
unless $yak.shaved {
$!yak-shaver.shave($yak);
}
}
}
}
my $shaver = mocked(Shaver);
my $store = mocked(YakStore, computing => {
get-all-yaks => { Yak.new(:!shaved), Yak.new(:shaved), Yak.new(:!shaved) }
});
my $yaktivity = YakShaving.new(
yak-store => $store,
yak-shaver => $shaver
);
$yaktivity.proccess();
check-mock($store,
*.called('get-all-yaks', times => 1)
);
check-mock($shaver,
*.called('shave', times => 2, with => :($ where { !$^y.shaved })),
*.never-called('shave', with => :($ where { $^y.shaved }))
);
$shaver = mocked(Shaver);
$store = mocked(YakStore, computing => {
get-all-yaks => { die "Boom!" }
});
$yaktivity = YakShaving.new(
yak-store => $store,
yak-shaver => $shaver
);
throws-like { $yaktivity.proccess() }, X::AdHoc, message => "Boom!";
check-mock($store,
*.called('get-all-yaks', times => 1)
);
check-mock($shaver,
*.never-called('shave')
);