Hello Amka,

Your question is slightly ambiguous, are you trying to test the 
content/body of the 302 message or the content/body of the message it 
redirects to? Most people don't include a body on their 302 so I'm going to 
assume you mean the latter. Assuming that's true, this is how you might 
test both.

```perl
# set the internal useragent to follow redirects
# in this case I'm only going to allow one since I only expect one
$t->ua->max_redirects(1);

# then test the request and the final response
$t->post_ok('/engre' => {Accept => '*/*'} => form => {a => '0.25', z => 
'10'})->status_is(200)->content_like(qr/principale/);

# then come back and test that there was a redirect and it was the 
appropriate status
my $redirect = $t->tx->previous;
ok $redirect, 'got a previous transaction';
is $redirect->res->code, 302, 'got the expected redirect code';

# if you don't care about the exact value you could have tested
ok $redirect->res->is_redirect, 'previous transaction was a redirect';
# however the fact that there was a previous transaction kinda implies that 
same thing.
```

Of course you could wrap some of that into its own test method, but that's 
only useful if you are going to do it a lot.

Cheers,
Joel

On Friday, July 7, 2017 at 11:57:44 AM UTC-5, [email protected] wrote:
>
> Hi,
>
> Can please someone say me how to check a content_like, in a mojolicious 
> test script, if a redirects occurs ?
>
> $t = $t->post_ok('/engre' => {Accept => '*/*'} => form => {a => '0.25', z 
> => '10'})->status_is(302)->content_like(qr/principale/);
>
> does not work.
>
> Thanks & best regards,
>
> Amka
>
>

-- 
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.

Reply via email to