Notes + extra test for EPO workshop and YAPC::EU 2009
[catagits/catbook-code.git] / t / snippet / simple.t
diff --git a/t/snippet/simple.t b/t/snippet/simple.t
new file mode 100644 (file)
index 0000000..f5a7440
--- /dev/null
@@ -0,0 +1,55 @@
+use strict;
+use warnings;
+use Test::More qw(no_plan);
+use Test::Moose;
+use Test::Exception;
+use aliased 'LolCatalyst::Lite::Snippet';
+
+{ package MockTranslator;
+  use Moose;
+  sub can_translate_to { $_[1] eq 'uc' };
+
+  sub translate { return uc $_[1] };
+}
+
+my ($id, $snippet);
+
+has_attribute_ok(Snippet, "id", "Snippets know about thier own id");
+has_attribute_ok(Snippet, "text", "Snippets have text attr");
+
+
+dies_ok {
+  $snippet = Snippet->new(
+    id => rand 9_999,
+    translator => MockTranslator->new
+  )
+} qr/\(text\) is required/;
+
+dies_ok {
+  $snippet = Snippet->new(
+    text => "hi there",
+    translator => MockTranslator->new
+  )
+} qr/\(id\) is required/;
+
+dies_ok {
+  $snippet = Snippet->new(
+    id => rand 9_999,
+    text => "hi there",
+  )
+} qr/\(translator\) is required/;
+
+lives_ok {
+  $snippet = Snippet->new(
+    id => ($id = rand 9_999),
+    text => "hi there",
+    translator => MockTranslator->new
+  )
+} "Can create a snippet";
+
+is($snippet->id, $id, "this snippet has the right id");
+is($snippet->text, "hi there");
+
+is($snippet->translated(), "HI THERE", "and the snippet can be translated");
+
+