Skip to content

Commit

Permalink
replace json_message_content_is with json_message_is
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 11, 2013
1 parent ae7e983 commit 07e197e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Changes
Expand Up @@ -2,7 +2,7 @@
3.77 2013-01-12
- Added support for advanced binary WebSocket message tests to Test::Mojo.
- Added binary and text events to Mojo::Transaction::WebSocket.
- Added json_message_content_is method to Test::Mojo.
- Added json_message_is method to Test::Mojo.
- Added j function to Mojo::JSON.
- Improved documentation.
- Improved tests.
Expand Down
21 changes: 12 additions & 9 deletions lib/Test/Mojo.pm
Expand Up @@ -10,6 +10,7 @@ use Mojo::Base -base;
# Fry: Santa Claus is gunning you down!"
use Mojo::IOLoop;
use Mojo::JSON;
use Mojo::JSON::Pointer;
use Mojo::Server;
use Mojo::UserAgent;
use Mojo::Util qw(decode encode);
Expand Down Expand Up @@ -163,10 +164,11 @@ sub json_is {
return $self->_test('is_deeply', $self->tx->res->json($p), $data, $desc);
}

sub json_message_content_is {
my ($self, $data, $desc) = @_;
my $structure = Mojo::JSON->new->decode(@{$self->_next || []}[1]);
return $self->_test('is_deeply', $structure, $data,
sub json_message_is {
my ($self, $p, $data, $desc) = @_;
my $value = Mojo::JSON::Pointer->new->get(
Mojo::JSON->new->decode(@{$self->_next || []}[1]), $p);
return $self->_test('is_deeply', $value, $data,
$desc || 'exact match for JSON structure');
}

Expand Down Expand Up @@ -622,13 +624,14 @@ Opposite of C<json_has>.
Check the value extracted from JSON response using the given JSON Pointer with
L<Mojo::JSON::Pointer>.
=head2 json_message_content_is
=head2 json_message_is
$t = $t->json_message_content_is([1, 2, 3]);
$t = $t->json_message_content_is([1, 2, 3], 'right content');
$t = $t->json_message_content_is({foo => 'bar', baz => 23}, 'right content');
$t = $t->json_message_is('/foo' => {bar => [1, 2, 3]});
$t = $t->json_message_is('/foo/bar' => [1, 2, 3]);
$t = $t->json_message_is('/foo/bar/1' => 2, 'right value');
Check WebSocket message content for JSON data.
Check the value extracted from JSON WebSocket message using the given JSON
Pointer with L<Mojo::JSON::Pointer>.
=head2 message_is
Expand Down
5 changes: 3 additions & 2 deletions t/mojolicious/websocket_lite_app.t
Expand Up @@ -143,9 +143,10 @@ $t->get_ok('/echo')->status_is(200)->content_is('plain echo!');
# WebSocket /json
$t->websocket_ok('/json')
->send_ok({text => j({test => 23, snowman => ''})})
->json_message_content_is({test => 24, snowman => ''})
->json_message_is('/' => {test => 24, snowman => ''})
->send_ok({binary => j([1, 2, 3])})
->json_message_content_is([1, 2, 3, 4], 'right content')->finish_ok;
->json_message_is('/' => [1, 2, 3, 4], 'right content')
->send_ok({binary => j([1, 2, 3])})->json_message_is('/2' => 3)->finish_ok;

# GET /plain
$t->get_ok('/plain')->status_is(200)->content_is('Nothing to see here!');
Expand Down

0 comments on commit 07e197e

Please sign in to comment.