You think about this right. The problem is the perl's infrastructure
doesn't have any tools to write and run usable unit tests. That's why
everybody writes slow functional tests. And particularly Mojo::UserAgent
isn't very unit-testing-friendly at all.
But if you insist. Here is an example that should give you an idea:
https://gist.github.com/alexbyk/8d5877dd0df6fd329835
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
<mailto:mojolicious+unsubscr...@googlegroups.com>.
To post to this group, send email to mojolicious@googlegroups.com
<mailto:mojolicious@googlegroups.com>.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.
--
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.