For anyone looking for a working example of mocking a service in a test
file and overriding the configuration (standard style disclaimers apply),
here is the equivalent of the original (non-working) post using a full
Mojolicious app:
use Mojo::Base -strict;
use Test::More;
use Test::Mojo;
package Foo;
use Mojo::Base 'Mojolicious';
sub startup {
my $app = shift;
$app->plugin(Config => {default => {jack => 'squat'}});
$app->routes->get('/' => sub {
my $c = shift;
$c->render(text => $c->app->config->{jack});
});
}
package main;
my $t = Test::Mojo->new(Foo => {jack => 'flack'});
$t->get_ok('/')
->content_is('flack')
->or(sub { say STDERR $t->app->dumper(shift->tx->res->body) });
done_testing();
In my case, I have a second lite app I've loaded in the test file that I
can now point to use the mocked instance—handy to have one test file stand
up and tear down the mocked service along with the tests.
Scott
On Thursday, September 27, 2018 at 10:01:16 AM UTC-6, sri wrote:
>
> > Config overriding works only for full apps
>
> Actually that's not true, but i see this here is a special case.
> Config overrides only
> work with full apps and instances of lite apps. Lite apps in classes
> are a pretty
> bad hack and do not work here.
>
> --
> Sebastian Riedel
> https://mojolicious.org
> https://github.com/kraih
> https://twitter.com/kraih
>
--
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.