I notice that Mojo::UserAgent can make mock web server when I run unit test.
code like this:

use 5.010;
use strict;
use warnings;
use Mojolicious;
use Mojo::UserAgent;

my $ua = Mojo::UserAgent->new;

# Mock web service
$ua->server->app(Mojolicious->new);
$ua->server->app->routes->get(
    '/time' => sub {
        my $c = shift;
        $c->render(json => {now => time});
    }
);

my $time;
$ua->get('/time', sub {
    my ($ua, $tx) = @_;

    $time = $tx->res->json->{now};
});

Mojo::IOLoop->start unless Mojo::IOLoop->is_running;

say $time;

When I try to execute the script, I found Mojo::IOLoop won't stop until I 
press Ctrl-C.

Is there a way to mock Mojo::UserAgent in non-blocking request ?

-- 
You received this message because you are subscribed to the Google Groups 
"Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to