summaryrefslogtreecommitdiff
path: root/t/exceptions/object.t
diff options
context:
space:
mode:
Diffstat (limited to 't/exceptions/object.t')
-rw-r--r--t/exceptions/object.t77
1 files changed, 77 insertions, 0 deletions
diff --git a/t/exceptions/object.t b/t/exceptions/object.t
new file mode 100644
index 0000000..71b78d4
--- /dev/null
+++ b/t/exceptions/object.t
@@ -0,0 +1,77 @@
+use strict;
+use warnings;
+
+use Test::More;
+use Test::Fatal;
+
+# tests for SingleParamsToNewMustBeHashRef
+{
+ {
+ package Foo;
+ use Moose;
+ }
+
+ my $exception = exception {
+ Foo->new("hello")
+ };
+
+ like(
+ $exception,
+ qr/^\QSingle parameters to new() must be a HASH ref/,
+ "A single non-hashref arg to a constructor throws an error");
+
+ isa_ok(
+ $exception,
+ "Moose::Exception::SingleParamsToNewMustBeHashRef",
+ "A single non-hashref arg to a constructor throws an error");
+}
+
+# tests for DoesRequiresRoleName
+{
+ {
+ package Foo;
+ use Moose;
+ }
+
+ my $foo = Foo->new;
+
+ my $exception = exception {
+ $foo->does;
+ };
+
+ like(
+ $exception,
+ qr/^\QYou must supply a role name to does()/,
+ "Cannot call does() without a role name");
+
+ isa_ok(
+ $exception,
+ "Moose::Exception::DoesRequiresRoleName",
+ "Cannot call does() without a role name");
+
+ is(
+ $exception->class_name,
+ "Foo",
+ "Cannot call does() without a role name");
+
+ $exception = exception {
+ Foo->does;
+ };
+
+ like(
+ $exception,
+ qr/^\QYou must supply a role name to does()/,
+ "Cannot call does() without a role name");
+
+ isa_ok(
+ $exception,
+ "Moose::Exception::DoesRequiresRoleName",
+ "Cannot call does() without a role name");
+
+ is(
+ $exception->class_name,
+ "Foo",
+ "Cannot call does() without a role name");
+}
+
+done_testing;