OSDN Git Service

Newslash::Util::TestMan: add Mail subclass
authorhylom <hylom@users.sourceforge.jp>
Wed, 28 Nov 2018 11:14:46 +0000 (20:14 +0900)
committerhylom <hylom@users.sourceforge.jp>
Wed, 28 Nov 2018 11:14:46 +0000 (20:14 +0900)
src/newslash_web/lib/Newslash/Util/TestMan/Mail.pm [new file with mode: 0644]

diff --git a/src/newslash_web/lib/Newslash/Util/TestMan/Mail.pm b/src/newslash_web/lib/Newslash/Util/TestMan/Mail.pm
new file mode 100644 (file)
index 0000000..784191e
--- /dev/null
@@ -0,0 +1,44 @@
+package Newslash::Util::TestMan::Mail;
+
+use strict;
+use warnings;
+use utf8;
+use feature ':5.10';
+use Exporter 'import';
+
+use Test::More;
+use Data::Dumper;
+
+sub new {
+    my ($class, $mail, $options) = @_;
+    $options ||= {};
+    bless {
+           options => $options,
+           mail => $mail,
+           last_match => {},
+          }, $class;
+}
+
+sub mail { return shift->{mail}; }
+sub body { return shift->mail->{body} };
+sub to { return shift->mail->{to} };
+
+sub to_is {
+    my ($self, $address, $message) = @_;
+    is($self->to, $address, $message);
+    return $self;
+}
+
+sub body_matches {
+    my ($self, $regex, $message) = @_;
+    ok($self->body =~ $regex, $message);
+    $self->{last_match} = {%+};
+    return $self;
+}
+
+sub last_match {
+    return shift->{last_match};
+}
+
+
+1;