Skip Menu |

This queue is for tickets about the Catalyst CPAN distribution.

Report information
The Basics
Id: 78051
Status: new
Priority: 0/
Queue: Catalyst

People
Owner: Nobody in particular
Requestors: john.whitley [...] heartinternet.co.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: [Patch] Catalyst::Test cannot test HTTP methods other than GET - limiting the test of a RESTful site
Catalyst::Test seems to be set up to test GET requests to the exclusion of other HTTP methods. This is normally fine: however, during the development of a RESTful website this restriction makes testing harder. I have developed a mechanism that works here, but accept that this may not be the direction in which the development of Catalyst::Test was intending to head. I have attached a patch as it is probably better to suggest a solution than request someone else to have to develop one. This solution works by using the extra_env hash that gets passed to the _customize_request method. Here the keys within extra_env are assumed to be the same as the methods available in the Request instance, and values to be the parameter to pass to the method. As I mentioned, this may not the correct solution, and if not please feed back. This is a feature that is having increasing importance for us, and I may be able to develop something more in-line with how this should actually be implemented. Thanks for your time!
Subject: Catalyst-Test-5.90013.pm.patch
--- Catalyst-Test-5.90013.pm 2012-06-26 09:09:21.402414864 +0100 +++ Catalyst-Test-5.90013.pm.patched 2012-06-26 09:20:13.758245752 +0100 @@ -250,11 +250,20 @@ =head2 $res = request( ... ); Returns an L<HTTP::Response> object. Accepts an optional hashref for request -header configuration; currently only supports setting 'host' value. +header configuration. The parameter host works as it has previously. my $res = request('foo/bar?test=1'); my $virtual_res = request('foo/bar?test=1', {host => 'virtualhost.com'}); +You may also provide settings to the Request object via the extra_env +hash parameter. The extra_env value is a hashref where the key is the +method name that you wish to call to configure the Request instance, and +the value is the value that you wish to pass to the method. For example, +you may wish to set the HTTP method, to test the different functionality +between a GET and a POST request. + + my $virtual_res = request('foo/bar?test=1', { extra_env => { method => 'POST' } } ); + =head2 ($res, $c) = ctx_request( ... ); Works exactly like L<request|/"$res = request( ... );">, except it also returns the Catalyst context object, @@ -410,6 +419,12 @@ if (my $extra = $opts->{extra_env}) { @{ $extra_env }{keys %{ $extra }} = values %{ $extra }; } + + foreach my $method_name ( keys %$extra_env ) { + if ( $request->can( $method_name ) ) { + $request->$method_name( $extra_env->{$method_name} ); + } + } } =head2 action_ok($url [, $test_name ])