NAME

Test::Mojo::Role::HTTPstatus

DESCRIPTION

Role to add some extra methods to Test::Mojo for testing routes' HTTP status codes

SYNOPSIS

  use Test::More;
  use Test::Mojo::WithRoles qw(HTTPstatus);

  my $t = Test::Mojo::WithRoles->new('MyApp');

  $t->get_ok('/success')->status_like(qr/^2/);
  $t->get_ok('/failure')->status_is_error();

  done_testing();

METHODS

status_like does most of the work behind the scenes. For completeness, its opposite status_unlike is also provided.

status_like
  $t = $t->status_like(qr/^4/);
  $t = $t->status_like(qr/^4/, 'some kind of error');

Pass if the status matches a given regex.

status_unlike
  $t = $t->status_unlike(qr/^3/);
  $t = $t->status_unlike(qr/^3/, 'not any kind of redirect');

Pass if the status does not match the given regex.

The various status_is_* methods match the is_* methods in Mojo::Message::Response.

status_is_client_error

Matches a 4xx status code.

status_is_empty

Matches a 1xx, 204, or 304 status code.

status_is_error

Matches a 4xx or 5xx status code.

status_is_info

Matches a 1xx status code.

status_is_redirect

Matches a 3xx status code.

status_is_server_error

Matches a 5xx status code.

status_is_success

Matches a 2xx status code.

BUGS

None known, plenty lurking no doubt. Please report any bugs that you find on Github:

https://github.com/DrHyde/perl-modules-Test-Mojo-Role-HTTPstatus/issues

or even better, raise a pull request that fixes it. The best pull requests include at least two commits, the first being a test that fails, and then in the following commits a code change that makes that test pass, and documentation. I realise that it is difficult to work in that manner, but git rebase -i will let you edit history to pretend that's what you did.

SEE ALSO

Test::Mojo

AUTHOR, COPYRIGHT and LICENCE

Copyright 2020 David Cantrell <david@cantrell.org.uk>

This software is free-as-in-speech software, and may be used, distributed, and modified under the terms of either the GNU General Public Licence version 2 or the Artistic Licence. It's up to you which one you use. The full text of the licences can be found in the files GPL2.txt and ARTISTIC.txt, respectively.

CONSPIRACY

This module is also free-as-in-mason software.