Skip to content

Instantly share code, notes, and snippets.

@kraih
Last active September 27, 2015 06:39
Show Gist options
  • Save kraih/1227900 to your computer and use it in GitHub Desktop.
Save kraih/1227900 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use Mojo::Base -strict;
use utf8;
use Test::More tests => 4;
use Mojolicious::Lite;
use Test::Mojo;
# Tiny echo web service
websocket '/echo' => sub {
my $self = shift;
$self->on(message => sub {
my ($self, $message) = @_;
$self->send("echo: $message");
});
};
# Send message and receive echo
my $t = Test::Mojo->new;
$t->websocket_ok('/echo')
->send_ok('I ♥ Mojolicious')
->message_ok
->message_is('echo: I ♥ Mojolicious')
->finish_ok;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment