Skip to content

Commit

Permalink
deprecated Test::Mojo->json_content_is in favor of Test::Mojo->json_is
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Dec 23, 2011
1 parent 5869d29 commit 432c38a
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 52 deletions.
2 changes: 2 additions & 0 deletions Changes
@@ -1,6 +1,8 @@
This file documents the revision history for Perl extension Mojolicious.

2.40 2011-12-23 00:00:00
- Deprecated Test::Mojo->json_content_is in favor of
Test::Mojo->json_is.
- Added EXPERIMENTAL JSON Pointer support. (crab)
- Improved inactivity timeouts by allowing them to be disabled.
- Fixed repository to not favor specific editors.
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Message.pm
Expand Up @@ -791,8 +791,8 @@ Check if message content is a L<Mojo::Content::MultiPart> object.
Decode JSON message body directly using L<Mojo::JSON> if possible, returns
C<undef> otherwise. An optional JSON Pointer can be used to extract a
specific value. Note that the JSON Pointer argument of this method is
EXPERIMENTAL and might change without warning!
specific value with L<Mojo::JSON::Pointer>. Note that the JSON Pointer
argument of this method is EXPERIMENTAL and might change without warning!
say $message->json->{foo}->{bar}->[23];
say $message->json('/foo/bar/23');
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Command/get.pm
Expand Up @@ -144,7 +144,7 @@ sub run {
$url = encode 'UTF-8', $url;
warn qq/Problem loading URL "$url". ($message)\n/ if $message && !$code;

# JSON
# JSON Pointer
return unless $selector;
return $self->_json($buffer, $selector)
if ($tx->res->headers->content_type || '') =~ /JSON/i;
Expand Down
25 changes: 12 additions & 13 deletions lib/Test/Mojo.pm
Expand Up @@ -163,7 +163,11 @@ sub header_unlike {
return $self;
}

# DEPRECATED in Leaf Fluttering In Wind!
sub json_content_is {
warn <<EOF;
Test::Mojo->json_content_is is DEPRECATED in favor of Test::Mojo->json_is!
EOF
my ($self, $data, $desc) = @_;
local $Test::Builder::Level = $Test::Builder::Level + 1;
Test::More::is_deeply $self->tx->res->json, $data,
Expand Down Expand Up @@ -584,31 +588,26 @@ Check response header for similar match.
Opposite of C<header_like>.
=head2 C<json_content_is>
$t = $t->json_content_is([1, 2, 3]);
$t = $t->json_content_is([1, 2, 3], 'right content');
$t = $t->json_content_is({foo => 'bar', baz => 23}, 'right content');
Check response content for JSON data.
=head2 C<json_is>
$t = $t->json_is('/foo' => {bar => [1, 2, 3]});
$t = $t->json_is('/foo/bar' => [1, 2, 3]);
$t = $t->json_is('/foo/bar/1' => 2, 'right value');
Check the value extracted from JSON response using the given JSON Pointer.
Note that this method is EXPERIMENTAL and might change without warning!
Check the value extracted from JSON response using the given JSON Pointer
with L<Mojo::JSON::Pointer>. Note that this method is EXPERIMENTAL and might
change without warning!
$t->json_is('/' => [1, 2, 3]);
=head2 C<json_has>
$t = $t->json_has('/foo');
$t = $t->json_has('/minibar', 'has a minibar');
Check if JSON response contains a value that can be identified with the given
JSON Pointer. Note that this method is EXPERIMENTAL and might change without
warning!
Check if JSON response contains a value that can be identified using the
given JSON Pointer with L<Mojo::JSON::Pointer>. Note that this method is
EXPERIMENTAL and might change without warning!
=head2 C<json_hasnt>
Expand Down
4 changes: 2 additions & 2 deletions t/mojolicious/app.t
Expand Up @@ -82,13 +82,13 @@ $t->get_ok('/exceptional_too/this_one_dies', {'X-DoNotDie' => 1})
$t->get_ok('/exceptional/this_one_does_not_exist')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->json_content_is({error => 'not found!'});
->json_is('/' => {error => 'not found!'});

# Exceptional::this_one_does_not_exist (action behind bridge does not exist)
$t->get_ok('/exceptional_too/this_one_does_not_exist', {'X-DoNotDie' => 1})
->status_is(200)->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->json_content_is({error => 'not found!'});
->json_is('/' => {error => 'not found!'});

# Foo::fun
$t->get_ok('/fun/time', {'X-Test' => 'Hi there!'})->status_is(200)
Expand Down
4 changes: 2 additions & 2 deletions t/mojolicious/charset_lite_app.t
Expand Up @@ -105,11 +105,11 @@ $t->post_ok('/data', $yatta_sjis)->status_is(200)->content_is($yatta_sjis);

# JSON data
$t->get_ok('/json')->status_is(200)->content_type_is('application/json')
->json_content_is({test => $yatta});
->json_is('/' => {test => $yatta});

# IRI
$t->get_ok('/привет/мир')->status_is(200)
->content_type_is('application/json')->json_content_is({foo => $yatta});
->content_type_is('application/json')->json_is('/' => {foo => $yatta});

__DATA__
@@ index.html.ep
Expand Down
7 changes: 4 additions & 3 deletions t/mojolicious/lite_app.t
Expand Up @@ -9,7 +9,7 @@ BEGIN {
$ENV{MOJO_MODE} = 'development';
}

use Test::More tests => 714;
use Test::More tests => 715;

# "Wait you're the only friend I have...
# You really want a robot for a friend?
Expand Down Expand Up @@ -735,7 +735,7 @@ $t->get_ok('/without-format')->content_is("/without-format\n");
$t->get_ok('/without-format.html')->content_is("/without-format\n");

# GET /json_too
$t->get_ok('/json_too')->status_is(200)->json_content_is({hello => 'world'});
$t->get_ok('/json_too')->status_is(200)->json_is('/' => {hello => 'world'});

# GET /static.txt (static inline file)
$t->get_ok('/static.txt')->status_is(200)
Expand Down Expand Up @@ -1169,7 +1169,8 @@ is $tx->res->body, '%E1', 'right content';
$t->get_ok('/json')->status_is(200)->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->content_type_is('application/json')
->json_content_is({foo => [1, -2, 3, 'b☃r']})->json_is('/foo/3', 'b☃r')
->json_is('/' => {foo => [1, -2, 3, 'b☃r']})
->json_is('/foo', [1, -2, 3, 'b☃r'])->json_is('/foo/3', 'b☃r')
->json_has('/foo')->json_hasnt('/bar');

# GET /autostash
Expand Down
4 changes: 2 additions & 2 deletions t/mojolicious/production_app.t
Expand Up @@ -53,13 +53,13 @@ $t->get_ok('/exceptional_too/this_one_dies', {'X-DoNotDie' => 1})
$t->get_ok('/exceptional/this_one_does_not_exist')->status_is(200)
->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->json_content_is({error => 'not found!'});
->json_is('/' => {error => 'not found!'});

# Exceptional::this_one_does_not_exist (action behind bridge does not exist)
$t->get_ok('/exceptional_too/this_one_does_not_exist', {'X-DoNotDie' => 1})
->status_is(200)->header_is(Server => 'Mojolicious (Perl)')
->header_is('X-Powered-By' => 'Mojolicious (Perl)')
->json_content_is({error => 'not found!'});
->json_is('/' => {error => 'not found!'});

# Static file /hello.txt in production mode
$t->get_ok('/hello.txt')->status_is(200)
Expand Down
48 changes: 24 additions & 24 deletions t/mojolicious/restful_lite_app.t
Expand Up @@ -96,45 +96,45 @@ $t->get_ok('/rest.html?format=html', {Accept => 'text/html'})->status_is(200)

# GET /rest.json (json format)
$t->get_ok('/rest.json')->status_is(200)->content_type_is('application/json')
->json_content_is({just => 'works'});
->json_is('/' => {just => 'works'});

# GET /rest (accept json)
$t->get_ok('/rest', {Accept => 'application/json'})->status_is(200)
->content_type_is('application/json')->json_content_is({just => 'works'});
->content_type_is('application/json')->json_is('/' => {just => 'works'});

# GET /rest (accept json again)
$t->get_ok('/rest', {Accept => 'APPLICATION/JSON'})->status_is(200)
->content_type_is('application/json')->json_content_is({just => 'works'});
->content_type_is('application/json')->json_is('/' => {just => 'works'});

# GET /rest.json (accept json with format)
$t->get_ok('/rest.json', {Accept => 'application/json'})->status_is(200)
->content_type_is('application/json')->json_content_is({just => 'works'});
->content_type_is('application/json')->json_is('/' => {just => 'works'});

# GET /rest.png (accept json with wrong format)
$t->get_ok('/rest.png', {Accept => 'application/json'})->status_is(200)
->content_type_is('application/json')->json_content_is({just => 'works'});
->content_type_is('application/json')->json_is('/' => {just => 'works'});

# GET /rest (accept json with quality)
$t->get_ok('/rest', {Accept => 'application/json;q=9'})->status_is(200)
->content_type_is('application/json')->json_content_is({just => 'works'});
->content_type_is('application/json')->json_is('/' => {just => 'works'});

# GET /rest (json query)
$t->get_ok('/rest?format=json')->status_is(200)
->content_type_is('application/json')->json_content_is({just => 'works'});
->content_type_is('application/json')->json_is('/' => {just => 'works'});

# GET /rest (json format with query)
$t->get_ok('/rest.json?format=json')->status_is(200)
->content_type_is('application/json')->json_content_is({just => 'works'});
->content_type_is('application/json')->json_is('/' => {just => 'works'});

# GET /rest (accept json with query)
$t->get_ok('/rest?format=json', {Accept => 'application/json'})
->status_is(200)->content_type_is('application/json')
->json_content_is({just => 'works'});
->json_is('/' => {just => 'works'});

# GET /rest (accept json with everything)
$t->get_ok('/rest.json?format=json', {Accept => 'application/json'})
->status_is(200)->content_type_is('application/json')
->json_content_is({just => 'works'});
->json_is('/' => {just => 'works'});

# GET /rest.xml (xml format)
$t->get_ok('/rest.xml')->status_is(200)->content_type_is('text/xml')
Expand Down Expand Up @@ -257,74 +257,74 @@ $t->post_form_ok(

# POST /rest.json (json format)
$t->post_ok('/rest.json')->status_is(200)->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest (accept json)
$t->post_ok('/rest', {Accept => 'application/json'})->status_is(200)
->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest (accept json again)
$t->post_ok('/rest', {Accept => 'APPLICATION/JSON'})->status_is(200)
->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest.json (accept json with format)
$t->post_ok('/rest.json', {Accept => 'application/json'})->status_is(200)
->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest.png (accept json with wrong format)
$t->post_ok('/rest.png', {Accept => 'application/json'})->status_is(200)
->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest (accept json with quality)
$t->post_ok('/rest', {Accept => 'application/json;q=9'})->status_is(200)
->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest (json query)
$t->post_ok('/rest?format=json')->status_is(200)
->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest (json format with query)
$t->post_ok('/rest.json?format=json')->status_is(200)
->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest (accept json with query)
$t->post_ok('/rest?format=json', {Accept => 'application/json'})
->status_is(200)->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest (accept json with everything)
$t->post_ok('/rest.json?format=json', {Accept => 'application/json'})
->status_is(200)->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest (json form)
$t->post_form_ok('/rest' => {format => 'json'})->status_is(200)
->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest (json format with form)
$t->post_form_ok('/rest.json' => {format => 'json'})->status_is(200)
->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest (accept json with form)
$t->post_form_ok(
'/rest' => {format => 'json'} => {Accept => 'application/json'})
->status_is(200)->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest (accept json with everything, form alternative)
$t->post_form_ok(
'/rest.json' => {format => 'json'} => {Accept => 'application/json'})
->status_is(200)->content_type_is('application/json')
->json_content_is({just => 'works too'});
->json_is('/' => {just => 'works too'});

# POST /rest.xml (xml format)
$t->post_ok('/rest.xml')->status_is(200)->content_type_is('text/xml')
Expand Down
6 changes: 3 additions & 3 deletions t/pod_coverage.t
Expand Up @@ -12,9 +12,9 @@ my @sunglasses = (qw/on_progress on_read on_request on_resume on_start/);

# DEPRECATED in Leaf Fluttering In Wind!
my @leaf = (
qw/add_hook connect connection_timeout is_done keep_alive_timeout listen/,
qw/on_close on_error on_finish on_lock on_process on_read on_unlock/,
qw/run_hook run_hook_reverse timeout write/
qw/add_hook connect connection_timeout is_done json_content_is/,
qw/keep_alive_timeout listen on_close on_error on_finish on_lock/,
qw/on_process on_read on_unlock run_hook run_hook_reverse timeout write/
);

# "Marge, I'm going to miss you so much. And it's not just the sex.
Expand Down

0 comments on commit 432c38a

Please sign in to comment.