Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Reload a Catalyst application during testing

by gwg (Beadle)
on May 09, 2019 at 17:24 UTC ( #1233514=perlquestion: print w/replies, xml ) Need Help??

gwg has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

A seemingly simple question that is currently evading my perl- and google-fu.

How does one reload / restart a Catalyst application during testing? I'm using Test::WWW::Mechanize::Catalyst and want to reload the Catalyst app with a different configuration. Obviously this can easily be done by splitting up the tests into two different files, but I'd prefer to keep them together.

Some pseudocode to demonstrate the situation:

my $mech = Test::WWW::Mechanize::Catalyst->new( catalyst_app => "CoolC +atalystApp" ); run_tests( $mech ); # the application has various read-only values that get initialised fr +om the environment # when the app starts up. Alter those values to test alternative confi +gs. change_config(); # what goes here?! # just creating a new mech does not reflect changes in the environment + that # should result in a different config missing_step_to_reload_catalyst_app(); run_tests( $mech );

Replies are listed 'Best First'.
Re: Reload a Catalyst application during testing
by Your Mother (Archbishop) on May 09, 2019 at 17:41 UTC

    I believe Catalyst forbids/ignores live app config changes (sidenote: this has nothing to with model data, just $ctx->config stuff) after ->setup is run. There are probably some hacky re->import(…)/unload things you could try but I don’t think it’s a good idea.

    So, for “what goes here?” the easy and clear answer is a new test file with something like local $ENV{CATALYST_CONFIG_LOCAL_SUFFIX} = "other_test" at the top matching your new test config. If you use a PSGI test runner or something instead of the built-in test lib you could probably do this more easily in one test file, in blocks or subtests, but it doesn’t seem like it’s as transparent or a big gain over two test files.

Re: Reload a Catalyst application during testing
by talexb (Canon) on May 10, 2019 at 12:04 UTC

    Can't you just use two separate scopes?

    { { my $mech = Test::WWW::Mechanize::Catalyst->new( catalyst_app => "CoolCatalystApp" ); run_tests( $mech ); } change_config(); { my $mech = Test::WWW::Mechanize::Catalyst->new( catalyst_app => "CoolCatalystApp" ); run_tests( $mech ); } }
    Once the app goes out of scope, it doesn't exist any more.

    Alex / talexb / Toronto

    Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      Doh. Thank you, sometimes the most obvious answer is staring you in the face!

      - gwg (not logged in)

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1233514]
Front-paged by haukex
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2021-12-01 10:48 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (3 votes). Check out past polls.