KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
We have created the following simple Mojolicious controller: package SampleApp::Pages; # $Id$ use strict; use warnings; our $VERSION = '0.01'; use Mojo::Base 'Mojolicious::Controller'; sub home { my $self = shift; $self->render( 'title' => 'Home' ); return; } sub contact { my $self = shift; $self->render( 'title' => 'Contact' ); return; } sub about { my $self = shift; $self->render( 'title' => 'About' ); return; } 1; The corresponding unit tests look as follows: package Test::SampleApp::Pages; # $Id$ use strict; use warnings; our $VERSION = '0.01'; use Carp; use English '-no_match_vars'; use Readonly; use Test::Mojo; use Test::Most; use base 'Test::Class'; Readonly my $SERVER_OK => 200; sub startup : Tests(startup) { eval { require SampleApp; SampleApp->import; 1; } or Carp::croak($EVAL_ERROR); return; } sub get_home : Tests(4) { my $test = shift; my $mojo = $test->mojo; $mojo->get_ok('/pages/home')->status_is($SERVER_OK); $mojo->text_is( 'title', $test->base_title . ' | Home', '... and should have the right title' ); $mojo->content_like( qr/<body>(?:\s*\S+\s*)+<\/body>/msx, '... and should have a non-blank body' ); return; } sub get_contact : Tests(3) { my $test = shift; my $mojo = $test->mojo; $mojo->get_ok('/pages/contact')->status_is($SERVER_OK); $mojo->text_is( 'title', $test->base_title . ' | Contact', '... and should have the right title' ); return; } sub get_about : Tests(3) { my $test = shift; my $mojo = $test->mojo; $mojo->get_ok('/pages/about')->status_is($SERVER_OK); $mojo->text_is( 'title', $test->base_title . ' |
Tags (comma-separated)
Save Edits
Cancel