From: Dave Rolsky Date: Mon, 8 Sep 2008 17:21:13 +0000 (+0000) Subject: Add some tests for the error handling in Moose::Object, and fix a bug X-Git-Tag: 0.58~43 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3ce5143912e8c9995e1251073377e155a81af82e;p=gitmo%2FMoose.git Add some tests for the error handling in Moose::Object, and fix a bug I found which motivated said tests. --- diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index 1c6f441..cdab64e 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -24,7 +24,7 @@ sub BUILDARGS { if (scalar @_ == 1) { if (defined $_[0]) { (ref($_[0]) eq 'HASH') - || $class->throw_error("Single parameters to new() must be a HASH ref", data => $_[0]); + || $class->meta->throw_error("Single parameters to new() must be a HASH ref", data => $_[0]); return {%{$_[0]}}; } else { diff --git a/t/010_basics/017_error_handling.t b/t/010_basics/017_error_handling.t new file mode 100644 index 0000000..081ced0 --- /dev/null +++ b/t/010_basics/017_error_handling.t @@ -0,0 +1,20 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 2; +use Test::Exception; + +# This tests the error handling in Moose::Object only + +{ + package Foo; + use Moose; +} + +throws_ok { Foo->new('bad') } qr/^\QSingle parameters to new() must be a HASH ref/, + 'A single non-hashref arg to a constructor throws an error'; + +throws_ok { Foo->does() } qr/^\QYou much supply a role name to does()/, + 'Cannot call does() without a role name';