[Moose-commits] r7467 - MooseX-Params-Validate/trunk/t
autarch at code2.0beta.co.uk
autarch at code2.0beta.co.uk
Sun Feb 1 15:38:54 GMT 2009
Author: autarch
Date: 2009-02-01 07:38:54 -0800 (Sun, 01 Feb 2009)
New Revision: 7467
Modified:
MooseX-Params-Validate/trunk/t/001_basic.t
Log:
Use throws_ok to do a basic check on the exception (because otherwise
we could die for _any_ reason and still report success)
Modified: MooseX-Params-Validate/trunk/t/001_basic.t
===================================================================
--- MooseX-Params-Validate/trunk/t/001_basic.t 2009-02-01 15:10:26 UTC (rev 7466)
+++ MooseX-Params-Validate/trunk/t/001_basic.t 2009-02-01 15:38:54 UTC (rev 7467)
@@ -68,39 +68,41 @@
is( $foo->baz( foo => $foo ), $foo, '... foo param must be a Foo instance' );
-dies_ok { $foo->baz( foo => 10 ) }
-'... the foo param in &baz must be a Foo instance';
-dies_ok { $foo->baz( foo => "foo" ) }
-'... the foo param in &baz must be a Foo instance';
-dies_ok { $foo->baz( foo => [] ) }
-'... the foo param in &baz must be a Foo instance';
+throws_ok { $foo->baz( foo => 10 ) } qr/\QThe 'foo' parameter ("10")/,
+ '... the foo param in &baz must be a Foo instance';
+throws_ok { $foo->baz( foo => "foo" ) } qr/\QThe 'foo' parameter ("foo")/,
+ '... the foo param in &baz must be a Foo instance';
+throws_ok { $foo->baz( foo => [] ) } qr/\QThe 'foo' parameter/,
+ '... the foo param in &baz must be a Foo instance';
is( $foo->baz( bar => $foo ), $foo, '... bar param must do Roles::Blah' );
-dies_ok { $foo->baz( bar => 10 ) }
+throws_ok { $foo->baz( bar => 10 ) } qr/\QThe 'bar' parameter ("10")/,
'... the bar param in &baz must be do Roles::Blah';
-dies_ok { $foo->baz( bar => "foo" ) }
+throws_ok { $foo->baz( bar => "foo" ) } qr/\QThe 'bar' parameter ("foo")/,
'... the bar param in &baz must be do Roles::Blah';
-dies_ok { $foo->baz( bar => [] ) }
+throws_ok { $foo->baz( bar => [] ) } qr/\QThe 'bar' parameter/,
'... the bar param in &baz must be do Roles::Blah';
is( $foo->baz( boo => $foo ), $foo, '... boo param must do Roles::Blah' );
-dies_ok { $foo->baz( boo => 10 ) }
+throws_ok { $foo->baz( boo => 10 ) } qr/\QThe 'boo' parameter ("10")/,
'... the boo param in &baz must be do Roles::Blah';
-dies_ok { $foo->baz( boo => "foo" ) }
+throws_ok { $foo->baz( boo => "foo" ) } qr/\QThe 'boo' parameter ("foo")/,
'... the boo param in &baz must be do Roles::Blah';
-dies_ok { $foo->baz( boo => [] ) }
+throws_ok { $foo->baz( boo => [] ) } qr/\QThe 'boo' parameter/,
'... the boo param in &baz must be do Roles::Blah';
-dies_ok { $foo->bar } '... bar has a required params';
-dies_ok { $foo->bar( foo => 10 ) }
-'... the foo param in &bar must be a Foo instance';
-dies_ok { $foo->bar( foo => "foo" ) }
-'... the foo param in &bar must be a Foo instance';
-dies_ok { $foo->bar( foo => [] ) }
-'... the foo param in &bar must be a Foo instance';
-dies_ok { $foo->bar( baz => [] ) } '... bar has a required foo param';
+throws_ok { $foo->bar } qr/\QMandatory parameter 'foo'/,
+ '... bar has a required param';
+throws_ok { $foo->bar( foo => 10 ) } qr/\QThe 'foo' parameter ("10")/,
+ '... the foo param in &bar must be a Foo instance';
+throws_ok { $foo->bar( foo => "foo" ) } qr/\QThe 'foo' parameter ("foo")/,
+ '... the foo param in &bar must be a Foo instance';
+throws_ok { $foo->bar( foo => [] ) } qr/\QThe 'foo' parameter/,
+ '... the foo param in &bar must be a Foo instance';
+throws_ok { $foo->bar( baz => [] ) } qr/\QMandatory parameter 'foo'/,,
+ '... bar has a required foo param';
is_deeply(
$foo->bar( foo => $foo ),
@@ -120,14 +122,18 @@
'... the foo param and baz param in &bar got a correct args'
);
-dies_ok { $foo->bar( foo => $foo, baz => undef ) }
-'... baz requires a ArrayRef | HashRef';
-dies_ok { $foo->bar( foo => $foo, baz => 10 ) }
-'... baz requires a ArrayRef | HashRef';
-dies_ok { $foo->bar( foo => $foo, baz => 'Foo' ) }
-'... baz requires a ArrayRef | HashRef';
-dies_ok { $foo->bar( foo => $foo, baz => \( my $var ) ) }
-'... baz requires a ArrayRef | HashRef';
+throws_ok { $foo->bar( foo => $foo, baz => undef ) }
+qr/\QThe 'baz' parameter (undef)/,
+ '... baz requires a ArrayRef | HashRef';
+throws_ok { $foo->bar( foo => $foo, baz => 10 ) }
+qr/\QThe 'baz' parameter ("10")/,
+ '... baz requires a ArrayRef | HashRef';
+throws_ok { $foo->bar( foo => $foo, baz => 'Foo' ) }
+qr/\QThe 'baz' parameter ("Foo")/,
+ '... baz requires a ArrayRef | HashRef';
+throws_ok { $foo->bar( foo => $foo, baz => \( my $var ) ) }
+qr/\QThe 'baz' parameter/,
+ '... baz requires a ArrayRef | HashRef';
is_deeply(
$foo->bar( foo => $foo, gorch => [ 1, 2, 3 ] ),
@@ -135,14 +141,19 @@
'... the foo param in &bar got a Foo instance'
);
-dies_ok { $foo->bar( foo => $foo, gorch => undef ) }
-'... gorch requires a ArrayRef[Int]';
-dies_ok { $foo->bar( foo => $foo, gorch => 10 ) }
-'... gorch requires a ArrayRef[Int]';
-dies_ok { $foo->bar( foo => $foo, gorch => 'Foo' ) }
-'... gorch requires a ArrayRef[Int]';
-dies_ok { $foo->bar( foo => $foo, gorch => \( my $var ) ) }
-'... gorch requires a ArrayRef[Int]';
-dies_ok { $foo->bar( foo => $foo, gorch => [qw/one two three/] ) }
-'... gorch requires a ArrayRef[Int]';
+throws_ok { $foo->bar( foo => $foo, gorch => undef ) }
+qr/\QThe 'gorch' parameter (undef)/,
+ '... gorch requires a ArrayRef[Int]';
+throws_ok { $foo->bar( foo => $foo, gorch => 10 ) }
+qr/\QThe 'gorch' parameter ("10")/,
+ '... gorch requires a ArrayRef[Int]';
+throws_ok { $foo->bar( foo => $foo, gorch => 'Foo' ) }
+qr/\QThe 'gorch' parameter ("Foo")/,
+ '... gorch requires a ArrayRef[Int]';
+throws_ok { $foo->bar( foo => $foo, gorch => \( my $var ) ) }
+qr/\QThe 'gorch' parameter/,
+ '... gorch requires a ArrayRef[Int]';
+throws_ok { $foo->bar( foo => $foo, gorch => [qw/one two three/] ) }
+qr/\QThe 'gorch' parameter/,
+ '... gorch requires a ArrayRef[Int]';
More information about the Moose-commits
mailing list