From c1c31063c01e0ff559a2283cf1e3a8eee5ebd330 Mon Sep 17 00:00:00 2001 From: Erik Michaels-Ober Date: Wed, 18 Dec 2013 08:32:40 -0500 Subject: [PATCH] Add spec coverage for Twitter::Streaming::Client#site with a user object passed --- lib/twitter/streaming/client.rb | 2 - spec/helper.rb | 2 +- spec/twitter/streaming/client_spec.rb | 143 +++++++++++++++----------- 3 files changed, 86 insertions(+), 61 deletions(-) diff --git a/lib/twitter/streaming/client.rb b/lib/twitter/streaming/client.rb index 6225d27da..bd5f1c79f 100644 --- a/lib/twitter/streaming/client.rb +++ b/lib/twitter/streaming/client.rb @@ -129,8 +129,6 @@ def collect_user_ids(users) case user when Integer user_ids << user - when String - user_ids << user.to_i when Twitter::User user_ids << user.id end diff --git a/spec/helper.rb b/spec/helper.rb index 8e90232ba..8f576b559 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -8,7 +8,7 @@ SimpleCov.start do add_filter '/spec/' - minimum_coverage(99.24) + minimum_coverage(99.35) end require 'twitter' diff --git a/spec/twitter/streaming/client_spec.rb b/spec/twitter/streaming/client_spec.rb index ac6005821..6e9475fe9 100644 --- a/spec/twitter/streaming/client_spec.rb +++ b/spec/twitter/streaming/client_spec.rb @@ -17,80 +17,107 @@ def stream(request, response) end end - it '#before_request' do - @client.connection = FakeConnection.new(fixture('track_streaming.json')) - var = false - @client.before_request do - var = true + describe '#before_request' do + it 'runs before a request' do + @client.connection = FakeConnection.new(fixture('track_streaming.json')) + var = false + @client.before_request do + var = true + end + expect(var).to be false + @client.user {} + expect(var).to be true end - expect(var).to be false - @client.user {} - expect(var).to be true end - it '#filter' do - @client.connection = FakeConnection.new(fixture('track_streaming.json')) - objects = [] - @client.filter(:track => 'india') do |object| - objects << object + describe '#filter' do + it 'returns an arary of Tweets' do + @client.connection = FakeConnection.new(fixture('track_streaming.json')) + objects = [] + @client.filter(:track => 'india') do |object| + objects << object + end + expect(objects.size).to eq(2) + expect(objects.first).to be_a Twitter::Tweet + expect(objects.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do." end - expect(objects.size).to eq(2) - expect(objects.first).to be_a Twitter::Tweet - expect(objects.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do." end - it '#firehose' do - @client.connection = FakeConnection.new(fixture('track_streaming.json')) - objects = [] - @client.firehose do |object| - objects << object + describe '#firehose' do + it 'returns an arary of Tweets' do + @client.connection = FakeConnection.new(fixture('track_streaming.json')) + objects = [] + @client.firehose do |object| + objects << object + end + expect(objects.size).to eq(2) + expect(objects.first).to be_a Twitter::Tweet + expect(objects.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do." end - expect(objects.size).to eq(2) - expect(objects.first).to be_a Twitter::Tweet - expect(objects.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do." end - it '#sample' do - @client.connection = FakeConnection.new(fixture('track_streaming.json')) - objects = [] - @client.sample do |object| - objects << object + describe '#sample' do + it 'returns an arary of Tweets' do + @client.connection = FakeConnection.new(fixture('track_streaming.json')) + objects = [] + @client.sample do |object| + objects << object + end + expect(objects.size).to eq(2) + expect(objects.first).to be_a Twitter::Tweet + expect(objects.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do." end - expect(objects.size).to eq(2) - expect(objects.first).to be_a Twitter::Tweet - expect(objects.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do." end - it '#site' do - @client.connection = FakeConnection.new(fixture('track_streaming.json')) - objects = [] - @client.site(7_505_382) do |object| - objects << object + describe '#site' do + context 'with a user ID passed' do + it 'returns an arary of Tweets' do + @client.connection = FakeConnection.new(fixture('track_streaming.json')) + objects = [] + @client.site(7_505_382) do |object| + objects << object + end + expect(objects.size).to eq(2) + expect(objects.first).to be_a Twitter::Tweet + expect(objects.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do." + end + end + context 'with a user object passed' do + it 'returns an arary of Tweets' do + @client.connection = FakeConnection.new(fixture('track_streaming.json')) + objects = [] + user = Twitter::User.new(:id => 7_505_382) + @client.site(user) do |object| + objects << object + end + expect(objects.size).to eq(2) + expect(objects.first).to be_a Twitter::Tweet + expect(objects.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do." + end end - expect(objects.size).to eq(2) - expect(objects.first).to be_a Twitter::Tweet - expect(objects.first.text).to eq "The problem with your code is that it's doing exactly what you told it to do." end - it '#user' do - @client.connection = FakeConnection.new(fixture('track_streaming_user.json')) - objects = [] - @client.user do |object| - objects << object + describe '#user' do + it 'returns an arary of Tweets' do + @client.connection = FakeConnection.new(fixture('track_streaming_user.json')) + objects = [] + @client.user do |object| + objects << object + end + expect(objects.size).to eq(6) + expect(objects[0]).to be_a Twitter::Streaming::FriendList + expect(objects[0]).to eq([488_736_931, 311_444_249]) + expect(objects[1]).to be_a Twitter::Tweet + expect(objects[1].text).to eq("The problem with your code is that it's doing exactly what you told it to do.") + expect(objects[2]).to be_a Twitter::DirectMessage + expect(objects[2].text).to eq('hello bot') + expect(objects[3]).to be_a Twitter::Streaming::Event + expect(objects[3].name).to eq(:follow) + expect(objects[4]).to be_a Twitter::Streaming::DeletedTweet + expect(objects[4].id).to eq(272_691_609_211_117_568) + expect(objects[5]).to be_a Twitter::Streaming::StallWarning + expect(objects[5].code).to eq('FALLING_BEHIND') end - expect(objects.size).to eq(6) - expect(objects[0]).to be_a Twitter::Streaming::FriendList - expect(objects[0]).to eq([488_736_931, 311_444_249]) - expect(objects[1]).to be_a Twitter::Tweet - expect(objects[1].text).to eq("The problem with your code is that it's doing exactly what you told it to do.") - expect(objects[2]).to be_a Twitter::DirectMessage - expect(objects[2].text).to eq('hello bot') - expect(objects[3]).to be_a Twitter::Streaming::Event - expect(objects[3].name).to eq(:follow) - expect(objects[4]).to be_a Twitter::Streaming::DeletedTweet - expect(objects[4].id).to eq(272_691_609_211_117_568) - expect(objects[5]).to be_a Twitter::Streaming::StallWarning - expect(objects[5].code).to eq('FALLING_BEHIND') end end