|
@@ -221,20 +221,20 @@ describe Agents::TwitterStreamAgent do
|
|
context "callback handling" do
|
|
context "callback handling" do
|
|
it "logs error messages" do
|
|
it "logs error messages" do
|
|
stub_without(:on_error).on_error.yields('woups')
|
|
stub_without(:on_error).on_error.yields('woups')
|
|
- mock(STDERR).puts(" --> Twitter error: woups <--")
|
|
|
|
|
|
+ mock(STDERR).puts(anything) { |text| expect(text).to match(/woups/) }
|
|
@worker.send(:stream!, ['agent'], @agent)
|
|
@worker.send(:stream!, ['agent'], @agent)
|
|
end
|
|
end
|
|
|
|
|
|
it "stop when no data was received"do
|
|
it "stop when no data was received"do
|
|
stub_without(:on_no_data).on_no_data.yields
|
|
stub_without(:on_no_data).on_no_data.yields
|
|
mock(@worker).restart!
|
|
mock(@worker).restart!
|
|
- mock(STDERR).puts(" --> Got no data for awhile; trying to reconnect.")
|
|
|
|
|
|
+ mock(STDERR).puts(anything)
|
|
@worker.send(:stream!, ['agent'], @agent)
|
|
@worker.send(:stream!, ['agent'], @agent)
|
|
end
|
|
end
|
|
|
|
|
|
it "sleeps for 60 seconds on_max_reconnects" do
|
|
it "sleeps for 60 seconds on_max_reconnects" do
|
|
stub_without(:on_max_reconnects).on_max_reconnects.yields
|
|
stub_without(:on_max_reconnects).on_max_reconnects.yields
|
|
- mock(STDERR).puts(" --> Oops, tried too many times! <--")
|
|
|
|
|
|
+ mock(STDERR).puts(anything)
|
|
mock(@worker).sleep(60)
|
|
mock(@worker).sleep(60)
|
|
mock(@worker).restart!
|
|
mock(@worker).restart!
|
|
@worker.send(:stream!, ['agent'], @agent)
|
|
@worker.send(:stream!, ['agent'], @agent)
|
|
@@ -251,22 +251,21 @@ describe Agents::TwitterStreamAgent do
|
|
|
|
|
|
context "#handle_status" do
|
|
context "#handle_status" do
|
|
it "skips retweets" do
|
|
it "skips retweets" do
|
|
- mock.instance_of(IO).puts('Skipping retweet: retweet')
|
|
|
|
- @worker.send(:handle_status, {'text' => 'retweet', 'retweeted_status' => {one: true}})
|
|
|
|
|
|
+ @worker.send(:handle_status, {'text' => 'retweet', 'retweeted_status' => {one: true}, 'id_str' => '123' })
|
|
|
|
+ expect(@worker.instance_variable_get(:'@recent_tweets')).not_to include('123')
|
|
end
|
|
end
|
|
|
|
|
|
it "deduplicates tweets" do
|
|
it "deduplicates tweets" do
|
|
- mock.instance_of(IO).puts("dup")
|
|
|
|
- @worker.send(:handle_status, {'text' => 'dup', 'id_str' => 1})
|
|
|
|
- mock.instance_of(IO).puts("Skipping duplicate tweet: dup")
|
|
|
|
- @worker.send(:handle_status, {'text' => 'dup', 'id_str' => 1})
|
|
|
|
|
|
+ @worker.send(:handle_status, {'text' => 'dup', 'id_str' => '1'})
|
|
|
|
+ @worker.send(:handle_status, {'text' => 'dup', 'id_str' => '1'})
|
|
|
|
+ expect(@worker.instance_variable_get(:'@recent_tweets').select { |str| str == '1' }.length).to eq 1
|
|
end
|
|
end
|
|
|
|
|
|
it "calls the agent to process the tweet" do
|
|
it "calls the agent to process the tweet" do
|
|
- stub.instance_of(IO).puts
|
|
|
|
mock(@mock_agent).name { 'mock' }
|
|
mock(@mock_agent).name { 'mock' }
|
|
mock(@mock_agent).process_tweet('agent', {'text' => 'agent'})
|
|
mock(@mock_agent).process_tweet('agent', {'text' => 'agent'})
|
|
- @worker.send(:handle_status, {'text' => 'agent'})
|
|
|
|
|
|
+ @worker.send(:handle_status, {'text' => 'agent', 'id_str' => '123'})
|
|
|
|
+ expect(@worker.instance_variable_get(:'@recent_tweets')).to include('123')
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|