Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add testcase of `and_die` method. #8

Merged
merged 1 commit into from

1 participant

@NetPenguin
Owner

No description provided.

@NetPenguin NetPenguin merged commit 19678cc into from
@NetPenguin NetPenguin deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 1, 2013
This page is out of date. Refresh to see the latest.
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);
Something went wrong with that request. Please try again.