Skip to content

Commit

Permalink
More tests for Collector
Browse files Browse the repository at this point in the history
Checks now if the keywords are properly matched
  • Loading branch information
miquelruiz committed Dec 27, 2011
1 parent f4b8772 commit 12489a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions lib/App/cart/Collector.pm
Expand Up @@ -37,7 +37,7 @@ sub new {
},
on_tweet => sub {
$self->on_tweet(shift);
$test_tweet_cv->send if defined $test_tweet_cv;
$test_tweet_cv->end if defined $test_tweet_cv;
},
on_error => sub {
$log->critical("Got error: " . join("|", @_));
Expand Down Expand Up @@ -112,7 +112,7 @@ sub is_valid {

my @kw = @{ $self->{keywords} };
foreach (@kw) {
if ($tweet->{text} =~ /$_/) {
if ($tweet->{text} =~ /(?:\s|^)$_(?:\s|$)/) {
$log->debug("Got a match with $_");
return 1;
}
Expand Down
14 changes: 10 additions & 4 deletions t/02-collector.t
Expand Up @@ -24,6 +24,7 @@ SKIP: {

write_config();
my $conf = read_config();
$conf->{keywords} = [ '#keyword' ];

# instantiate a collector
my ($conn, $got_tweet) = (AnyEvent->condvar, AnyEvent->condvar);
Expand All @@ -37,15 +38,20 @@ SKIP: {
traits => [qw/OAuth API::REST/],
%{ $conf->{oauth} },
);
my $text = time . ' ' . rand(1000);
$nt->update($text);

# Wait a little for it
my $text;
for ('#nokeyword', '#keywordcontained', '#keyword') {
$got_tweet->begin;
$text = time . ' ' . rand(1000) . ' ' . $_;
$nt->update($text);
}

# Wait for the tweets
$got_tweet->recv;

# instantiate a buffer so we can check if the collector catched it
my $buffer = App::cart::Buffer->new($conf);
is($buffer->count, 1, "There's a tweet");
is($buffer->count, 1, "There's only one tweet");
is($buffer->bshift->{data}, $text, "It is ours");

cleanup_config();
Expand Down

0 comments on commit 12489a3

Please sign in to comment.