use strict;
use warnings;
+use Test::Exception;
use Test::More;
-use Test::Moose 'does_ok';
+use Test::Moose;
my %handles = (
inc_counter => 'inc',
);
{
- package MyHomePage;
+
+ package Foo;
use Moose;
has 'counter' => (
);
}
-my $page = MyHomePage->new();
-isa_ok( $page, 'MyHomePage' );
+can_ok( 'Foo', $_ ) for sort keys %handles;
+
+with_immutable {
+ my $page = Foo->new();
+
+ is( $page->counter, 0, '... got the default value' );
-can_ok( $page, $_ ) for sort keys %handles;
+ $page->inc_counter;
+ is( $page->counter, 1, '... got the incremented value' );
-is( $page->counter, 0, '... got the default value' );
+ $page->inc_counter;
+ is( $page->counter, 2, '... got the incremented value (again)' );
-$page->inc_counter;
-is( $page->counter, 1, '... got the incremented value' );
+ throws_ok { $page->inc_counter( 1, 2 ) }
+ qr/Cannot call inc with more than 1 argument/,
+ 'inc throws an error when two arguments are passed';
-$page->inc_counter;
-is( $page->counter, 2, '... got the incremented value (again)' );
+ $page->dec_counter;
+ is( $page->counter, 1, '... got the decremented value' );
-$page->dec_counter;
-is( $page->counter, 1, '... got the decremented value' );
+ throws_ok { $page->dec_counter( 1, 2 ) }
+ qr/Cannot call dec with more than 1 argument/,
+ 'dec throws an error when two arguments are passed';
-$page->reset_counter;
-is( $page->counter, 0, '... got the original value' );
+ $page->reset_counter;
+ is( $page->counter, 0, '... got the original value' );
-$page->set_counter(5);
-is( $page->counter, 5, '... set the value' );
+ throws_ok { $page->reset_counter(2) }
+ qr/Cannot call reset with any arguments/,
+ 'reset throws an error when an argument is passed';
-$page->inc_counter(2);
-is( $page->counter, 7, '... increment by arg' );
+ $page->set_counter(5);
+ is( $page->counter, 5, '... set the value' );
-$page->dec_counter(5);
-is( $page->counter, 2, '... decrement by arg' );
+ throws_ok { $page->set_counter( 1, 2 ) }
+ qr/Cannot call set with more than 1 argument/,
+ 'set throws an error when two arguments are passed';
-$page->inc_counter_2;
-is( $page->counter, 4, '... curried increment' );
+ $page->inc_counter(2);
+ is( $page->counter, 7, '... increment by arg' );
-$page->dec_counter_2;
-is( $page->counter, 2, '... curried deccrement' );
+ $page->dec_counter(5);
+ is( $page->counter, 2, '... decrement by arg' );
-$page->set_counter_42;
-is( $page->counter, 42, '... curried set' );
+ $page->inc_counter_2;
+ is( $page->counter, 4, '... curried increment' );
+
+ $page->dec_counter_2;
+ is( $page->counter, 2, '... curried deccrement' );
+
+ $page->set_counter_42;
+ is( $page->counter, 42, '... curried set' );
+}
+'Foo';
done_testing;