[Rt-commit] rt branch, 3.8-trunk, updated. rt-3.8.5-297-gd343e18

Ruslan Zakirov ruz at bestpractical.com
Wed Oct 14 05:51:31 EDT 2009


The branch, 3.8-trunk has been updated
       via  d343e18de308e6d3de4856d623450a3000758ac8 (commit)
       via  7b3d05fdc3977e7536b5dd71728af07ebc1c9447 (commit)
       via  9982496c0ca2cc46265b5eb894fc28edcbed3666 (commit)
      from  d8d0f822fbec2b66481de983dbade6ebced7d8c5 (commit)

Summary of changes:
 lib/RT/Test.pm            |  113 +++++++++++++++++++++++++-------------------
 t/maildigest/attributes.t |    2 +
 2 files changed, 66 insertions(+), 49 deletions(-)

- Log -----------------------------------------------------------------
commit 9982496c0ca2cc46265b5eb894fc28edcbed3666
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Oct 14 03:04:20 2009 +0400

    refactor catching mails in tests
    
    * we had duplication, mailsent_ok didn't work with catcher
    * use external file as tests under apache can not share variables

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index 6de822a..f2f0e9f 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -77,7 +77,6 @@ wrap 'HTTP::Request::Common::form_data',
 our @EXPORT = qw(is_empty);
 
 our ($port, $dbname);
-my $mailsent;
 
 =head1 NAME
 
@@ -147,15 +146,6 @@ sub import {
 
     if (RT->Config->Get('DevelMode')) { require Module::Refresh; }
 
-    # make it another function
-    $mailsent = 0;
-    my $mailfunc = sub { 
-        my $Entity = shift;
-        $mailsent++;
-        return 1;
-    };
-    RT->Config->Set( 'MailCommand' => $mailfunc );
-
     $class->bootstrap_db( %args );
 
     RT->Init;
@@ -202,6 +192,7 @@ sub db_requires_no_dba {
 }
 
 my $config;
+my $mailbox_catcher = File::Temp->new( OPEN => 0, CLEANUP => 0 )->filename;
 sub bootstrap_config {
     my $self = shift;
     my %args = @_;
@@ -224,6 +215,20 @@ Set( \$MailCommand, 'testfile');
     print $config "Set( \$DevelMode, 0 );\n"
         if $INC{'Devel/Cover.pm'};
 
+    # set mail catcher
+    print $config <<END;
+Set( \$MailCommand, sub {
+    my \$MIME = shift;
+
+    open my \$handle, '>>', '$mailbox_catcher'
+        or die "Unable to open '$mailbox_catcher' for appending: \$!";
+
+    \$MIME->print(\$handle);
+    print \$handle "%% split me! %%\n";
+    close \$handle;
+} );
+END
+
     print $config $args{'config'} if $args{'config'};
 
     print $config "\n1;\n";
@@ -377,29 +382,6 @@ sub _get_dbh {
     return $dbh;
 }
 
-sub open_mailgate_ok {
-    my $class   = shift;
-    my $baseurl = shift;
-    my $queue   = shift || 'general';
-    my $action  = shift || 'correspond';
-    Test::More::ok(open(my $mail, "|$RT::BinPath/rt-mailgate --url $baseurl --queue $queue --action $action"), "Opened the mailgate - $!");
-    return $mail;
-}
-
-
-sub close_mailgate_ok {
-    my $class = shift;
-    my $mail  = shift;
-    close $mail;
-    Test::More::is ($? >> 8, 0, "The mail gateway exited normally. yay");
-}
-
-sub mailsent_ok {
-    my $class = shift;
-    my $expected  = shift;
-    Test::More::is ($mailsent, $expected, "The number of mail sent ($expected) matches. yay");
-}
-
 =head1 UTILITIES
 
 =head2 load_or_create_user
@@ -654,40 +636,71 @@ sub send_via_mailgate {
     my $message = shift;
     my %args = (@_);
 
-    my ($status, $gate_result) = $self->run_mailgate( message => $message, %args );
+    my ($status, $gate_result) = $self->run_mailgate(
+        message => $message, %args
+    );
 
     my $id;
     unless ( $status >> 8 ) {
         ($id) = ($gate_result =~ /Ticket:\s*(\d+)/i);
         unless ( $id ) {
-            Test::More::diag "Couldn't find ticket id in text:\n$gate_result" if $ENV{'TEST_VERBOSE'};
+            Test::More::diag "Couldn't find ticket id in text:\n$gate_result"
+                if $ENV{'TEST_VERBOSE'};
         }
     } else {
-        Test::More::diag "Mailgate output:\n$gate_result" if $ENV{'TEST_VERBOSE'};
+        Test::More::diag "Mailgate output:\n$gate_result"
+            if $ENV{'TEST_VERBOSE'};
     }
     return ($status, $id);
 }
 
-my $mailbox_catcher = File::Temp->new( OPEN => 0, CLEANUP => 0 )->filename;
-sub set_mail_catcher {
-    my $self = shift;
-    my $catcher = sub {
-        my $MIME = shift;
+sub open_mailgate_ok {
+    my $class   = shift;
+    my $baseurl = shift;
+    my $queue   = shift || 'general';
+    my $action  = shift || 'correspond';
+    Test::More::ok(open(my $mail, "|$RT::BinPath/rt-mailgate --url $baseurl --queue $queue --action $action"), "Opened the mailgate - $!");
+    return $mail;
+}
 
-        open my $handle, '>>', $mailbox_catcher
-            or die "Unable to open $mailbox_catcher for appending: $!";
 
-        $MIME->print($handle);
-        print $handle "%% split me! %%\n";
-        close $handle;
-    };
-    RT->Config->Set( MailCommand => $catcher );
+sub close_mailgate_ok {
+    my $class = shift;
+    my $mail  = shift;
+    close $mail;
+    Test::More::is ($? >> 8, 0, "The mail gateway exited normally. yay");
+}
+
+sub mailsent_ok {
+    my $class = shift;
+    my $expected  = shift;
+
+    my $mailsent = scalar grep /\S/, split /%% split me! %%\n/,
+        RT::Test->file_content(
+            $mailbox_catcher,
+            'unlink' => 0,
+            noexist => 1
+        );
+
+    Test::More::is(
+        $mailsent, $expected,
+        "The number of mail sent ($expected) matches. yay"
+    );
+}
+
+sub set_mail_catcher {
+    my $self = shift;
+    return 1;
 }
 
 sub fetch_caught_mails {
     my $self = shift;
     return grep /\S/, split /%% split me! %%\n/,
-        RT::Test->file_content( $mailbox_catcher, 'unlink' => 1, noexist => 1 );
+        RT::Test->file_content(
+            $mailbox_catcher,
+            'unlink' => 1,
+            noexist => 1
+        );
 }
 
 sub clean_caught_mails {

commit 7b3d05fdc3977e7536b5dd71728af07ebc1c9447
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Oct 14 12:09:09 2009 +0400

    adjust test level so failures reported in the right place

diff --git a/t/maildigest/attributes.t b/t/maildigest/attributes.t
index f52ed00..ba2a585 100644
--- a/t/maildigest/attributes.t
+++ b/t/maildigest/attributes.t
@@ -152,6 +152,8 @@ sub email_digest_like {
     my $arg = shift;
     my $pattern = shift;
 
+    local $Test::Builder::Level = $Test::Builder::Level + 1;
+
     my $perl = $^X . ' ' . join ' ', map { "-I$_" } @INC;
     open my $digester, "-|", "$perl $RT::SbinPath/rt-email-digest $arg";
     my @results = <$digester>;

commit d343e18de308e6d3de4856d623450a3000758ac8
Author: Ruslan Zakirov <ruz at bestpractical.com>
Date:   Wed Oct 14 12:10:13 2009 +0400

    clean cought emails on END

diff --git a/lib/RT/Test.pm b/lib/RT/Test.pm
index f2f0e9f..b072d51 100644
--- a/lib/RT/Test.pm
+++ b/lib/RT/Test.pm
@@ -1173,6 +1173,8 @@ END {
 
     RT::Test->stop_server;
 
+    RT::Test->clean_caught_mails;
+
     if ( $ENV{RT_TEST_PARALLEL} && $created_new_db ) {
 
         # Pg doesn't like if you issue a DROP DATABASE while still connected

-----------------------------------------------------------------------


More information about the Rt-commit mailing list