Skip to content
Browse files

More tests for Collector

Checks now if the keywords are properly matched
  • Loading branch information...
1 parent f4b8772 commit 12489a3080608bfa1ee84dc3bffdb1cea8495d50 @miquelruiz committed
Showing with 12 additions and 6 deletions.
  1. +2 −2 lib/App/cart/Collector.pm
  2. +10 −4 t/02-collector.t
View
4 lib/App/cart/Collector.pm
@@ -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("|", @_));
@@ -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;
}
View
14 t/02-collector.t
@@ -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);
@@ -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();

0 comments on commit 12489a3

Please sign in to comment.
Something went wrong with that request. Please try again.