[Rt-commit] rt branch, 4.4/test-fail-content-dump, created. rt-4.4.0rc1-4-g8d449b6

Shawn Moore shawn at bestpractical.com
Tue Nov 17 11:46:24 EST 2015


The branch, 4.4/test-fail-content-dump has been created
        at  8d449b6dd242be4daabcf317145f139a73ad5b8d (commit)

- Log -----------------------------------------------------------------
commit 8d449b6dd242be4daabcf317145f139a73ad5b8d
Author: Shawn M Moore <shawn at bestpractical.com>
Date:   Tue Nov 17 16:45:22 2015 +0000

    On content_* or text_* fails, dump content in tmp
    
        Fixes: I#31408

diff --git a/lib/RT/Test/Web.pm b/lib/RT/Test/Web.pm
index 46cdc05..7f2b9c7 100644
--- a/lib/RT/Test/Web.pm
+++ b/lib/RT/Test/Web.pm
@@ -432,6 +432,36 @@ sub dom {
     return Mojo::DOM->new( $self->content );
 }
 
+# override content_* and text_* methods in Test::Mech to dump the content
+# on failure, to speed investigation
+for my $method_name (qw/
+    content_is content_contains content_lacks content_like content_unlike
+    text_contains text_lacks text_like text_unlike
+/) {
+    my $super_method = __PACKAGE__->SUPER::can($method_name);
+    my $implementation = sub {
+        local $Test::Builder::Level = $Test::Builder::Level + 1;
+
+        my $self = shift;
+        my $ok = $self->$super_method(@_);
+        if (!$ok) {
+            my $dir = RT::Test->temp_directory;
+            my ($name) = $self->uri =~ m{/([^/]+)$};
+            my $file = $dir . '/' . RT::Test->builder->current_test . '-' . $name;
+
+            open my $handle, '>', $file or die $@;
+            print $handle $self->content or die $@;
+            close $handle or die $@;
+
+            Test::More::diag("Dumped failing test page content to $file");
+        }
+        return $ok;
+    };
+
+    no strict 'refs';
+    *{$method_name} = $implementation;
+}
+
 sub DESTROY {
     my $self = shift;
 

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


More information about the rt-commit mailing list