I have a controller method which makes calls using $controller->delay to 
another service.  I want to mock the response from these services so that 
unit tests can still run without needing to connect to the other services. 
 I've found a way by subscribing to the controller and the tx like so 
$t->app()->ua()->on(start => sub {
   my ($ua, $tx) = @_;
   $tx->on(finish => sub{
       my $tx = shift;
       my $mock_res = Mojo::Message::Response->new();
       $mock_res->code(200);
       $mock_res->body('{"foo":"bar"}');
       $tx->res($mock_res);
       return;
   }
});

This does what I want but will still make the call out to the service.  Is 
there a way to do something similar before the call gets made? Am I 
thinking about this wrong? 

Thanks

-- 
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 http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

Reply via email to