Skip to content
Browse files

take advantage of Test::Log::Dispatch to test logging, rather than us…

…ing a scalarref directly. also renaming the logger attr to not conflict with logger being Pinto::Logger itself.
  • Loading branch information...
1 parent be2b044 commit 9d424ff98eec8972db2133a71ccd3a218a885b56 @karenetheridge committed Mar 29, 2012
Showing with 12 additions and 27 deletions.
  1. +3 −2 lib/Pinto/Logger.pm
  2. +9 −25 lib/Pinto/Tester.pm
View
5 lib/Pinto/Logger.pm
@@ -74,7 +74,8 @@ my %normal = ( text => undef, background => undef );
my %bold_yellow = ( text => 'yellow', background => undef, bold => 1 );
my %bold_red = ( text => 'red', background => undef, bold => 1 );
-has logger => (
+has log_handler => (
+ is => 'rw',
isa => 'Log::Dispatch',
lazy => 1,
default => sub {
@@ -162,7 +163,7 @@ Dies with the given message.
sub fatal {
my ($self, $message) = @_;
- $self->logger->log_and_die(level => 'fatal', message => $message);
+ $self->log_handler->log_and_die(level => 'fatal', message => $message);
}
View
34 lib/Pinto/Tester.pm
@@ -9,6 +9,7 @@ use MooseX::Types::Moose qw(ScalarRef HashRef);
use Carp;
use IO::String;
use Path::Class;
+use Test::Log::Dispatch;
use Pinto;
use Pinto::Util;
@@ -56,14 +57,6 @@ has root => (
);
-has buffer => (
- is => 'ro',
- isa => ScalarRef,
- default => sub { \my $buffer },
- writer => '_set_buffer',
-);
-
-
has tb => (
is => 'ro',
isa => 'Test::Builder',
@@ -79,28 +72,19 @@ sub _build_pinto {
my $creator = Pinto::Creator->new( root => $self->root() );
$creator->create( $self->creator_args() );
- my %defaults = ( out => $self->buffer(), verbose => 3, root => $self->root() );
+ my %defaults = ( log_handler => Test::Log::Dispatch->new, verbose => 3, root => $self->root() );
return Pinto->new(%defaults, $self->pinto_args());
}
#------------------------------------------------------------------------------
-sub bufferstr {
- my ($self) = @_;
-
- return ${ $self->buffer() };
-}
+# for backcompat
+sub reset_buffer { goto &reset_log }
-#------------------------------------------------------------------------------
-
-sub reset_buffer {
- my ($self, $new_buffer) = @_;
-
- $new_buffer ||= \my $buffer;
- my $io = IO::String->new( ${$new_buffer} );
- $self->pinto->logger->{out} = $io; # Hack!
- $self->_set_buffer($new_buffer);
+sub reset_log {
+ my ($self) = @_;
+ $self->pinto->logger->log_handler(Test::Log::Dispatch->new);
return $self;
}
@@ -227,7 +211,7 @@ sub log_like {
$name ||= 'Log output matches';
- $self->tb->like( $self->bufferstr(), $rx, $name );
+ $self->pinto->logger->log_handler->contains_ok($rx, $name);
return;
}
@@ -239,7 +223,7 @@ sub log_unlike {
$name ||= 'Log output does not match';
- $self->tb->unlike( $self->bufferstr(), $rx, $name );
+ $self->pinto->logger->log_handler->does_not_contain_ok($rx, $name);
return;
}

0 comments on commit 9d424ff

Please sign in to comment.
Something went wrong with that request. Please try again.