Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better message tests
  • Loading branch information
kraih committed Mar 17, 2015
1 parent 3ab74fd commit e858821
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 37 deletions.
2 changes: 1 addition & 1 deletion t/mojo/daemon.t
Expand Up @@ -97,7 +97,7 @@ like $@, qr/^Can't find application class "Mojo::DoesNotExist" in \@INC/,
'right error';

# Transaction
isa_ok $app->build_tx, 'Mojo::Transaction::HTTP', 'right class';
isa_ok $app->build_tx, 'Mojo::Transaction::HTTP', 'right transaction';

# Fresh application
$app = Mojolicious->new;
Expand Down
4 changes: 2 additions & 2 deletions t/mojo/loader.t
Expand Up @@ -15,7 +15,7 @@ ok !!UNIVERSAL::can(B => 'svref_2object'), 'method found';

# Exception
my $e = load_class 'Mojo::LoaderException';
isa_ok $e, 'Mojo::Exception', 'right object';
isa_ok $e, 'Mojo::Exception', 'right exception';
like $e->message, qr/Missing right curly/, 'right message';
is $e->lines_before->[0][0], 2, 'right number';
is $e->lines_before->[0][1], '', 'right line';
Expand All @@ -33,7 +33,7 @@ like "$e", qr/Missing right curly/, 'right message';

# Complicated exception
$e = load_class 'Mojo::LoaderException2';
isa_ok $e, 'Mojo::Exception', 'right object';
isa_ok $e, 'Mojo::Exception', 'right exception';
like $e->message, qr/Exception/, 'right message';
is $e->lines_before->[0][0], 1, 'right number';
is $e->lines_before->[0][1], 'package Mojo::LoaderException2;', 'right line';
Expand Down
41 changes: 20 additions & 21 deletions t/mojo/request.t
Expand Up @@ -749,19 +749,20 @@ is $req->headers->content_type,
'multipart/form-data; boundary=----------0xKhTmLbOuNdArY',
'right "Content-Type" value';
is $req->headers->content_length, 416, 'right "Content-Length" value';
isa_ok $req->content->parts->[0], 'Mojo::Content::Single', 'right part';
isa_ok $req->content->parts->[1], 'Mojo::Content::Single', 'right part';
isa_ok $req->content->parts->[2], 'Mojo::Content::Single', 'right part';
ok !$req->content->parts->[0]->is_multipart, 'no multipart content';
ok !$req->content->parts->[1]->is_multipart, 'no multipart content';
ok !$req->content->parts->[2]->is_multipart, 'no multipart content';
ok !$req->content->parts->[0]->asset->is_file, 'stored in memory';
is $req->content->parts->[0]->asset->slurp, "hallo welt test123\n",
'right content';
is $req->body_params->to_hash->{text1}, "hallo welt test123\n", 'right value';
is $req->body_params->to_hash->{text2}, '', 'right value';
is $req->upload('upload')->filename, 'hello.pl', 'right filename';
isa_ok $req->upload('upload')->asset, 'Mojo::Asset::Memory', 'right file';
is $req->upload('upload')->filename, 'hello.pl', 'right filename';
ok !$req->upload('upload')->asset->is_file, 'stored in memory';
is $req->upload('upload')->asset->size, 69, 'right size';
my $file = catfile(tempdir(CLEANUP => 1), ("MOJO_TMP." . time . ".txt"));
isa_ok $req->upload('upload')->move_to($file), 'Mojo::Upload', 'moved file';
is $req->upload('upload')->move_to($file)->filename, 'hello.pl',
'right filename';
ok unlink($file), 'unlinked file';
is $req->content->boundary, '----------0xKhTmLbOuNdArY', 'right boundary';

Expand Down Expand Up @@ -815,9 +816,9 @@ is $req->headers->content_type,
'multipart/form-data; boundary=----------0xKhTmLbOuNdArY',
'right "Content-Type" value';
is $req->headers->content_length, 562, 'right "Content-Length" value';
isa_ok $req->content->parts->[0], 'Mojo::Content::Single', 'right part';
isa_ok $req->content->parts->[1], 'Mojo::Content::Single', 'right part';
isa_ok $req->content->parts->[2], 'Mojo::Content::Single', 'right part';
ok !$req->content->parts->[0]->is_multipart, 'no multipart content';
ok !$req->content->parts->[1]->is_multipart, 'no multipart content';
ok !$req->content->parts->[2]->is_multipart, 'no multipart content';
ok $req->content->parts->[0]->asset->is_file, 'stored in file';
is $req->content->parts->[0]->asset->slurp, "hallo welt test123\n",
'right content';
Expand All @@ -826,12 +827,10 @@ is $req->body_params->to_hash->{text2}, '', 'right value';
is $req->upload('upload')->filename, 'bye.txt', 'right filename';
is $req->upload('upload')->asset->size, 4, 'right size';
is $req->every_upload('upload')->[0]->filename, 'hello.pl', 'right filename';
isa_ok $req->every_upload('upload')->[0]->asset, 'Mojo::Asset::File',
'right file';
ok $req->every_upload('upload')->[0]->asset->is_file, 'stored in file';
is $req->every_upload('upload')->[0]->asset->size, 69, 'right size';
is $req->every_upload('upload')->[1]->filename, 'bye.txt', 'right filename';
isa_ok $req->every_upload('upload')->[1]->asset, 'Mojo::Asset::Memory',
'right file';
ok !$req->every_upload('upload')->[1]->asset->is_file, 'stored in memory';
is $req->every_upload('upload')->[1]->asset->size, 4, 'right size';

# Parse HTTP 1.1 multipart request (with callbacks and stream)
Expand Down Expand Up @@ -898,9 +897,9 @@ is $req->headers->content_type,
'multipart/form-data; boundary=----------0xKhTmLbOuNdArY',
'right "Content-Type" value';
is $req->headers->content_length, 418, 'right "Content-Length" value';
isa_ok $req->content->parts->[0], 'Mojo::Content::Single', 'right part';
isa_ok $req->content->parts->[1], 'Mojo::Content::Single', 'right part';
isa_ok $req->content->parts->[2], 'Mojo::Content::Single', 'right part';
ok !$req->content->parts->[0]->is_multipart, 'no multipart content';
ok !$req->content->parts->[1]->is_multipart, 'no multipart content';
ok !$req->content->parts->[2]->is_multipart, 'no multipart content';
is $req->content->parts->[0]->asset->slurp, "hallo welt test123\n",
'right content';
is $req->body_params->to_hash->{text1}, "hallo welt test123\n", 'right value';
Expand Down Expand Up @@ -942,7 +941,7 @@ is $req->headers->content_type,
'multipart/form-data; boundary=----------0xKhTmLbOuNdArY',
'right "Content-Type" value';
is $req->headers->content_length, 418, 'right "Content-Length" value';
isa_ok $req->content, 'Mojo::Content::Single', 'right content';
ok !$req->content->is_multipart, 'no multipart content';
like $req->content->asset->slurp, qr/------------0xKhTmLbOuNdArY--$/,
'right content';

Expand Down Expand Up @@ -976,16 +975,16 @@ is $req->headers->content_type,
'multipart/form-data; boundary=----------0xKhTmLbOuNdArY',
'right "Content-Type" value';
is $req->headers->content_length, 410, 'right "Content-Length" value';
isa_ok $req->content->parts->[0], 'Mojo::Content::Single', 'right part';
isa_ok $req->content->parts->[1], 'Mojo::Content::Single', 'right part';
isa_ok $req->content->parts->[2], 'Mojo::Content::Single', 'right part';
ok !$req->content->parts->[0]->is_multipart, 'no multipart content';
ok !$req->content->parts->[1]->is_multipart, 'no multipart content';
ok !$req->content->parts->[2]->is_multipart, 'no multipart content';
is $req->content->parts->[0]->asset->slurp, "hallo welt test123\n",
'right content';
is $req->body_params->to_hash->{text1}, "hallo welt test123\n", 'right value';
is $req->body_params->to_hash->{text2}, '', 'right value';
is $req->body_params->to_hash->{upload}, undef, 'not a body parameter';
is $req->upload('upload')->filename, '0', 'right filename';
isa_ok $req->upload('upload')->asset, 'Mojo::Asset::Memory', 'right file';
ok !$req->upload('upload')->asset->is_file, 'stored in memory';
is $req->upload('upload')->asset->size, 69, 'right size';

# Parse full HTTP 1.1 proxy request with basic authentication
Expand Down
22 changes: 11 additions & 11 deletions t/mojo/response.t
Expand Up @@ -470,9 +470,9 @@ is $res->version, '1.1', 'right version';
is $res->headers->content_type,
'multipart/form-data; boundary=----------0xKhTmLbOuNdArY',
'right "Content-Type" value';
isa_ok $res->content->parts->[0], 'Mojo::Content::Single', 'right part';
isa_ok $res->content->parts->[1], 'Mojo::Content::Single', 'right part';
isa_ok $res->content->parts->[2], 'Mojo::Content::Single', 'right part';
ok !$res->content->parts->[0]->is_multipart, 'no multipart content';
ok !$res->content->parts->[1]->is_multipart, 'no multipart content';
ok !$res->content->parts->[2]->is_multipart, 'no multipart content';
is $res->content->parts->[0]->asset->slurp, "hallo welt test123\n",
'right content';

Expand Down Expand Up @@ -511,13 +511,13 @@ is $res->headers->content_type,
is $res->headers->content_length, 418, 'right "Content-Length" value';
is $res->headers->transfer_encoding, undef, 'no "Transfer-Encoding" value';
is $res->body_size, 418, 'right size';
isa_ok $res->content->parts->[0], 'Mojo::Content::Single', 'right part';
isa_ok $res->content->parts->[1], 'Mojo::Content::Single', 'right part';
isa_ok $res->content->parts->[2], 'Mojo::Content::Single', 'right part';
ok !$res->content->parts->[0]->is_multipart, 'no multipart content';
ok !$res->content->parts->[1]->is_multipart, 'no multipart content';
ok !$res->content->parts->[2]->is_multipart, 'no multipart content';
is $res->content->parts->[0]->asset->slurp, "hallo welt test123\n",
'right content';
is $res->upload('upload')->filename, 'hello.pl', 'right filename';
isa_ok $res->upload('upload')->asset, 'Mojo::Asset::Memory', 'right file';
is $res->upload('upload')->filename, 'hello.pl', 'right filename';
ok !$res->upload('upload')->asset->is_file, 'stored in memory';
is $res->upload('upload')->asset->size, 69, 'right size';
is $res->content->parts->[2]->headers->content_type,
'application/octet-stream', 'right "Content-Type" value';
Expand Down Expand Up @@ -561,8 +561,8 @@ is $res->headers->content_type,
is $res->headers->content_length, 129, 'right "Content-Length" value';
is $res->headers->transfer_encoding, undef, 'no "Transfer-Encoding" value';
is $res->body_size, 129, 'right size';
isa_ok $res->content->parts->[0], 'Mojo::Content::Single', 'right part';
isa_ok $res->content->parts->[1], 'Mojo::Content::Single', 'right part';
ok !$res->content->parts->[0]->is_multipart, 'no multipart content';
ok !$res->content->parts->[1]->is_multipart, 'no multipart content';
is $res->content->parts->[0]->asset->slurp, 'abcd', 'right content';
is $res->content->parts->[0]->headers->content_type, 'image/jpeg',
'right "Content-Type" value';
Expand Down Expand Up @@ -599,7 +599,7 @@ is $res->message, 'OK', 'right message';
is $res->version, '1.1', 'right version';
is $res->headers->content_type, 'multipart/form-data; bo',
'right "Content-Type" value';
isa_ok $res->content, 'Mojo::Content::Single', 'right content';
ok !$res->content->is_multipart, 'no multipart content';
like $res->content->asset->slurp, qr/hallo welt/, 'right content';

# Parse HTTP 1.1 gzip compressed response
Expand Down
4 changes: 2 additions & 2 deletions t/mojolicious/exception_lite_app.t
Expand Up @@ -233,8 +233,8 @@ ok !$exception, 'no exception';
ok !$snapshot, 'no snapshot';
$t->get_ok('/reuse/exception')->status_is(500)
->content_like(qr/Reusable exception/);
isa_ok $exception, 'Mojo::Exception', 'right exception class';
like $exception, qr/Reusable exception/, 'right exception';
isa_ok $exception, 'Mojo::Exception', 'right exception';
like $exception, qr/Reusable exception/, 'right message';
is $snapshot->{foo}, 'bar', 'right snapshot value';
ok !$snapshot->{exception}, 'no exception in snapshot';

Expand Down

0 comments on commit e858821

Please sign in to comment.