Add with_immutable to Test::Mouse
gfx [Wed, 16 Dec 2009 08:22:28 +0000 (17:22 +0900)]
lib/Test/Mouse.pm

index 34697eb..a9583bf 100644 (file)
@@ -10,6 +10,7 @@ Mouse::Exporter->setup_import_methods(
         meta_ok
         does_ok
         has_attribute_ok
+        with_immutable
     )],
 );
 
@@ -60,6 +61,20 @@ sub has_attribute_ok ($$;$) {
     }
 }
 
+sub with_immutable (&@) {
+    my $block = shift;
+
+    my $before = $Test->current_test;
+
+    $block->();
+    $_->meta->make_immutable for @_;
+    $block->();
+
+    my $num_tests = $Test->current_test - $before;
+
+    return !grep{ !$_ } ($Test->summary)[-$num_tests .. -1];
+}
+
 1;
 __END__