What I do is that I have a "base url" that I can override. That way I can make the requests go the the local process instead of to the internet.
You can have a look here for an example https://github.com/jhthorsen/mojolicious-plugin-stripepayment/blob/master/lib/Mojolicious/Plugin/StripePayment.pm#L300 https://github.com/jhthorsen/mojolicious-plugin-stripepayment/blob/master/lib/Mojolicious/Plugin/StripePayment.pm#L385 https://github.com/jhthorsen/mojolicious-plugin-stripepayment/blob/master/t/stripe-charge.t So when I register the plugin with "mocked" set to a true value, I change the "base_url" and pass all the requests my application and render the response with some additional routes created by the plugin. On Thursday, November 12, 2015 at 1:17:35 AM UTC+1, William Wheeler wrote: > > 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 mojolicious+unsubscr...@googlegroups.com. To post to this group, send email to mojolicious@googlegroups.com. Visit this group at http://groups.google.com/group/mojolicious. For more options, visit https://groups.google.com/d/optout.