Skip to content

Commit

Permalink
Add spec coverage for Twitter::Streaming::Client#site with a user obj…
Browse files Browse the repository at this point in the history
…ect passed
  • Loading branch information
sferik committed Dec 18, 2013
1 parent 715b979 commit c1c3106
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 61 deletions.
2 changes: 0 additions & 2 deletions lib/twitter/streaming/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

SimpleCov.start do
add_filter '/spec/'
minimum_coverage(99.24)
minimum_coverage(99.35)
end

require 'twitter'
Expand Down
143 changes: 85 additions & 58 deletions spec/twitter/streaming/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c1c3106

Please sign in to comment.