Commit | Line | Data |
98cb0f3d |
1 | use strict; |
2 | use warnings; |
3 | use Test::More qw(no_plan); |
4 | use Test::Moose; |
5 | use Test::Exception; |
6 | use 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 | |
15 | my ($id, $snippet); |
16 | |
17 | has_attribute_ok(Snippet, "id", "Snippets know about thier own id"); |
18 | has_attribute_ok(Snippet, "text", "Snippets have text attr"); |
19 | |
20 | |
21 | dies_ok { |
22 | $snippet = Snippet->new( |
23 | id => rand 9_999, |
24 | translator => MockTranslator->new |
25 | ) |
26 | } qr/\(text\) is required/; |
27 | |
28 | dies_ok { |
29 | $snippet = Snippet->new( |
30 | text => "hi there", |
31 | translator => MockTranslator->new |
32 | ) |
33 | } qr/\(id\) is required/; |
34 | |
35 | dies_ok { |
36 | $snippet = Snippet->new( |
37 | id => rand 9_999, |
38 | text => "hi there", |
39 | ) |
40 | } qr/\(translator\) is required/; |
41 | |
42 | lives_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 | |
50 | is($snippet->id, $id, "this snippet has the right id"); |
51 | is($snippet->text, "hi there"); |
52 | |
53 | is($snippet->translated(), "HI THERE", "and the snippet can be translated"); |
54 | |
55 | |