Navigation Menu

Skip to content

Commit

Permalink
updated Test::Mojo to use new Test::Stream::Context
Browse files Browse the repository at this point in the history
  • Loading branch information
jberger committed Jan 8, 2015
1 parent ab8be9b commit fbd3c26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Makefile.PL
Expand Up @@ -28,7 +28,8 @@ WriteMakefile(
PREREQ_PM => {
'IO::Socket::IP' => '0.26',
'Pod::Simple' => '3.09',
'Time::Local' => '1.2'
'Time::Local' => '1.2',
'Test::Simple' => '1.301001097',
},
EXE_FILES => ['script/hypnotoad', 'script/mojo', 'script/morbo'],
test => {TESTS => 't/*.t t/*/*.t'}
Expand Down
11 changes: 6 additions & 5 deletions lib/Test/Mojo.pm
Expand Up @@ -15,6 +15,7 @@ use Mojo::Server;
use Mojo::UserAgent;
use Mojo::Util qw(decode encode);
use Test::More ();
use Test::Stream::Toolset ();

has [qw(message success tx)];
has ua => sub { Mojo::UserAgent->new->ioloop(Mojo::IOLoop->singleton) };
Expand Down Expand Up @@ -310,7 +311,7 @@ sub websocket_ok {

sub _build_ok {
my ($self, $method, $url) = (shift, shift, shift);
local $Test::Builder::Level = $Test::Builder::Level + 1;
my $ctx = Test::Stream::Toolset::context();
return $self->_request_ok($self->ua->build_tx($method, $url, @_), $url);
}

Expand All @@ -321,7 +322,7 @@ sub _json {

sub _message {
my ($self, $name, $value, $desc) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 1;
my $ctx = Test::Stream::Toolset::context();
my ($type, $msg) = @{$self->message // []};

# Type check
Expand All @@ -340,7 +341,7 @@ sub _message {
sub _request_ok {
my ($self, $tx, $url) = @_;

local $Test::Builder::Level = $Test::Builder::Level + 1;
my $ctx = Test::Stream::Toolset::context();

# Establish WebSocket connection
if ($tx->req->is_handshake) {
Expand All @@ -364,15 +365,15 @@ sub _request_ok {
# Perform request
$self->tx($self->ua->start($tx));
my $err = $self->tx->error;
Test::More::diag $err->{message}
$ctx->diag($err->{message})
if !(my $ok = !$err->{message} || $err->{code}) && $err;
my $desc = encode 'UTF-8', "@{[uc $tx->req->method]} $url";
return $self->_test('ok', $ok, $desc);
}

sub _test {
my ($self, $name, @args) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 2;
my $ctx = Test::Stream::Toolset::context(1);
return $self->success(!!Test::More->can($name)->(@args));
}

Expand Down

0 comments on commit fbd3c26

Please sign in to comment.