Notes + extra test for EPO workshop and YAPC::EU 2009
[catagits/catbook-code.git] / t / snippet / simple.t
CommitLineData
98cb0f3d 1use strict;
2use warnings;
3use Test::More qw(no_plan);
4use Test::Moose;
5use Test::Exception;
6use aliased 'LolCatalyst::Lite::Snippet';
7
8{ package MockTranslator;
9 use Moose;
10 sub can_translate_to { $_[1] eq 'uc' };
11
12 sub translate { return uc $_[1] };
13}
14
15my ($id, $snippet);
16
17has_attribute_ok(Snippet, "id", "Snippets know about thier own id");
18has_attribute_ok(Snippet, "text", "Snippets have text attr");
19
20
21dies_ok {
22 $snippet = Snippet->new(
23 id => rand 9_999,
24 translator => MockTranslator->new
25 )
26} qr/\(text\) is required/;
27
28dies_ok {
29 $snippet = Snippet->new(
30 text => "hi there",
31 translator => MockTranslator->new
32 )
33} qr/\(id\) is required/;
34
35dies_ok {
36 $snippet = Snippet->new(
37 id => rand 9_999,
38 text => "hi there",
39 )
40} qr/\(translator\) is required/;
41
42lives_ok {
43 $snippet = Snippet->new(
44 id => ($id = rand 9_999),
45 text => "hi there",
46 translator => MockTranslator->new
47 )
48} "Can create a snippet";
49
50is($snippet->id, $id, "this snippet has the right id");
51is($snippet->text, "hi there");
52
53is($snippet->translated(), "HI THERE", "and the snippet can be translated");
54
55