summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/jitterbug/Emailer.pm26
-rw-r--r--t/006_emailer.t25
2 files changed, 34 insertions, 17 deletions
diff --git a/lib/jitterbug/Emailer.pm b/lib/jitterbug/Emailer.pm
index 648c72f..4bf2e51 100644
--- a/lib/jitterbug/Emailer.pm
+++ b/lib/jitterbug/Emailer.pm
@@ -3,6 +3,7 @@ package jitterbug::Emailer;
use strict;
use warnings;
use Email::Stuff;
+use JSON;
sub new {
my $self = bless {} => shift;
@@ -16,30 +17,33 @@ sub new {
}
sub run {
- my $self = shift;
- my $task = $self->{'task'};
- my $buildconf = $self->{'conf'}->{'jitterbug'}{'build_process'};
- my $project = $task->project->name;
+ my $self = shift;
+ my $task = $self->{'task'};
+ my $buildconf = $self->{'conf'}->{'jitterbug'}{'build_process'};
+ my $project = $task->project->name;
my $tap_output = $self->{'tap_output'};
- my $sha1 = $task->commit->sha256;
- my $desc = JSON::decode_json( $task->commit->content );
- my $email = $desc->{'author'}{'email'};
+ my $sha1 = $task->commit->sha256;
+ my $desc = JSON::decode_json( $task->commit->content );
+ my $email = $desc->{'author'}{'email'};
my $body = <<BODY;
$tap_output
BODY
- Email::Stuff->from($buildconf->{'on_failure_from_email'})
- ->to($email)
+ my $stuff = Email::Stuff->from($buildconf->{'on_failure_from_email'})
+ # bug in Email::Stuff brakes chaining if $email is empty
+ ->to($email || " ")
->cc($buildconf->{'on_failure_cc_email'})
->text_body($body)
->subject(
$buildconf->{'on_failure_subject_prefix'} . "$project @ $sha1"
- )
+ );
# Should we attach a build log for convenience?
# ->attach(io('dead_bunbun_faked.gif')->all,
# filename => 'dead_bunbun_proof.gif')
- ->send;
+ $self->{'last_email_sent'} = $stuff;
+
+ $stuff->send;
return $self;
}
diff --git a/t/006_emailer.t b/t/006_emailer.t
index 2df25f1..0dce025 100644
--- a/t/006_emailer.t
+++ b/t/006_emailer.t
@@ -1,29 +1,42 @@
use strict;
use warnings;
-use Test::Most tests => 3;
+use Test::Most tests => 5;
use Data::Dumper;
use Test::MockObject;
use_ok "jitterbug::Emailer";
{
- my $conf = { jitterbug => { build_process => 'bar'} };
- my $commit = Test::MockObject->new;
+ my $buildconf = {
+ on_failure_from_email => 'bob@example.com',
+ on_failure_cc_email => 'steve@apple.com',
+ on_failure_subject_prefix => 'BLARG',
+ };
+
+ my $conf = { jitterbug => { build_process => $buildconf } };
+ my $commit = Test::MockObject->new;
my $project = Test::MockObject->new;
- my $task = Test::MockObject->new;
+ my $task = Test::MockObject->new;
$project->mock('name', sub { 'ponie' });
$commit->mock('sha256', sub { 'c0decafe' });
- $commit->mock('content', sub { 'this should be JSON' } );
+ $commit->mock('content', sub { '{ }' } );
$task->mock('commit', sub { $commit });
$task->mock('project', sub { $project });
- my $tap = "1..1\nok 1\n";
+ my $tap = "THIS IS TAP";
my $e = jitterbug::Emailer->new($conf, $task, $tap);
isa_ok($e,'jitterbug::Emailer');
can_ok($e,qw/new run/);
+ $e->run;
+ my $email = $e->{'last_email_sent'}{'email'};
+ like($email->body, qr/THIS IS TAP/, 'email body looks right');
+
+ my $header = $email->{'header'};
+ isa_ok($header, 'Email::MIME::Header');
+
}