Skip to content

Commit

Permalink
modernized tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Oct 29, 2012
1 parent 0d2e5c1 commit 402d089
Show file tree
Hide file tree
Showing 86 changed files with 247 additions and 88 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,6 +1,7 @@

3.53 2012-10-28
3.53 2012-10-29
- Improved documentation.
- Improved tests.

3.52 2012-10-26
- Added boolean shortcut support to Mojo::JSON.
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojolicious/Command/generate/app.pm
Expand Up @@ -117,12 +117,14 @@ sub welcome {
% my $class = shift;
use Mojo::Base -strict;
use Test::More tests => 3;
use Test::More;
use Test::Mojo;
my $t = Test::Mojo->new('<%= $class %>');
$t->get_ok('/')->status_is(200)->content_like(qr/Mojolicious/i);
done_testing();
@@ layout
<!DOCTYPE html>
<html>
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojolicious/Command/generate/plugin.pm
Expand Up @@ -78,7 +78,7 @@ L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicio.us>.
% my $name = shift;
use Mojo::Base -strict;
use Test::More tests => 3;
use Test::More;
use Mojolicious::Lite;
use Test::Mojo;
Expand All @@ -93,6 +93,8 @@ get '/' => sub {
my $t = Test::Mojo->new;
$t->get_ok('/')->status_is(200)->content_is('Hello Mojo!');
done_testing();
@@ makefile
% my ($class, $path) = @_;
use strict;
Expand Down
4 changes: 3 additions & 1 deletion lib/Mojolicious/Guides/Cookbook.pod
Expand Up @@ -500,7 +500,7 @@ While the message flow on WebSocket connections can be rather dynamic, it
more often than not is quite predictable, which allows this rather pleasant
L<Test::Mojo> API to be used.

use Test::More tests => 4;
use Test::More;
use Test::Mojo;

# Include application
Expand All @@ -514,6 +514,8 @@ L<Test::Mojo> API to be used.
->message_is('echo: Hello Mojo!')
->finish_ok;

done_testing();

=head2 EventSource web service

EventSource is a special form of long-polling where you can directly send DOM
Expand Down
8 changes: 6 additions & 2 deletions lib/Mojolicious/Guides/Growing.pod
Expand Up @@ -283,7 +283,7 @@ L<Test::Mojo> is a scriptable HTTP user agent designed specifically for
testing, with many fun state of the art features such as CSS selectors based
on L<Mojo::DOM>.

use Test::More tests => 16;
use Test::More;
use Test::Mojo;

# Include application
Expand Down Expand Up @@ -314,6 +314,8 @@ on L<Mojo::DOM>.
->element_exists('form input[name="pass"]')
->element_exists('form input[type="submit"]');

done_testing();

From now on you can always check your progress by running these unit tests
against your application.

Expand Down Expand Up @@ -663,7 +665,7 @@ Only a few small details change.
Normal L<Mojolicious> applications are a little easier to test, so
C<t/login.t> can be simplified.

use Test::More tests => 16;
use Test::More;
use Test::Mojo;

# Load application class
Expand All @@ -686,6 +688,8 @@ C<t/login.t> can be simplified.
->element_exists('form input[name="pass"]')
->element_exists('form input[type="submit"]');

done_testing();

Test driven development takes a little getting used to, but is very well worth
it!

Expand Down
4 changes: 3 additions & 1 deletion lib/Mojolicious/Lite.pm
Expand Up @@ -868,7 +868,7 @@ Base64 encoded) or a C<public> directory if it exists.
Testing your application is as easy as creating a C<t> directory and filling
it with normal Perl unit tests.
use Test::More tests => 3;
use Test::More;
use Test::Mojo;
use FindBin;
Expand All @@ -877,6 +877,8 @@ it with normal Perl unit tests.
my $t = Test::Mojo->new;
$t->get_ok('/')->status_is(200)->content_like(qr/Funky/);
done_testing();
Run all unit tests with the C<test> command.
$ ./myapp.pl test
Expand Down
4 changes: 3 additions & 1 deletion lib/Test/Mojo.pm
Expand Up @@ -328,7 +328,7 @@ Test::Mojo - Testing Mojo!
=head1 SYNOPSIS
use Test::More tests => 12;
use Test::More;
use Test::Mojo;
my $t = Test::Mojo->new('MyApp');
Expand All @@ -349,6 +349,8 @@ Test::Mojo - Testing Mojo!
->message_is('echo: hello')
->finish_ok;
done_testing();
=head1 DESCRIPTION
L<Test::Mojo> is a collection of testing helpers for everyone developing
Expand Down
4 changes: 3 additions & 1 deletion t/mojo/app.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 63;
use Test::More;

use Mojo;
use Mojo::IOLoop;
Expand Down Expand Up @@ -265,3 +265,5 @@ ok !$tx2->error, 'no error';
ok $tx3->is_finished, 'transaction is finished';
is $tx3->res->body, 'Your Mojo is working!', 'right content';
ok !$tx3->error, 'no error';

done_testing();
4 changes: 3 additions & 1 deletion t/mojo/asset.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 65;
use Test::More;

use Mojo::Asset::File;
use Mojo::Asset::Memory;
Expand Down Expand Up @@ -147,3 +147,5 @@ undef $file;
ok -e $path, 'file exists';
unlink $path;
ok !-e $path, 'file has been cleaned up';

done_testing();
4 changes: 2 additions & 2 deletions t/mojo/base.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 415;
use Test::More;

use FindBin;
use lib "$FindBin::Bin/lib";
Expand Down Expand Up @@ -97,4 +97,4 @@ like $@, qr/Default has to be a code reference or constant value/,
eval { Mojo::BaseTest->attr(23) };
like $@, qr/Attribute "23" invalid/, 'right error';

1;
done_testing();
4 changes: 3 additions & 1 deletion t/mojo/bytestream.t
Expand Up @@ -2,7 +2,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 47;
use Test::More;

use File::Spec::Functions qw(catfile splitdir);
use File::Temp 'tempdir';
Expand Down Expand Up @@ -153,3 +153,5 @@ my $dir = tempdir CLEANUP => 1;
$file = catfile $dir, 'test.txt';
is b("just\nworks!")->spurt($file)->quote, qq{"just\nworks!"}, 'right result';
is b($file)->slurp, "just\nworks!", 'successful roundtrip';

done_testing();
4 changes: 3 additions & 1 deletion t/mojo/cache.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 20;
use Test::More;

use Mojo::Cache;

Expand Down Expand Up @@ -35,3 +35,5 @@ is $cache->get('foo'), undef, 'no result';
is $cache->get('bar'), 'baz', 'right result';
is $cache->get('baz'), 'yada', 'right result';
is $cache->get('yada'), 23, 'right result';

done_testing();
4 changes: 3 additions & 1 deletion t/mojo/cgi.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 22;
use Test::More;

use Mojo::Message::Response;
use Mojo::Server::CGI;
Expand Down Expand Up @@ -127,3 +127,5 @@ is $res->headers->content_type, 'application/json',
is $res->headers->content_length, 27, 'right "Content-Length" value';
is $res->json->{lalala}, 23, 'right value';
is $res->json->{bar}, 'baz', 'right value';

done_testing();
4 changes: 3 additions & 1 deletion t/mojo/collection.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 57;
use Test::More;

use Mojo::Collection 'c';

Expand Down Expand Up @@ -124,3 +124,5 @@ $collection = c(1, 2, 3, 2, 3, 4, 5, 4);
is_deeply [$collection->uniq->each], [1, 2, 3, 4, 5], 'right result';
is_deeply [$collection->uniq->reverse->uniq->each], [5, 4, 3, 2, 1],
'right result';

done_testing();
4 changes: 3 additions & 1 deletion t/mojo/content.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 25;
use Test::More;

use Mojo::Content::MultiPart;
use Mojo::Content::Single;
Expand Down Expand Up @@ -56,3 +56,5 @@ $content = Mojo::Content::MultiPart->new;
ok !$content->charset, 'no charset';
'a' =~ /(.)/;
ok !$content->boundary, 'no boundary';

done_testing();
4 changes: 3 additions & 1 deletion t/mojo/cookie.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 190;
use Test::More;

use Mojo::Cookie::Request;
use Mojo::Cookie::Response;
Expand Down Expand Up @@ -392,3 +392,5 @@ is $cookies->[0]->expires, 'Thu, 01 Jan 1970 00:00:00 GMT',
is $cookies->[0]->expires->epoch, 0, 'right expires epoch value';
is $cookies->[0]->secure, '1', 'right secure flag';
is $cookies->[1], undef, 'no more cookies';

done_testing();
3 changes: 2 additions & 1 deletion t/mojo/cookiejar.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 92;
use Test::More;

use Mojo::Cookie::Response;
use Mojo::URL;
Expand Down Expand Up @@ -304,3 +304,4 @@ is $cookies[0]->name, 'foo', 'right name';
is $cookies[0]->value, 'bar', 'right value';
is $cookies[1], undef, 'no second cookie';

done_testing();
4 changes: 3 additions & 1 deletion t/mojo/date.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 20;
use Test::More;

use Mojo::Date;

Expand Down Expand Up @@ -52,3 +52,5 @@ is(Mojo::Date->new('Thu, 01 Jan 1970 00:00:00 GMT')->epoch,
$date = Mojo::Date->new;
ok $date->parse('Mon, 01 Jan 1900 00:00:00'), 'right format';
is $date->epoch, undef, 'no epoch value';

done_testing();
4 changes: 3 additions & 1 deletion t/mojo/delay.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 14;
use Test::More;

use Mojo::IOLoop;
use Mojo::IOLoop::Delay;
Expand Down Expand Up @@ -125,3 +125,5 @@ $delay = Mojo::IOLoop->delay(
is_deeply [$delay->wait], [2, 3, 2, 1, 4, 5, 6], 'right numbers';
is $finished, 1, 'finish event has been emitted once';
is_deeply $result, [1, 2, 3, 2, 3, 2, 1, 4, 5, 6], 'right numbers';

done_testing();
3 changes: 2 additions & 1 deletion t/mojo/dom.t
Expand Up @@ -2,7 +2,7 @@ use Mojo::Base -strict;

use utf8;

use Test::More tests => 793;
use Test::More;

use Mojo::DOM;
use Mojo::Util 'encode';
Expand Down Expand Up @@ -2145,3 +2145,4 @@ is $dom->tree->[3][1], ' bad idea -- HTML5 ', 'right comment';
is $dom->tree->[5][1], ' HTML4 ', 'right comment';
is $dom->tree->[7][1], ' bad idea -- HTML4 ', 'right comment';

done_testing();
4 changes: 3 additions & 1 deletion t/mojo/eventemitter.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 46;
use Test::More;

use Mojo::EventEmitter;

Expand Down Expand Up @@ -140,3 +140,5 @@ $e->emit(one => $buffer => 'three');
is $buffer, 'abctwo123twoabcthree123threedef', 'right result';
$e->emit(one => $buffer => 'x');
is $buffer, 'abctwo123twoabcthree123threedefabcx123x', 'right result';

done_testing();
4 changes: 3 additions & 1 deletion t/mojo/headers.t
@@ -1,6 +1,6 @@
use Mojo::Base -strict;

use Test::More tests => 93;
use Test::More;

use Mojo::Headers;

Expand Down Expand Up @@ -185,3 +185,5 @@ EOF
ok $headers->is_finished, 'parser is finished';
is $headers->content_type, 'text/plain', 'right value';
is $headers->header('X-Bender'), 'Bite my shiny, metal ass!', 'right value';

done_testing();
4 changes: 3 additions & 1 deletion t/mojo/home.t
Expand Up @@ -3,7 +3,7 @@ use Mojo::Base -strict;
# Disable libev
BEGIN { $ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll' }

use Test::More tests => 15;
use Test::More;

use Cwd qw(cwd realpath);
use File::Spec::Functions qw(canonpath catdir splitdir);
Expand Down Expand Up @@ -64,3 +64,5 @@ like $home->slurp_rel_file('lib/Mojo/BaseTest/Base2.pm'), qr/Base2/,
'right content';
like $home->slurp_rel_file('lib/Mojo/BaseTest/Base3.pm'), qr/Base3/,
'right content';

done_testing();
3 changes: 2 additions & 1 deletion t/mojo/hypnotoad.t
Expand Up @@ -9,7 +9,6 @@ BEGIN {
use Test::More;
plan skip_all => 'set TEST_HYPNOTOAD to enable this test (developer only!)'
unless $ENV{TEST_HYPNOTOAD};
plan tests => 50;

use File::Spec::Functions 'catdir';
use File::Temp 'tempdir';
Expand Down Expand Up @@ -185,3 +184,5 @@ sub _pid {
chomp $pid;
return $pid;
}

done_testing();
4 changes: 3 additions & 1 deletion t/mojo/ioloop.t
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$ENV{MOJO_REACTOR} = 'Mojo::Reactor::Poll';
}

use Test::More tests => 32;
use Test::More;

use Mojo::IOLoop;
use Mojo::IOLoop::Client;
Expand Down Expand Up @@ -270,3 +270,5 @@ is(
Mojo::IOLoop->singleton->reactor,
'right default'
);

done_testing();

0 comments on commit 402d089

Please sign in to comment.