Subject: | Middleware doesn't re-wrap when using Kelp::Test |
While trying to run some tests using "Kelp::Test" against my own application, it kept throwing an error about:
not ok 3 - No Session middleware wrapped at /usr/share/perl5/vendor_perl/Kelp.pm line 219.
After having a view of the source, I think I see why...
While you use:
next if $self->{_loaded_middleware}->{$class}++;
to prevent the middleware from being re-loaded and re-wrapped around the application multiple times, that same "run()" method also creates the app each time its invoked.
Thus, if I were to take an App that specified middleware via "config.pl", and ran it in a test as follows:
$t->request(GET "/users/123")->code_is(200);
$t->request(GET "/users/123")->code_is(200);
I would get that "No Session middleware" error. The $app created by "run()" for the first request caused the modules to get loaded, and it was wrapped with that middleware. For the second request, however, "run()" determined that the modules were already loaded, and it was *not* wrapped with the middleware.
Perhaps, rather than using "$self->{_loaded_middleware}" to track if we've wrapped the App with that middleware, what about just using a hash in that function? Then, it'd re-wrap the newly created App each time it was invoked.
FYI... I did also check your own tests to see if I was doing something weird here, and I saw in your "middleware.t" test that it cleared the list of loaded middleware between each test invocation. I suspect that this is why it went un-noticed.
Your thoughts?