[dancer-users] Dancer::Test and params()

Tom Hukins tom at eborcom.com
Tue Sep 3 14:26:01 BST 2013


Hi,

I'm working with a Dancer 1 code base that uses Dancer::Test to test
itself.

One particular route does the following:

    post '/register' => sub {
        my $user = param( 'user, 'post' );
        my $password = param( 'pass', 'post' );
    };

And it has tests like this:

    my $response = dancer_response POST => 'register',
        { params => { user => 'me', pass => 'secret' } };

However, I notice that param() only takes one argument, the name of
the parameter to fetch.  Unlike params(), it cannot specify the
parameter's source.

I also notice that the documentation for Dancer::Test doesn't state
what it does with "params" passed to it.  I expect the author of the
code I maintain intended to pass these in the HTTP body, whereas I
notice it passes them in the query string.  Currently, I can encode
POST parameters myself and pass them to dancer_response() in the
"body" argument, as "body" must contain a string.

I plan to implement the following, but thought I would see if anyone
objects before I do so:

1. Document that the "params" argument to dancer_response() always
populates the query string, even for POST requests.

2. Allow the "body" argument to dancer_response() to take a hash
reference as well as a string and make dancer_response() serialise the
hash reference.

3. Have Dancer::param() warn if passed more than one argument to help
people who mistakenly assume it takes the same arguments as params().

Do my plans seem reasonable?  Have I missed a better approach?

Thanks,
Tom


More information about the dancer-users mailing list