Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #8 from NetPenguin/add-testcase-of-and_die

Add testcase of `and_die` method.
  • Loading branch information...
commit 19678ccf703bb6f255d3395e25c5ae130d667150 2 parents e4ed395 + d98d181
@NetPenguin authored
Showing with 45 additions and 3 deletions.
  1. +45 −3 t/01.total.t
View
48 t/01.total.t
@@ -14,6 +14,7 @@ BEGIN {
});
}
use Test::Deep qw(ignore);
+use Test::Exception;
use Scalar::Util qw(weaken);
# ----
@@ -75,6 +76,18 @@ subtest 'default mock' => sub {
reset($mock);
+ subtest 'expect and_die' => sub {
+ my $error = 'an error message';
+ expect($mock->foo)->and_die($error);
+ replay($mock);
+
+ throws_ok { $mock->foo } qr{$error}, 'throw error';
+
+ verify($mock);
+ };
+
+ reset($mock);
+
subtest 'with Test::Deep comparison parameter' => sub {
my $result1 = 'a result of first.';
my $result2 = 'a result of sencond.';
@@ -208,7 +221,7 @@ subtest 'default mock' => sub {
subtest 'expect with `stub_scalar_return`, but no call mock method.' => sub {
expect($mock->foo())->and_stub_scalar_return('');
replay($mock);
- verify($mock); # pass
+ verify($mock); # pass
};
reset($mock);
@@ -243,7 +256,7 @@ subtest 'default mock' => sub {
subtest 'expect with `stub_array_return`, but no call mock method.' => sub {
expect($mock->foo())->and_stub_array_return('');
replay($mock);
- verify($mock); # pass
+ verify($mock); # pass
};
reset($mock);
@@ -278,7 +291,36 @@ subtest 'default mock' => sub {
subtest 'expect with `stub_list_return`, but no call mock method.' => sub {
expect($mock->foo())->and_stub_list_return('');
replay($mock);
- verify($mock); # pass
+ verify($mock); # pass
+ };
+
+ reset($mock);
+
+ subtest 'and_stub_die' => sub {
+ my $args1 = 'argument';
+ my $error1_1 = 'an error message of first';
+ my $error1_2 = 'an error message of second';
+ my $args2 = 'other';
+ my $error2 = 'an error message of other';
+
+ expect($mock->foo($args1))->and_die($error1_1);
+ expect($mock->foo($args1))->and_stub_die($error1_2);
+ expect($mock->foo($args2))->and_stub_die($error2);
+ replay($mock);
+
+ throws_ok { $mock->foo($args1) } qr{$error1_1}, 'throw error1_1';
+ throws_ok { $mock->foo($args1) } qr{$error1_2}, 'throw error1_2';
+ throws_ok { $mock->foo($args2) } qr{$error2}, 'throw error2';
+
+ verify($mock);
+ };
+
+ reset($mock);
+
+ subtest 'expect with `stub_die`, but no call mock method.' => sub {
+ expect($mock->foo())->and_stub_die('');
+ replay($mock);
+ verify($mock); # pass
};
reset($mock);
Please sign in to comment.
Something went wrong with that request. Please try again.