Permalink
Browse files

tidied

  • Loading branch information...
1 parent f839fb1 commit 9ef6af266bf2a2d7be51479169263473188238bb @aanoaa committed Nov 15, 2012
Showing with 100 additions and 85 deletions.
  1. +3 −4 lib/Hubot/Scripts/shorten.pm
  2. +9 −7 t/01_help.t
  3. +9 −7 t/02_ascii.t
  4. +21 −18 t/03_roles.t
  5. +19 −14 t/04_shorten.t
  6. +12 −9 t/05_tweet.t
  7. +27 −26 t/lib/Hubot/Adapter/Helper.pm
@@ -15,11 +15,10 @@ sub load {
sub {
my $msg = shift;
my $bitly = $msg->match->[0];
- if (
- length $bitly > 50
+ if ( length $bitly > 50
&& $ENV{HUBOT_BITLY_USERNAME}
- && $ENV{HUBOT_BITLY_API_KEY}
- ) {
+ && $ENV{HUBOT_BITLY_API_KEY} )
+ {
my $uri = URI->new("http://api.bitly.com/v3/shorten");
$uri->query_form_hash(
login => $ENV{HUBOT_BITLY_USERNAME},
View
@@ -4,12 +4,14 @@ use Hubot::Robot;
use lib 't/lib';
use Test::More tests => 2;
-my $robot = Hubot::Robot->new({
- adapter => 'helper',
- name => 'hubot'
-});
+my $robot = Hubot::Robot->new(
+ {
+ adapter => 'helper',
+ name => 'hubot'
+ }
+);
-$robot->loadHubotScripts(["help","roles"]);
+$robot->loadHubotScripts( [ "help", "roles" ] );
push @{ $robot->{receive} }, 'hubot help';
push @{ $robot->{receive} }, 'hubot help roles';
@@ -18,6 +20,6 @@ $robot->run;
my $got;
$got = shift @{ $robot->{sent} };
-like("@$got", qr/help <query>/, 'generall help');
+like( "@$got", qr/help <query>/, 'generall help' );
$got = shift @{ $robot->{sent} };
-like("@$got", qr/see what roles a user has/, 'specific help');
+like( "@$got", qr/see what roles a user has/, 'specific help' );
View
@@ -4,12 +4,14 @@ use Hubot::Robot;
use lib 't/lib';
use Test::More tests => 2;
-my $robot = Hubot::Robot->new({
- adapter => 'helper',
- name => 'hubot'
-});
+my $robot = Hubot::Robot->new(
+ {
+ adapter => 'helper',
+ name => 'hubot'
+ }
+);
-$robot->loadHubotScripts(["help","ascii"]);
+$robot->loadHubotScripts( [ "help", "ascii" ] );
$robot->adapter->interval(3);
push @{ $robot->{receive} }, 'hubot help ascii';
@@ -19,6 +21,6 @@ $robot->run;
my $got;
$got = shift @{ $robot->{sent} };
-like("@$got", qr/ascii me/, 'correct help message');
+like( "@$got", qr/ascii me/, 'correct help message' );
$got = shift @{ $robot->{sent} };
-like("@$got", qr/\| \|/, 'ascii art');
+like( "@$got", qr/\| \|/, 'ascii art' );
View
@@ -5,53 +5,56 @@ use Hubot::User;
use lib 't/lib';
use Test::More tests => 9;
-my $robot = Hubot::Robot->new({
- adapter => 'helper',
- name => 'hubot'
-});
+my $robot = Hubot::Robot->new(
+ {
+ adapter => 'helper',
+ name => 'hubot'
+ }
+);
-$robot->loadHubotScripts(["help","roles"]);
+$robot->loadHubotScripts( [ "help", "roles" ] );
$robot->adapter->interval(0.2);
-$robot->userForId('misskim', {}); # for known user test
+$robot->userForId( 'misskim', {} ); # for known user test
-push @{ $robot->{receive} }, (
+push @{ $robot->{receive} },
+ (
'hubot help user',
'hubot who is ' . time,
'hubot ' . time . ' is a dayfly',
- 'hubot who is misskim' ,
+ 'hubot who is misskim',
'hubot misskim is a dayfly',
'hubot who is misskim',
'hubot misskim is not a dayfly',
'hubot who is misskim',
'hubot who is ' . $robot->name,
-);
+ );
$robot->run;
my $got;
$got = shift @{ $robot->{sent} };
-like("@$got", qr/badass guitarist/, '<robot> help roles');
+like( "@$got", qr/badass guitarist/, '<robot> help roles' );
$got = shift @{ $robot->{sent} };
-like("@$got", qr/Never heard/, 'who is <unknown>');
+like( "@$got", qr/Never heard/, 'who is <unknown>' );
$got = shift @{ $robot->{sent} };
-like("@$got", qr/anything about/, 'assign a role to <unknown>');
+like( "@$got", qr/anything about/, 'assign a role to <unknown>' );
$got = shift @{ $robot->{sent} };
-like("@$got", qr/nothing to me/, 'who is <known>');
+like( "@$got", qr/nothing to me/, 'who is <known>' );
$got = shift @{ $robot->{sent} };
-like("@$got", qr/is a dayfly/, 'give a role');
+like( "@$got", qr/is a dayfly/, 'give a role' );
$got = shift @{ $robot->{sent} };
-like("@$got", qr/is a dayfly/, 'got correct role');
+like( "@$got", qr/is a dayfly/, 'got correct role' );
$got = shift @{ $robot->{sent} };
-like("@$got", qr/is no longer a dayfly/, 'drop a role');
+like( "@$got", qr/is no longer a dayfly/, 'drop a role' );
$got = shift @{ $robot->{sent} };
-like("@$got", qr/nothing to me/, 'who is <known> again after drop roles');
+like( "@$got", qr/nothing to me/, 'who is <known> again after drop roles' );
$got = shift @{ $robot->{sent} };
-like("@$got", qr/The best/, 'who is hubot');
+like( "@$got", qr/The best/, 'who is hubot' );
View
@@ -4,34 +4,39 @@ use Hubot::Robot;
use lib 't/lib';
use Test::More tests => 6;
-my $robot = Hubot::Robot->new({
- adapter => 'helper',
- name => 'hubot'
-});
+my $robot = Hubot::Robot->new(
+ {
+ adapter => 'helper',
+ name => 'hubot'
+ }
+);
-$robot->loadHubotScripts(["help","shorten"]);
+$robot->loadHubotScripts( [ "help", "shorten" ] );
$robot->adapter->interval(3);
-push @{ $robot->{receive} }, (
+push @{ $robot->{receive} },
+ (
'hubot help shorten',
'https://www.google.com/',
'https://github.com/aanoaa/p5-hubot/blob/master/lib/Hubot/Scripts/shorten.pm',
-);
+ );
$robot->run;
my $got;
$got = shift @{ $robot->{sent} };
-ok("@$got", 'containing help messages');
+ok( "@$got", 'containing help messages' );
SKIP: {
- skip "ENV [HUBOT_BITLY_USERNAME] and [HUBOT_BITLY_API_KEY] are required", 5 if !$ENV{HUBOT_BITLY_USERNAME} or !$ENV{HUBOT_BITLY_API_KEY};
+ skip "ENV [HUBOT_BITLY_USERNAME] and [HUBOT_BITLY_API_KEY] are required", 5
+ if !$ENV{HUBOT_BITLY_USERNAME}
+ or !$ENV{HUBOT_BITLY_API_KEY};
$got = shift @{ $robot->{sent} } || [];
- ok("@$got", "got response on https");
- like("@$got", qr/google/i, 'pick a title from google');
- like("@$got", qr/google\.com/, 'has link');
+ ok( "@$got", "got response on https" );
+ like( "@$got", qr/google/i, 'pick a title from google' );
+ like( "@$got", qr/google\.com/, 'has link' );
$got = shift @{ $robot->{sent} } || [];
- like("@$got", qr/github/i, 'pick a title from github');
- like("@$got", qr/bit\.ly/, 'got shorten link');
+ like( "@$got", qr/github/i, 'pick a title from github' );
+ like( "@$got", qr/bit\.ly/, 'got shorten link' );
}
View
@@ -4,24 +4,27 @@ use Hubot::Robot;
use lib 't/lib';
use Test::More tests => 2;
-my $robot = Hubot::Robot->new({
- adapter => 'helper',
- name => 'hubot'
-});
+my $robot = Hubot::Robot->new(
+ {
+ adapter => 'helper',
+ name => 'hubot'
+ }
+);
-$robot->loadHubotScripts(["help","tweet"]);
+$robot->loadHubotScripts( [ "help", "tweet" ] );
$robot->adapter->interval(3);
-push @{ $robot->{receive} }, (
+push @{ $robot->{receive} },
+ (
'hubot help tweet',
'https://twitter.com/saltfactory/status/263821902001369088',
-);
+ );
$robot->run;
my $got;
$got = shift @{ $robot->{sent} };
-ok("@$got", 'containing help messages');
+ok( "@$got", 'containing help messages' );
$got = shift @{ $robot->{sent} };
-like("@$got", qr/Ruby/, 'has tweet content');
+like( "@$got", qr/Ruby/, 'has tweet content' );
@@ -19,18 +19,19 @@ has 'cv' => (
);
has 'interval' => (
- is => 'rw',
+ is => 'rw',
default => 1,
);
sub BUILD {
my $self = shift;
- $self->robot->{sent} = [];
+ $self->robot->{sent} = [];
$self->robot->{receive} = [];
}
sub _build_cv { AnyEvent->condvar }
-sub close { shift->cv->send }
+sub close { shift->cv->send }
+
sub send {
my ( $self, $user, @strings ) = @_;
push @{ $self->robot->{sent} }, \@strings;
@@ -48,35 +49,35 @@ sub run {
local $| = 1;
my $w = AnyEvent->timer(
- after => 0,
+ after => 0,
interval => $self->interval,
- cb =>
- sub {
- my $text = shift @{ $self->robot->{receive} };
- return $self->cv->end unless $text;
-
- $self->cv->begin;
- my $user = $self->userForId(
- 1,
+ cb => sub {
+ my $text = shift @{ $self->robot->{receive} };
+ return $self->cv->end unless $text;
+
+ $self->cv->begin;
+ my $user = $self->userForId(
+ 1,
+ {
+ name => 'helper',
+ room => 'helper'
+ }
+ );
+
+ $self->receive(
+ new Hubot::TextMessage(
{
- name => 'helper',
- room => 'helper'
+ user => $user,
+ text => $text,
}
- );
-
- $self->receive(
- new Hubot::TextMessage(
- {
- user => $user,
- text => $text,
- }
- )
- );
- }
- );
+ )
+ );
+ }
+ );
$self->cv->begin;
$self->cv->recv;
+
# callback?
}

0 comments on commit 9ef6af2

Please sign in to comment.