diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 724c9a7b..023c6676 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -62,6 +62,7 @@ expect(a_post('/oauth/access_token')).to have_been_made expect(a_get('/1.1/account/verify_credentials.json').with(query: {skip_status: 'true'})).to have_been_made end + it 'does not raise error' do expect do expect(Readline).to receive(:readline).with('Press [Enter] to open the Twitter Developer site. ', true).and_return("\n") @@ -72,6 +73,7 @@ @cli.authorize end.not_to raise_error end + context 'empty RC file' do before do file_path = "#{project_path}/tmp/empty" @@ -94,6 +96,7 @@ expect(a_post('/oauth/access_token')).to have_been_made expect(a_get('/1.1/account/verify_credentials.json').with(query: {skip_status: 'true'})).to have_been_made end + it 'does not raise error' do expect do expect(Readline).to receive(:readline).with('Press [Enter] to open the Twitter Developer site. ', true).and_return("\n") @@ -117,10 +120,12 @@ @cli.block('sferik') expect(a_post('/1.1/blocks/create.json').with(body: {screen_name: 'sferik'})).to have_been_made end + it 'has the correct output' do @cli.block('sferik') expect($stdout.string).to match(/^@testcli blocked 1 user/) end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -149,6 +154,7 @@ expect(a_get('/1.1/account/verify_credentials.json').with(query: {skip_status: 'true'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '358486183,311650899,422190131,759849327200047104,73660881,328677087,4374876088,2924245126'})).to have_been_made end + it 'has the correct output' do @cli.direct_messages expect($stdout.string).to eq <<-EOS @@ -194,6 +200,7 @@ EOS end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -336,6 +343,7 @@ @cli.direct_messages_sent expect(a_get('/1.1/direct_messages/events/list.json').with(query: {count: '50', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @cli.direct_messages_sent expect($stdout.string).to eq <<-EOS @@ -350,6 +358,7 @@ EOS end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -401,6 +410,7 @@ @cli.direct_messages_sent expect(a_get('/1.1/direct_messages/events/list.json').with(query: {count: '50', include_entities: 'false'})).to have_been_made end + it 'limits the number of results to 201' do @cli.options = @cli.options.merge('number' => 201) @cli.direct_messages_sent @@ -443,10 +453,12 @@ expect(a_post('/1.1/direct_messages/events/new.json').with(body: {event: {type: 'message_create', message_create: {target: {recipient_id: 7_505_382}, message_data: {text: 'Creating a fixture for the Twitter gem'}}}})).to have_been_made expect(a_get('/1.1/users/show.json').with(query: {screen_name: 'sferik'})).to have_been_made end + it 'has the correct output' do @cli.dm('sferik', 'Creating a fixture for the Twitter gem') expect($stdout.string.chomp).to eq 'Direct Message sent from @testcli to @sferik.' end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -459,6 +471,7 @@ expect(a_post('/1.1/direct_messages/events/new.json').with(body: {event: {type: 'message_create', message_create: {target: {recipient_id: 7_505_382}, message_data: {text: 'Creating a fixture for the Twitter gem'}}}})).to have_been_made expect(a_get('/1.1/users/show.json').with(query: {user_id: '7505382'})).to have_been_made end + it 'has the correct output' do @cli.dm('7505382', 'Creating a fixture for the Twitter gem') expect($stdout.string.chomp).to eq 'Direct Message sent from @testcli to @sferik.' @@ -476,10 +489,12 @@ @cli.does_contain('presidents') expect(a_get('/1.1/lists/members/show.json').with(query: {owner_screen_name: 'testcli', screen_name: 'testcli', slug: 'presidents'})).to have_been_made end + it 'has the correct output' do @cli.does_contain('presidents') expect($stdout.string.chomp).to eq 'Yes, presidents contains @testcli.' end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -499,6 +514,7 @@ @cli.does_contain('testcli/presidents', 'testcli') expect($stdout.string.chomp).to eq 'Yes, presidents contains @testcli.' end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -545,10 +561,12 @@ @cli.does_follow('ev') expect(a_get('/1.1/friendships/show.json').with(query: {source_screen_name: 'ev', target_screen_name: 'testcli'})).to have_been_made end + it 'has the correct output' do @cli.does_follow('ev') expect($stdout.string.chomp).to eq 'Yes, @ev follows @testcli.' end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -561,6 +579,7 @@ expect(a_get('/1.1/users/show.json').with(query: {user_id: '20'})).to have_been_made expect(a_get('/1.1/friendships/show.json').with(query: {source_screen_name: 'sferik', target_screen_name: 'testcli'})).to have_been_made end + it 'has the correct output' do @cli.does_follow('20') expect($stdout.string.chomp).to eq 'Yes, @sferik follows @testcli.' @@ -576,10 +595,12 @@ @cli.does_follow('ev', 'sferik') expect(a_get('/1.1/friendships/show.json').with(query: {source_screen_name: 'ev', target_screen_name: 'sferik'})).to have_been_made end + it 'has the correct output' do @cli.does_follow('ev', 'sferik') expect($stdout.string.chomp).to eq 'Yes, @ev follows @sferik.' end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -594,16 +615,19 @@ expect(a_get('/1.1/users/show.json').with(query: {user_id: '428004849'})).to have_been_made expect(a_get('/1.1/friendships/show.json').with(query: {source_screen_name: 'sferik', target_screen_name: 'sferik'})).to have_been_made end + it 'has the correct output' do @cli.does_follow('20', '428004849') expect($stdout.string.chomp).to eq 'Yes, @sferik follows @sferik.' end + it 'cannot follow yourself' do expect do @cli.does_follow 'testcli' expect($stderr.string.chomp).to eq 'No, you are not following yourself.' end.to raise_error(SystemExit) end + it 'cannot check same account' do expect do @cli.does_follow('sferik', 'sferik') @@ -637,6 +661,7 @@ @cli.favorite('26755176471724032') expect(a_post('/1.1/favorites/create.json').with(body: {id: '26755176471724032'})).to have_been_made end + it 'has the correct output' do @cli.favorite('26755176471724032') expect($stdout.string).to match(/^@testcli favorited 1 tweet.$/) @@ -652,6 +677,7 @@ @cli.favorites expect(a_get('/1.1/favorites/list.json').with(query: {count: '20', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @cli.favorites expect($stdout.string).to eq <<-EOS @@ -732,6 +758,7 @@ EOS end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -775,6 +802,7 @@ @cli.favorites expect(a_get('/1.1/favorites/list.json').with(query: {count: '20', include_entities: 'true'})).to have_been_made end + it 'decodes URLs' do @cli.favorites expect($stdout.string).to include 'https://twitter.com/sferik/status/243988000076337152' @@ -812,6 +840,7 @@ 244099460672679938 Sep 7 07:47 @dwiskus Gentlemen, you can't fig... EOS end + context '--reverse' do before do @cli.options = @cli.options.merge('reverse' => true) @@ -870,6 +899,7 @@ @cli.favorites expect(a_get('/1.1/favorites/list.json').with(query: {count: '1', include_entities: 'false'})).to have_been_made end + it 'limits the number of results to 201' do @cli.options = @cli.options.merge('number' => 201) @cli.favorites @@ -899,6 +929,7 @@ @cli.favorites('sferik') expect(a_get('/1.1/favorites/list.json').with(query: {count: '20', screen_name: 'sferik', include_entities: 'false'})).to have_been_made end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -935,6 +966,7 @@ @cli.favorites('sferik') expect(a_get('/1.1/favorites/list.json').with(query: {count: '1', screen_name: 'sferik', include_entities: 'false'})).to have_been_made end + it 'limits the number of results to 201' do @cli.options = @cli.options.merge('number' => 201) @cli.favorites('sferik') @@ -977,10 +1009,12 @@ expect(a_get('/1.1/users/lookup.json').with(query: {screen_name: 'sferik,pengwynn'})).to have_been_made expect(a_post('/1.1/friendships/create.json').with(body: {user_id: '14100886'})).to have_been_made end + it 'has the correct output' do @cli.follow('sferik', 'pengwynn') expect($stdout.string).to match(/^@testcli is now following 1 more user\.$/) end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -1026,10 +1060,12 @@ expect(a_get('/1.1/friends/ids.json').with(query: {cursor: '-1', user_id: '7505382'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '7505382'})).to have_been_made end + it 'has the correct output' do @cli.followings expect($stdout.string.chomp).to eq 'pengwynn sferik' end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -1198,10 +1234,12 @@ expect(a_get('/1.1/followers/ids.json').with(query: {cursor: '-1', screen_name: 'sferik'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '7505382'})).to have_been_made end + it 'has the correct output' do @cli.followings_following('sferik') expect($stdout.string.chomp).to eq 'pengwynn sferik' end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -1343,6 +1381,7 @@ expect(a_get('/1.1/followers/ids.json').with(query: {cursor: '-1', screen_name: 'sferik'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '7505382'})).to have_been_made end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -1373,10 +1412,12 @@ expect(a_get('/1.1/followers/ids.json').with(query: {cursor: '-1', user_id: '7505382'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '7505382'})).to have_been_made end + it 'has the correct output' do @cli.followers expect($stdout.string.chomp).to eq 'pengwynn sferik' end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -1517,6 +1558,7 @@ expect(a_get('/1.1/followers/ids.json').with(query: {cursor: '-1', screen_name: 'sferik'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '7505382'})).to have_been_made end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -1547,10 +1589,12 @@ expect(a_get('/1.1/followers/ids.json').with(query: {cursor: '-1', screen_name: 'sferik'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '7505382'})).to have_been_made end + it 'has the correct output' do @cli.friends expect($stdout.string.chomp).to eq 'pengwynn sferik' end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -1692,6 +1736,7 @@ expect(a_get('/1.1/followers/ids.json').with(query: {cursor: '-1', screen_name: 'sferik'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '7505382'})).to have_been_made end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -1724,10 +1769,12 @@ expect(a_get('/1.1/friends/ids.json').with(query: {cursor: '-1', screen_name: 'sferik'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '213747670,428004849'})).to have_been_made end + it 'has the correct output' do @cli.groupies expect($stdout.string.chomp).to eq 'pengwynn sferik' end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -1869,6 +1916,7 @@ expect(a_get('/1.1/friends/ids.json').with(query: {cursor: '-1', screen_name: 'sferik'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '213747670,428004849'})).to have_been_made end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -1900,10 +1948,12 @@ expect(a_get('/1.1/friends/ids.json').with(query: {cursor: '-1', screen_name: 'sferik'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '7505382'})).to have_been_made end + it 'has the correct output' do @cli.intersection('sferik') expect($stdout.string.chomp).to eq 'pengwynn sferik' end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -2036,6 +2086,7 @@ expect(a_get('/1.1/followers/ids.json').with(query: {cursor: '-1', screen_name: 'sferik'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '213747670,428004849'})).to have_been_made end + it 'has the correct output' do @cli.intersection('sferik') expect($stdout.string.chomp).to eq 'pengwynn sferik' @@ -2065,6 +2116,7 @@ expect(a_get('/1.1/friends/ids.json').with(query: {cursor: '-1', screen_name: 'sferik'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '7505382'})).to have_been_made end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -2097,10 +2149,12 @@ expect(a_get('/1.1/followers/ids.json').with(query: {cursor: '-1', screen_name: 'sferik'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '7505382'})).to have_been_made end + it 'has the correct output' do @cli.leaders expect($stdout.string.chomp).to eq 'pengwynn sferik' end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -2242,6 +2296,7 @@ expect(a_get('/1.1/followers/ids.json').with(query: {cursor: '-1', screen_name: 'sferik'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '7505382'})).to have_been_made end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -2268,10 +2323,12 @@ @cli.lists expect(a_get('/1.1/lists/list.json')).to have_been_made end + it 'has the correct output' do @cli.lists expect($stdout.string.chomp).to eq '@pengwynn/rubyists @twitter/team @sferik/test' end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -2379,6 +2436,7 @@ @cli.lists('sferik') expect(a_get('/1.1/lists/list.json').with(query: {screen_name: 'sferik'})).to have_been_made end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -2404,6 +2462,7 @@ expect(a_get('/1.1/search/tweets.json').with(query: {q: 'lang:ja', count: 100, include_entities: 'false'})).to have_been_made expect(a_get('/1.1/search/tweets.json').with(query: {q: 'lang:ja', count: 100, max_id: '434642935557021697', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @cli.matrix expect($stdout.string).to eq('すまてっんさすでらなるあでかんせまいるきでいおすでいたりにずらさなもはういとざいうよいなしにいおでんせまてっはもらかのはにののずらかかるれらけでついらかがはがすでろこといたいとにいおにばらなくいばれたあんゃちあさかじましたあいしのくうよめやのうとこういうそたみてっがんくをまさかうょしでのるれくていでいてってっねよるれなくとのもなんみばれなくとのがいななんそよいなくしてしかんけでのとのいいゃちめ んくけったっだもどけるあはえたっあてっのやににめたのあたっかしこそあしだうそもなねうろだんるなになとっもらたてっにもしもるうおんぶたすまりなにはにかいちんゃにぃちほでいなしにのいいばれしことななんみわだいわこま  いたきのわふわっふくじたすましらかいならわたでんびにでれそんけやなかのたっゃちしとかよたてちにのねいさだくてきすましにりぱっやにいつがたしまりあはろことうろいろいあまねんもだにうとがりあいなてえかしとこたれらててれさてれさてれさきはいなてえうなるがゃちっめつっおいばやらかたてっすでのいばやいばやまんほねよすでかだんなかたしでうそりはやいわかりきっすしがんせまりあはでのていつにのなかのいなはにいらくるがなもとまてめせるけぬしをるすいならをるすいなてめじなにずらわかかもにのなとんにあにあてうゃちんさばおよすでてくなゃじすではのるてっがんさがすましででのいなおはてっあがつやるすにいたみをるあのとのるでいなきでかしではんくどんえっへすでみらたぎすらかんさのらかれこかすでるけべとっずをねいさだくでんにでのなびなんそてんなだねるめたかとこのせゆるねいがすさたっかはのこいなえりあぇふっぇふっぇふいらくとだらかだいらくでいたみゃちっめっもはてくないくしてっやのゆこそこきとなんこういてみのたしねどけうといぞうどるえもでんなででのみるぐいぬでさのでででべなきでききでるてっでぬいねもでくつりがのうよしうどいなくたきうもわこのだねすでうそええいなえかしおらかてっとおよだのいがのてっなくないがういとだぎゃじなをたっかなえとおでまだんでんをのてきてちおらかかったっかなくきのけにいたけにをいなえかしにでてべすのいらくれそできがにももいたりをのそるえうそとたっかよにとこたえにえかすまりかわかるいてっがすまいでんがいながすでのるすをいむにのるすのるいていかをたまてっよにくいてっがらかりすうよたれさにまさいながいのとのるてったいとっょちぜだんなつやいいるてっなにとこなてれがのそっくみいたきいるあではにずはいがりよえかちてしとにせらがにでたえばつにでのるすをれことんほ いのと すがるかわるてしはのてんないならをれあるあがぁぁぁぐっっべやかえねゃじんすらなれこよてままいがとれそねよいもれそぱっやをいいねてしごをいしうとがりあもうとがりあもいさゃにみすやおいまうがのすましいおばろぉふらたっかよすまきだたいてせさろぉふすまいざごうとがりあのたしまりなくすできらかいのこたみていかたてってっいたみていにすまいざごうよはおすではつつらからかうもちっこうそあわうたっへこどにでとるぎすなんみがのうよてしのかはのいがかだとみゃしくにうよすまりあでるれでがのにのたっやいてっらこいによはらかだたっかなかついかしいらくいえてえかすまてっでねすでりえかおよたっゃちっいさなんめごたしあうろやでらながっええたしましうとがりあうろをできいさなみすやおるらがなえをいなのくべるなかうこでういうどのでかしつかはてさいばやはれそいばやいばやんらまたんらまたうもらかやきたっかとんほいめやおいなけでどけいたき') @@ -2419,6 +2478,7 @@ @cli.mentions expect(a_get('/1.1/statuses/mentions_timeline.json').with(query: {count: '20', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @cli.mentions expect($stdout.string).to eq <<-EOS @@ -2499,6 +2559,7 @@ EOS end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -2542,6 +2603,7 @@ @cli.mentions expect(a_get('/1.1/statuses/mentions_timeline.json').with(query: {count: '20', include_entities: 'true'})).to have_been_made end + it 'decodes URLs' do @cli.mentions expect($stdout.string).to include 'https://twitter.com/sferik/status/243988000076337152' @@ -2579,6 +2641,7 @@ 244099460672679938 Sep 7 07:47 @dwiskus Gentlemen, you can't fig... EOS end + context '--reverse' do before do @cli.options = @cli.options.merge('reverse' => true) @@ -2625,6 +2688,7 @@ @cli.mentions expect(a_get('/1.1/statuses/mentions_timeline.json').with(query: {count: '1', include_entities: 'false'})).to have_been_made end + it 'limits the number of results to 201' do @cli.options = @cli.options.merge('number' => 201) @cli.mentions @@ -2644,10 +2708,12 @@ @cli.mute('sferik') expect(a_post('/1.1/mutes/users/create.json').with(body: {screen_name: 'sferik'})).to have_been_made end + it 'has the correct output' do @cli.mute('sferik') expect($stdout.string).to match(/^@testcli muted 1 user/) end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -2672,6 +2738,7 @@ expect(a_get('/1.1/mutes/users/ids.json').with(query: {cursor: '-1'})).to have_been_made expect(a_get('/1.1/users/lookup.json').with(query: {user_id: '14098423'})).to have_been_made end + it 'has the correct output' do @cli.muted expect($stdout.string.chomp).to eq 'johndbritton' @@ -2688,6 +2755,7 @@ @cli.open('sferik') end.not_to raise_error end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -2710,6 +2778,7 @@ @cli.open('55709764298092545') expect(a_get('/1.1/statuses/show/55709764298092545.json').with(query: {include_my_retweet: 'false'})).to have_been_made end + it 'has the correct output' do expect do @cli.open('55709764298092545') @@ -2737,6 +2806,7 @@ expect(a_get('/1.1/followers/ids.json').with(query: {cursor: '-1', user_id: '20009713'})).to have_been_made expect(a_get('/1.1/followers/ids.json').with(query: {cursor: '-1', user_id: '14100886'})).to have_been_made end + it 'has the correct output' do @cli.reach('55709764298092545') expect($stdout.string.split("\n").first).to eq '2' @@ -2759,10 +2829,12 @@ expect(a_request(:get, 'http://checkip.dyndns.org/')).not_to have_been_made expect(a_request(:get, 'http://www.geoplugin.net/xml.gp?ip=50.131.22.169')).not_to have_been_made end + it 'has the correct output' do @cli.reply('263813522369159169', 'Testing') expect($stdout.string.split("\n").first).to eq 'Reply posted by @testcli to @joshfrench.' end + context '--all' do before do @cli.options = @cli.options.merge('all' => true) @@ -2776,6 +2848,7 @@ expect(a_request(:get, 'http://checkip.dyndns.org/')).not_to have_been_made expect(a_request(:get, 'http://www.geoplugin.net/xml.gp?ip=50.131.22.169')).not_to have_been_made end + it 'has the correct output' do @cli.reply('263813522369159169', 'Testing') expect($stdout.string.split("\n").first).to eq 'Reply posted by @testcli to @joshfrench @sferik.' @@ -2794,6 +2867,7 @@ expect(a_request(:post, 'https://upload.twitter.com/1.1/media/upload.json')).to have_been_made expect(a_post('/1.1/statuses/update.json')).to have_been_made end + it 'has the correct output' do @cli.reply('263813522369159169', 'Testing') expect($stdout.string.split("\n").first).to eq 'Reply posted by @testcli to @joshfrench.' @@ -2814,6 +2888,7 @@ expect(a_request(:get, 'http://checkip.dyndns.org/')).to have_been_made expect(a_request(:get, 'http://www.geoplugin.net/xml.gp?ip=50.131.22.169')).to have_been_made end + it 'has the correct output' do @cli.reply('263813522369159169', 'Testing') expect($stdout.string.split("\n").first).to eq 'Reply posted by @testcli to @joshfrench.' @@ -2834,6 +2909,7 @@ expect(a_request(:get, 'http://checkip.dyndns.org/')).not_to have_been_made expect(a_request(:get, 'http://www.geoplugin.net/xml.gp?ip=50.131.22.169')).not_to have_been_made end + it 'has the correct output' do @cli.reply('263813522369159169', 'Testing') expect($stdout.string.split("\n").first).to eq 'Reply posted by @testcli to @joshfrench.' @@ -2858,10 +2934,12 @@ @cli.report_spam('sferik') expect(a_post('/1.1/users/report_spam.json').with(body: {screen_name: 'sferik'})).to have_been_made end + it 'has the correct output' do @cli.report_spam('sferik') expect($stdout.string).to match(/^@testcli reported 1 user/) end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -2885,6 +2963,7 @@ @cli.retweet('26755176471724032') expect(a_post('/1.1/statuses/retweet/26755176471724032.json')).to have_been_made end + it 'has the correct output' do @cli.retweet('26755176471724032') expect($stdout.string).to match(/^@testcli retweeted 1 tweet.$/) @@ -2903,6 +2982,7 @@ expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', include_rts: 'true', include_entities: 'false'})).to have_been_made expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', include_rts: 'true', max_id: '244102729860009983', include_entities: 'false'})).to have_been_made.times(3) end + it 'has the correct output' do @cli.retweets expect($stdout.string).to eq <<-EOS @@ -3068,6 +3148,7 @@ 244107823733174272 Sep 7 08:20 @codeforamerica RT @randomhacks: Going to ... EOS end + context '--reverse' do before do @cli.options = @cli.options.merge('reverse' => true) @@ -3113,6 +3194,7 @@ @cli.retweets expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', include_rts: 'true', include_entities: 'false'})).to have_been_made end + it 'limits the number of results to 201' do @cli.options = @cli.options.merge('number' => 201) @cli.retweets @@ -3132,6 +3214,7 @@ expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', include_rts: 'true', screen_name: 'sferik', include_entities: 'false'})).to have_been_made expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', include_rts: 'true', screen_name: 'sferik', max_id: '244102729860009983', include_entities: 'false'})).to have_been_made.times(3) end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -3158,6 +3241,7 @@ @cli.retweets_of_me expect(a_get('/1.1/statuses/retweets_of_me.json').with(query: {count: '20', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @cli.retweets_of_me expect($stdout.string).to eq <<-EOS @@ -3316,6 +3400,7 @@ 244099460672679938 Sep 7 07:47 @dwiskus Gentlemen, you can't fig... EOS end + context '--reverse' do before do @cli.options = @cli.options.merge('reverse' => true) @@ -3364,6 +3449,7 @@ @cli.retweets_of_me expect(a_get('/1.1/statuses/retweets_of_me.json').with(query: {count: '1', include_entities: 'false'})).to have_been_made end + it 'limits the number of results to 201' do @cli.options = @cli.options.merge('number' => 201) @cli.retweets_of_me @@ -3381,6 +3467,7 @@ expect($stdout.string.chomp.size).to eq 140 expect($stdout.string.chomp).to eq '----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|----|' end + context 'with indentation' do before do @cli.options = @cli.options.merge('indent' => 2) @@ -3403,6 +3490,7 @@ @cli.status('55709764298092545') expect(a_get('/1.1/statuses/show/55709764298092545.json').with(query: {include_my_retweet: 'false', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @cli.status('55709764298092545') expect($stdout.string).to eq <<~EOS @@ -3416,6 +3504,7 @@ Location Blowfish Sushi To Die For, 2170 Bryant St, San Francisco, California, United States EOS end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -3549,6 +3638,7 @@ Location San Francisco, CA, United States EOS end + context 'with no city' do before do stub_get('/1.1/statuses/show/55709764298092545.json').with(query: {include_my_retweet: 'false', include_entities: 'false'}).to_return(body: fixture('status_no_place.json'), headers: {content_type: 'application/json; charset=utf-8'}) @@ -3626,6 +3716,7 @@ Location Blowfish Sushi To Die For, 2170 Bryant St, San Francisco, California, United States EOS end + it 'whois has the correct output (absolute and relative date together)' do @cli.whois('sferik') expect($stdout.string).to eq <<~EOS @@ -3644,6 +3735,7 @@ URL https://github.com/sferik EOS end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -3684,6 +3776,7 @@ @cli.timeline expect(a_get('/1.1/statuses/home_timeline.json').with(query: {count: '20', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @cli.timeline expect($stdout.string).to eq <<-EOS @@ -3809,6 +3902,7 @@ @cli.timeline expect(a_get('/1.1/statuses/home_timeline.json').with(query: {count: '20', include_entities: 'true'})).to have_been_made end + it 'decodes URLs' do @cli.timeline expect($stdout.string).to include 'https://twitter.com/sferik/status/243988000076337152' @@ -3870,6 +3964,7 @@ 244099460672679938 Sep 7 07:47 @dwiskus Gentlemen, you can't fig... EOS end + context '--reverse' do before do @cli.options = @cli.options.merge('reverse' => true) @@ -3928,6 +4023,7 @@ @cli.timeline expect(a_get('/1.1/statuses/home_timeline.json').with(query: {count: '1', include_entities: 'false'})).to have_been_made end + it 'limits the number of results to 201' do @cli.options = @cli.options.merge('number' => 201) @cli.timeline @@ -3957,6 +4053,7 @@ @cli.timeline('sferik') expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '20', screen_name: 'sferik', include_entities: 'false'})).to have_been_made end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -3993,6 +4090,7 @@ @cli.timeline('sferik') expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '1', screen_name: 'sferik', include_entities: 'false'})).to have_been_made end + it 'limits the number of results to 201' do @cli.options = @cli.options.merge('number' => 201) @cli.timeline('sferik') @@ -4024,10 +4122,12 @@ @cli.trends expect(a_get('/1.1/trends/place.json').with(query: {id: '1'})).to have_been_made end + it 'has the correct output' do @cli.trends expect($stdout.string.chomp).to eq '#sevenwordsaftersex Walkman Allen Iverson' end + context '--exclude-hashtags' do before do @cli.options = @cli.options.merge('exclude-hashtags' => true) @@ -4038,6 +4138,7 @@ @cli.trends expect(a_get('/1.1/trends/place.json').with(query: {id: '1', exclude: 'hashtags'})).to have_been_made end + it 'has the correct output' do @cli.trends expect($stdout.string.chomp).to eq '#sevenwordsaftersex Walkman Allen Iverson' @@ -4053,6 +4154,7 @@ @cli.trends('2487956') expect(a_get('/1.1/trends/place.json').with(query: {id: '2487956'})).to have_been_made end + it 'has the correct output' do @cli.trends('2487956') expect($stdout.string.chomp).to eq '#sevenwordsaftersex Walkman Allen Iverson' @@ -4069,10 +4171,12 @@ @cli.trend_locations expect(a_get('/1.1/trends/available.json')).to have_been_made end + it 'has the correct output' do @cli.trend_locations expect($stdout.string.chomp).to eq 'San Francisco Soweto United States Worldwide' end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -4185,11 +4289,13 @@ @cli.unfollow('sferik') expect(a_post('/1.1/friendships/destroy.json').with(body: {screen_name: 'sferik'})).to have_been_made end + it 'has the correct output' do stub_post('/1.1/friendships/destroy.json').with(body: {screen_name: 'sferik'}).to_return(body: fixture('sferik.json'), headers: {content_type: 'application/json; charset=utf-8'}) @cli.unfollow('sferik') expect($stdout.string).to match(/^@testcli is no longer following 1 user\.$/) end + context '--id' do before do @cli.options = @cli.options.merge('id' => true) @@ -4228,10 +4334,12 @@ expect(a_request(:get, 'http://checkip.dyndns.org/')).not_to have_been_made expect(a_request(:get, 'http://www.geoplugin.net/xml.gp?ip=50.131.22.169')).not_to have_been_made end + it 'has the correct output' do @cli.update('Testing') expect($stdout.string.split("\n").first).to eq 'Tweet posted by @testcli.' end + context 'with file' do before do @cli.options = @cli.options.merge('file' => "#{fixture_path}/long.png") @@ -4244,6 +4352,7 @@ expect(a_request(:post, 'https://upload.twitter.com/1.1/media/upload.json')).to have_been_made expect(a_post('/1.1/statuses/update.json')).to have_been_made end + it 'has the correct output' do @cli.update('Testing') expect($stdout.string.split("\n").first).to eq 'Tweet posted by @testcli.' @@ -4262,6 +4371,7 @@ expect(a_request(:get, 'http://checkip.dyndns.org/')).to have_been_made expect(a_request(:get, 'http://www.geoplugin.net/xml.gp?ip=50.131.22.169')).to have_been_made end + it 'has the correct output' do @cli.update('Testing') expect($stdout.string.split("\n").first).to eq 'Tweet posted by @testcli.' @@ -4280,6 +4390,7 @@ expect(a_request(:get, 'http://checkip.dyndns.org/')).not_to have_been_made expect(a_request(:get, 'http://www.geoplugin.net/xml.gp?ip=50.131.22.169')).not_to have_been_made end + it 'has the correct output' do @cli.update('Testing') expect($stdout.string.split("\n").first).to eq 'Tweet posted by @testcli.' @@ -4303,10 +4414,12 @@ @cli.users('sferik', 'pengwynn') expect(a_get('/1.1/users/lookup.json').with(query: {screen_name: 'sferik,pengwynn'})).to have_been_made end + it 'has the correct output' do @cli.users('sferik', 'pengwynn') expect($stdout.string.chomp).to eq 'pengwynn sferik' end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -4465,6 +4578,7 @@ @cli.whois('sferik') expect(a_get('/1.1/users/show.json').with(query: {screen_name: 'sferik', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @cli.whois('sferik') expect($stdout.string).to eq <<~EOS @@ -4483,6 +4597,7 @@ URL https://github.com/sferik EOS end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) @@ -4533,6 +4648,7 @@ @cli.whoami expect(a_get('/1.1/users/show.json').with(query: {screen_name: 'testcli', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @cli.whoami expect($stdout.string).to eq <<~EOS @@ -4551,6 +4667,7 @@ URL https://github.com/sferik EOS end + context '--csv' do before do @cli.options = @cli.options.merge('csv' => true) diff --git a/spec/delete_spec.rb b/spec/delete_spec.rb index 1a57f1ec..c2b61516 100644 --- a/spec/delete_spec.rb +++ b/spec/delete_spec.rb @@ -28,10 +28,12 @@ @delete.block('sferik') expect(a_post('/1.1/blocks/destroy.json').with(body: {screen_name: 'sferik'})).to have_been_made end + it 'has the correct output' do @delete.block('sferik') expect($stdout.string).to match(/^@testcli unblocked 1 user\.$/) end + context '--id' do before do @delete.options = @delete.options.merge('id' => true) @@ -60,6 +62,7 @@ expect(a_delete('/1.1/direct_messages/events/destroy.json').with(query: {id: '1773478249'})).to have_been_made expect(a_get('/1.1/users/show.json').with(query: {user_id: '58983'})).to have_been_made end + context 'yes' do it 'has the correct output' do expect(Readline).to receive(:readline).with('Are you sure you want to permanently delete the direct message to @sferik: "testing"? [y/N] ', false).and_return('yes') @@ -85,6 +88,7 @@ @delete.dm('1773478249') expect(a_delete('/1.1/direct_messages/events/destroy.json').with(query: {id: '1773478249'})).to have_been_made end + it 'has the correct output' do @delete.dm('1773478249') expect($stdout.string.chomp).to eq '@testcli deleted 1 direct message.' @@ -105,6 +109,7 @@ expect(a_get('/1.1/statuses/show/28439861609.json').with(query: {include_my_retweet: 'false'})).to have_been_made expect(a_post('/1.1/favorites/destroy.json').with(body: {id: '28439861609'})).to have_been_made end + context 'yes' do it 'has the correct output' do expect(Readline).to receive(:readline).with("Are you sure you want to remove @sferik's status: \"The problem with your code is that it's doing exactly what you told it to do.\" from your favorites? [y/N] ", false).and_return('yes') @@ -130,6 +135,7 @@ @delete.favorite('28439861609') expect(a_post('/1.1/favorites/destroy.json').with(body: {id: '28439861609'})).to have_been_made end + it 'has the correct output' do @delete.favorite('28439861609') expect($stdout.string).to match(/^@testcli unfavorited @sferik's status: "The problem with your code is that it's doing exactly what you told it to do\."$/) @@ -151,6 +157,7 @@ expect(a_get('/1.1/account/verify_credentials.json').with(query: {skip_status: 'true'})).to have_been_made expect(a_post('/1.1/lists/destroy.json').with(body: {owner_id: '7505382', list_id: '8863586'})).to have_been_made end + context 'yes' do it 'has the correct output' do expect(Readline).to receive(:readline).with('Are you sure you want to permanently delete the list "presidents"? [y/N] ', false).and_return('yes') @@ -177,6 +184,7 @@ expect(a_get('/1.1/account/verify_credentials.json').with(query: {skip_status: 'true'})).to have_been_made expect(a_post('/1.1/lists/destroy.json').with(body: {owner_id: '7505382', list_id: '8863586'})).to have_been_made end + it 'has the correct output' do @delete.list('presidents') expect($stdout.string.chomp).to eq '@testcli deleted the list "presidents".' @@ -209,10 +217,12 @@ @delete.mute('sferik') expect(a_post('/1.1/mutes/users/destroy.json').with(body: {screen_name: 'sferik'})).to have_been_made end + it 'has the correct output' do @delete.mute('sferik') expect($stdout.string).to match(/^@testcli unmuted 1 user\.$/) end + context '--id' do before do @delete.options = @delete.options.merge('id' => true) @@ -283,6 +293,7 @@ expect(a_get('/1.1/statuses/show/26755176471724032.json').with(query: {include_my_retweet: 'false'})).to have_been_made expect(a_post('/1.1/statuses/destroy/26755176471724032.json').with(body: {trim_user: 'true'})).to have_been_made end + context 'yes' do it 'has the correct output' do expect(Readline).to receive(:readline).with("Are you sure you want to permanently delete @sferik's status: \"The problem with your code is that it's doing exactly what you told it to do.\"? [y/N] ", false).and_return('yes') @@ -308,6 +319,7 @@ @delete.status('26755176471724032') expect(a_post('/1.1/statuses/destroy/26755176471724032.json').with(body: {trim_user: 'true'})).to have_been_made end + it 'has the correct output' do @delete.status('26755176471724032') expect($stdout.string.chomp).to eq "@testcli deleted the Tweet: \"The problem with your code is that it's doing exactly what you told it to do.\"" diff --git a/spec/list_spec.rb b/spec/list_spec.rb index f7c12504..65fa2043 100644 --- a/spec/list_spec.rb +++ b/spec/list_spec.rb @@ -40,10 +40,12 @@ expect(a_get('/1.1/account/verify_credentials.json').with(query: {skip_status: 'true'})).to have_been_made expect(a_post('/1.1/lists/members/create_all.json').with(body: {screen_name: 'BarackObama', slug: 'presidents', owner_id: '7505382'})).to have_been_made end + it 'has the correct output' do @list.add('presidents', 'BarackObama') expect($stdout.string.split("\n").first).to eq '@testcli added 1 member to the list "presidents".' end + context '--id' do before do @list.options = @list.options.merge('id' => true) @@ -78,6 +80,7 @@ @list.create('presidents') expect(a_post('/1.1/lists/create.json').with(body: {name: 'presidents'})).to have_been_made end + it 'has the correct output' do @list.create('presidents') expect($stdout.string.chomp).to eq '@testcli created the list "presidents".' @@ -94,6 +97,7 @@ @list.information('presidents') expect(a_get('/1.1/lists/show.json').with(query: {owner_screen_name: 'testcli', slug: 'presidents'})).to have_been_made end + it 'has the correct output' do @list.information('presidents') expect($stdout.string).to eq <<~EOS @@ -109,6 +113,7 @@ URL https://twitter.com/sferik/presidents EOS end + it 'has the correct output with --relative-dates turned on' do @list.options = @list.options.merge('relative_dates' => true) @list.information('presidents') @@ -125,11 +130,13 @@ URL https://twitter.com/sferik/presidents EOS end + context 'with a user passed' do it 'requests the correct resource' do @list.information('testcli/presidents') expect(a_get('/1.1/lists/show.json').with(query: {owner_screen_name: 'testcli', slug: 'presidents'})).to have_been_made end + context '--id' do before do @list.options = @list.options.merge('id' => true) @@ -167,10 +174,12 @@ @list.members('presidents') expect(a_get('/1.1/lists/members.json').with(query: {cursor: '-1', owner_screen_name: 'testcli', slug: 'presidents'})).to have_been_made end + it 'has the correct output' do @list.members('presidents') expect($stdout.string.chomp).to eq 'pengwynn sferik' end + context '--csv' do before do @list.options = @list.options.merge('csv' => true) @@ -305,6 +314,7 @@ @list.members('testcli/presidents') expect(a_get('/1.1/lists/members.json').with(query: {cursor: '-1', owner_screen_name: 'testcli', slug: 'presidents'})).to have_been_made end + context '--id' do before do @list.options = @list.options.merge('id' => true) @@ -331,11 +341,13 @@ expect(a_get('/1.1/account/verify_credentials.json').with(query: {skip_status: 'true'})).to have_been_made expect(a_post('/1.1/lists/members/destroy_all.json').with(body: {screen_name: 'BarackObama', slug: 'presidents', owner_id: '7505382'})).to have_been_made end + it 'has the correct output' do stub_post('/1.1/lists/members/destroy_all.json').with(body: {screen_name: 'BarackObama', slug: 'presidents', owner_id: '7505382'}).to_return(body: fixture('list.json'), headers: {content_type: 'application/json; charset=utf-8'}) @list.remove('presidents', 'BarackObama') expect($stdout.string.split("\n").first).to eq '@testcli removed 1 member from the list "presidents".' end + context '--id' do before do @list.options = @list.options.merge('id' => true) @@ -370,6 +382,7 @@ @list.timeline('presidents') expect(a_get('/1.1/lists/statuses.json').with(query: {owner_screen_name: 'testcli', count: '20', slug: 'presidents', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @list.timeline('presidents') expect($stdout.string).to eq <<-EOS @@ -450,6 +463,7 @@ EOS end + context '--color=never' do before do @list.options = @list.options.merge('color' => 'never') @@ -622,6 +636,7 @@ EOS end + it 'outputs with color when stdout is a tty' do allow($stdout).to receive(:tty?).and_return(true) @list.timeline('presidents') @@ -873,6 +888,7 @@ @list.timeline('presidents') expect(a_get('/1.1/lists/statuses.json').with(query: {owner_screen_name: 'testcli', count: '20', slug: 'presidents', include_entities: 'true'})).to have_been_made end + it 'decodes URLs' do @list.timeline('presidents') expect($stdout.string).to include 'https://twitter.com/sferik/status/243988000076337152' @@ -910,6 +926,7 @@ 244099460672679938 Sep 7 07:47 @dwiskus Gentlemen, you can't fig... EOS end + context '--reverse' do before do @list.options = @list.options.merge('reverse' => true) @@ -956,6 +973,7 @@ @list.timeline('presidents') expect(a_get('/1.1/lists/statuses.json').with(query: {owner_screen_name: 'testcli', count: '1', slug: 'presidents', include_entities: 'false'})).to have_been_made end + it 'limits the number of results to 201' do @list.options = @list.options.merge('number' => 201) @list.timeline('presidents') @@ -969,6 +987,7 @@ @list.timeline('testcli/presidents') expect(a_get('/1.1/lists/statuses.json').with(query: {owner_screen_name: 'testcli', count: '20', slug: 'presidents', include_entities: 'false'})).to have_been_made end + context '--id' do before do @list.options = @list.options.merge('id' => true) diff --git a/spec/rcfile_spec.rb b/spec/rcfile_spec.rb index c645acaa..deed4faf 100644 --- a/spec/rcfile_spec.rb +++ b/spec/rcfile_spec.rb @@ -38,6 +38,7 @@ } expect(rcfile['testcli'].keys).to eq %w[abc123] end + it 'is not be world writable' do rcfile = T::RCFile.instance rcfile.path = "#{project_path}/tmp/trc" @@ -52,6 +53,7 @@ } expect(File.world_writable?(rcfile.path)).to be_nil end + it 'is not be world readable' do rcfile = T::RCFile.instance rcfile.path = "#{project_path}/tmp/trc" @@ -185,6 +187,7 @@ rcfile.path = "#{project_path}/tmp/trc" expect(rcfile.path).to eq "#{project_path}/tmp/trc" end + it 'reloads data' do rcfile = T::RCFile.instance rcfile.path = "#{fixture_path}/.trc" diff --git a/spec/search_spec.rb b/spec/search_spec.rb index 0ecae657..eeaf891b 100644 --- a/spec/search_spec.rb +++ b/spec/search_spec.rb @@ -38,6 +38,7 @@ @search.all('twitter') expect(a_get('/1.1/search/tweets.json').with(query: {q: 'twitter', count: '100', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @search.all('twitter') expect($stdout.string).to eq <<-EOS @@ -113,6 +114,7 @@ EOS end + context '--csv' do before do @search.options = @search.options.merge('csv' => true) @@ -195,6 +197,7 @@ @search.all('twitter') expect(a_get('/1.1/search/tweets.json').with(query: {q: 'twitter', count: '100', include_entities: 'false'})).to have_been_made end + it 'limits the number of results to 201' do @search.options = @search.options.merge('number' => 201) @search.all('twitter') @@ -215,6 +218,7 @@ expect(a_get('/1.1/favorites/list.json').with(query: {count: '200', include_entities: 'false'})).to have_been_made expect(a_get('/1.1/favorites/list.json').with(query: {count: '200', max_id: '244099460672679937', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @search.favorites('twitter') expect($stdout.string).to eq <<-EOS @@ -227,6 +231,7 @@ EOS end + context '--csv' do before do @search.options = @search.options.merge('csv' => true) @@ -254,6 +259,7 @@ expect(a_get('/1.1/favorites/list.json').with(query: {count: '200', include_entities: 'true'})).to have_been_made expect(a_get('/1.1/favorites/list.json').with(query: {count: '200', include_entities: 'true', max_id: '244099460672679937'})).to have_been_made end + it 'decodes URLs' do @search.favorites('twitter') expect($stdout.string).to include 'https://twitter.com/sferik/status/243988000076337152' @@ -296,6 +302,7 @@ expect(a_get('/1.1/favorites/list.json').with(query: {count: '200', screen_name: 'sferik', include_entities: 'false'})).to have_been_made expect(a_get('/1.1/favorites/list.json').with(query: {count: '200', max_id: '244099460672679937', screen_name: 'sferik', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @search.favorites('sferik', 'twitter') expect($stdout.string).to eq <<-EOS @@ -308,6 +315,7 @@ EOS end + context '--id' do before do @search.options = @search.options.merge('id' => true) @@ -320,6 +328,7 @@ expect(a_get('/1.1/favorites/list.json').with(query: {count: '200', user_id: '7505382', include_entities: 'false'})).to have_been_made expect(a_get('/1.1/favorites/list.json').with(query: {count: '200', max_id: '244099460672679937', user_id: '7505382', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @search.favorites('7505382', 'twitter') expect($stdout.string).to eq <<-EOS @@ -347,6 +356,7 @@ expect(a_get('/1.1/statuses/mentions_timeline.json').with(query: {count: '200', include_entities: 'false'})).to have_been_made expect(a_get('/1.1/statuses/mentions_timeline.json').with(query: {count: '200', max_id: '244099460672679937', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @search.mentions('twitter') expect($stdout.string).to eq <<-EOS @@ -359,6 +369,7 @@ EOS end + context '--csv' do before do @search.options = @search.options.merge('csv' => true) @@ -386,6 +397,7 @@ expect(a_get('/1.1/statuses/mentions_timeline.json').with(query: {count: '200', include_entities: 'true'})).to have_been_made expect(a_get('/1.1/statuses/mentions_timeline.json').with(query: {count: '200', include_entities: 'true', max_id: '244099460672679937'})).to have_been_made end + it 'decodes URLs' do @search.mentions('twitter') expect($stdout.string).to include 'https://twitter.com/sferik/status/243988000076337152' @@ -429,6 +441,7 @@ expect(a_get('/1.1/lists/statuses.json').with(query: {count: '200', owner_screen_name: 'testcli', slug: 'presidents', include_entities: 'false'})).to have_been_made expect(a_get('/1.1/lists/statuses.json').with(query: {count: '200', max_id: '244099460672679937', owner_screen_name: 'testcli', slug: 'presidents', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @search.list('presidents', 'twitter') expect($stdout.string).to eq <<-EOS @@ -441,6 +454,7 @@ EOS end + context '--csv' do before do @search.options = @search.options.merge('csv' => true) @@ -468,6 +482,7 @@ expect(a_get('/1.1/lists/statuses.json').with(query: {count: '200', owner_screen_name: 'testcli', slug: 'presidents', include_entities: 'true'})).to have_been_made expect(a_get('/1.1/lists/statuses.json').with(query: {count: '200', max_id: '244099460672679937', owner_screen_name: 'testcli', slug: 'presidents', include_entities: 'true'})).to have_been_made end + it 'decodes URLs' do @search.list('presidents', 'twitter') expect($stdout.string).to include 'https://dev.twitter.com/docs/api/post/direct_messages/destroy' @@ -494,6 +509,7 @@ @search.list('testcli/presidents', 'twitter') expect(a_get('/1.1/lists/statuses.json').with(query: {count: '200', owner_screen_name: 'testcli', slug: 'presidents', include_entities: 'false'})).to have_been_made end + context '--id' do before do @search.options = @search.options.merge('id' => true) @@ -531,6 +547,7 @@ expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', include_rts: 'true', include_entities: 'false'})).to have_been_made expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', include_rts: 'true', max_id: '244102729860009983', include_entities: 'false'})).to have_been_made.times(2) end + it 'has the correct output' do @search.retweets('mosaic') expect($stdout.string).to eq <<-EOS @@ -539,6 +556,7 @@ EOS end + context '--csv' do before do @search.options = @search.options.merge('csv' => true) @@ -565,6 +583,7 @@ expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', include_rts: 'true', include_entities: 'true'})).to have_been_made expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', include_rts: 'true', max_id: '244102729860009983', include_entities: 'true'})).to have_been_made.times(2) end + it 'decodes URLs' do @search.retweets('mosaic') expect($stdout.string).to include 'http://heymosaic.com/i/1Z8ssK' @@ -606,6 +625,7 @@ expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', include_rts: 'true', screen_name: 'sferik', include_entities: 'false'})).to have_been_made expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', include_rts: 'true', screen_name: 'sferik', max_id: '244102729860009983', include_entities: 'false'})).to have_been_made.times(2) end + it 'has the correct output' do @search.retweets('sferik', 'mosaic') expect($stdout.string).to eq <<-EOS @@ -614,6 +634,7 @@ EOS end + context '--id' do before do @search.options = @search.options.merge('id' => true) @@ -626,6 +647,7 @@ expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', include_rts: 'true', user_id: '7505382', include_entities: 'false'})).to have_been_made expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', include_rts: 'true', user_id: '7505382', max_id: '244102729860009983', include_entities: 'false'})).to have_been_made.times(2) end + it 'has the correct output' do @search.retweets('7505382', 'mosaic') expect($stdout.string).to eq <<-EOS @@ -649,6 +671,7 @@ expect(a_get('/1.1/statuses/home_timeline.json').with(query: {count: '200', include_entities: 'false'})).to have_been_made expect(a_get('/1.1/statuses/home_timeline.json').with(query: {count: '200', max_id: '244099460672679937', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @search.timeline('twitter') expect($stdout.string).to eq <<-EOS @@ -661,6 +684,7 @@ EOS end + context '--csv' do before do @search.options = @search.options.merge('csv' => true) @@ -688,6 +712,7 @@ expect(a_get('/1.1/statuses/home_timeline.json').with(query: {count: '200', include_entities: 'true'})).to have_been_made expect(a_get('/1.1/statuses/home_timeline.json').with(query: {count: '200', max_id: '244099460672679937', include_entities: 'true'})).to have_been_made end + it 'decodes URLs' do @search.timeline('twitter') expect($stdout.string).to include 'https://dev.twitter.com/docs/api/post/direct_messages/destroy' @@ -784,6 +809,7 @@ expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', screen_name: 'sferik', include_entities: 'false'})).to have_been_made expect(a_get('/1.1/statuses/user_timeline.json').with(query: {count: '200', max_id: '244099460672679937', screen_name: 'sferik', include_entities: 'false'})).to have_been_made end + it 'has the correct output' do @search.timeline('sferik', 'twitter') expect($stdout.string).to eq <<-EOS @@ -796,6 +822,7 @@ EOS end + context '--csv' do before do @search.options = @search.options.merge('csv' => true) @@ -889,10 +916,12 @@ expect(a_get('/1.1/users/search.json').with(query: {page: '1', q: 'Erik'})).to have_been_made expect(a_get('/1.1/users/search.json').with(query: {page: '2', q: 'Erik'})).to have_been_made end + it 'has the correct output' do @search.users('Erik') expect($stdout.string.chomp).to eq 'pengwynn sferik' end + context '--csv' do before do @search.options = @search.options.merge('csv' => true) diff --git a/spec/set_spec.rb b/spec/set_spec.rb index 14e9ef21..12c8339d 100644 --- a/spec/set_spec.rb +++ b/spec/set_spec.rb @@ -27,19 +27,23 @@ @set.active('testcli', 'abc123') expect($stdout.string.chomp).to eq 'Active account has been updated to testcli.' end + it 'accepts an account name without a consumer key' do @set.active('testcli') expect($stdout.string.chomp).to eq 'Active account has been updated to testcli.' end + it 'is case insensitive' do @set.active('TestCLI', 'abc123') expect($stdout.string.chomp).to eq 'Active account has been updated to testcli.' end + it 'raises an error if username is ambiguous' do expect do @set.active('test', 'abc123') end.to raise_error(ArgumentError, /Username test is ambiguous/) end + it 'raises an error if the username is not found' do expect do @set.active('clitest') @@ -57,6 +61,7 @@ @set.bio('Vagabond.') expect(a_post('/1.1/account/update_profile.json').with(body: {description: 'Vagabond.'})).to have_been_made end + it 'has the correct output' do @set.bio('Vagabond.') expect($stdout.string.chomp).to eq "@testcli's bio has been updated." @@ -73,6 +78,7 @@ @set.language('en') expect(a_post('/1.1/account/settings.json').with(body: {lang: 'en'})).to have_been_made end + it 'has the correct output' do @set.language('en') expect($stdout.string.chomp).to eq "@testcli's language has been updated." @@ -89,6 +95,7 @@ @set.location('San Francisco') expect(a_post('/1.1/account/update_profile.json').with(body: {location: 'San Francisco'})).to have_been_made end + it 'has the correct output' do @set.location('San Francisco') expect($stdout.string.chomp).to eq "@testcli's location has been updated." @@ -105,6 +112,7 @@ @set.name('Erik Michaels-Ober') expect(a_post('/1.1/account/update_profile.json').with(body: {name: 'Erik Michaels-Ober'})).to have_been_made end + it 'has the correct output' do @set.name('Erik Michaels-Ober') expect($stdout.string.chomp).to eq "@testcli's name has been updated." @@ -121,6 +129,7 @@ @set.profile_background_image("#{fixture_path}/we_concept_bg2.png") expect(a_post('/1.1/account/update_profile_background_image.json')).to have_been_made end + it 'has the correct output' do @set.profile_background_image("#{fixture_path}/we_concept_bg2.png") expect($stdout.string.chomp).to eq "@testcli's background image has been updated." @@ -137,6 +146,7 @@ @set.profile_image("#{fixture_path}/me.jpg") expect(a_post('/1.1/account/update_profile_image.json')).to have_been_made end + it 'has the correct output' do @set.profile_image("#{fixture_path}/me.jpg") expect($stdout.string.chomp).to eq "@testcli's image has been updated." @@ -153,6 +163,7 @@ @set.website('https://github.com/sferik') expect(a_post('/1.1/account/update_profile.json').with(body: {url: 'https://github.com/sferik'})).to have_been_made end + it 'has the correct output' do @set.website('https://github.com/sferik') expect($stdout.string.chomp).to eq "@testcli's website has been updated." diff --git a/spec/stream_spec.rb b/spec/stream_spec.rb index 0bf2997b..5035b7b2 100644 --- a/spec/stream_spec.rb +++ b/spec/stream_spec.rb @@ -30,6 +30,7 @@ expect(@stream).to receive(:print_message) @stream.all end + context '--csv' do before do @stream.options = @stream.options.merge('csv' => true) @@ -41,6 +42,7 @@ expect(@stream).to receive(:say).with("ID,Posted at,Screen name,Text\n") @stream.all end + it 'outputs in CSV format' do allow(@streaming_client).to receive(:before_request) allow(@streaming_client).to receive(:sample).and_yield(@tweet) @@ -60,6 +62,7 @@ expect(@stream).to receive(:print_table).with(any_args) @stream.all end + it 'outputs in long text format' do allow(@streaming_client).to receive(:before_request) allow(@streaming_client).to receive(:sample).and_yield(@tweet) @@ -86,10 +89,12 @@ allow(@streaming_client).to receive(:filter).and_yield(@tweet) @stream.list('presidents') end + it 'requests the correct resource' do @stream.list('presidents') expect(a_get('/1.1/lists/members.json').with(query: {cursor: '-1', owner_screen_name: 'testcli', slug: 'presidents'})).to have_been_made end + context '--csv' do before do @stream.options = @stream.options.merge('csv' => true) @@ -101,6 +106,7 @@ expect(@stream).to receive(:print_csv_tweet).with(any_args) @stream.list('presidents') end + it 'requests the correct resource' do @stream.list('presidents') expect(a_get('/1.1/lists/members.json').with(query: {cursor: '-1', owner_screen_name: 'testcli', slug: 'presidents'})).to have_been_made @@ -118,6 +124,7 @@ expect(@stream).to receive(:print_table).with(any_args) @stream.list('presidents') end + it 'requests the correct resource' do @stream.list('presidents') expect(a_get('/1.1/lists/members.json').with(query: {cursor: '-1', owner_screen_name: 'testcli', slug: 'presidents'})).to have_been_made @@ -131,6 +138,7 @@ expect(t_class).to receive(:timeline) @stream.list('presidents') end + it 'invokes Twitter::Streaming::Client#userstream' do allow(@streaming_client).to receive(:filter) expect(@streaming_client).to receive(:filter) @@ -149,12 +157,14 @@ expect(@stream).to receive(:say).with(any_args) @stream.matrix end + it 'invokes Twitter::Streaming::Client#sample' do allow(@streaming_client).to receive(:before_request) allow(@streaming_client).to receive(:sample).and_yield(@tweet) expect(@streaming_client).to receive(:sample) @stream.matrix end + it 'requests the correct resource' do allow(@streaming_client).to receive(:before_request).and_yield @stream.matrix @@ -171,6 +181,7 @@ expect(@stream).to receive(:print_message) @stream.search(%w[twitter gem]) end + context '--csv' do before do @stream.options = @stream.options.merge('csv' => true) @@ -203,6 +214,7 @@ expect(t_class).to receive(:all).with('t OR gem') @stream.search('t', 'gem') end + it 'invokes Twitter::Streaming::Client#filter' do allow(@streaming_client).to receive(:filter) expect(@streaming_client).to receive(:filter).with(track: 'twitter,gem') @@ -219,6 +231,7 @@ expect(@stream).to receive(:print_message) @stream.timeline end + context '--csv' do before do @stream.options = @stream.options.merge('csv' => true) @@ -250,6 +263,7 @@ expect(t_class).to receive(:timeline) @stream.timeline end + it 'invokes Twitter::Streaming::Client#userstream' do allow(@streaming_client).to receive(:user) expect(@streaming_client).to receive(:user) @@ -266,6 +280,7 @@ expect(@stream).to receive(:print_message) @stream.users('123') end + context '--csv' do before do @stream.options = @stream.options.merge('csv' => true) @@ -277,6 +292,7 @@ expect(@stream).to receive(:say).with("ID,Posted at,Screen name,Text\n") @stream.users('123') end + it 'outputs in CSV format' do allow(@streaming_client).to receive(:before_request) expect(@stream).to receive(:print_csv_tweet).with(any_args) @@ -295,6 +311,7 @@ expect(@stream).to receive(:print_table).with(any_args) @stream.users('123') end + it 'outputs in long text format' do allow(@streaming_client).to receive(:before_request) allow(@streaming_client).to receive(:filter).and_yield(@tweet) diff --git a/spec/utils_spec.rb b/spec/utils_spec.rb index 198d851e..0c19529d 100644 --- a/spec/utils_spec.rb +++ b/spec/utils_spec.rb @@ -24,54 +24,71 @@ class Test; end it 'returns "a split second" if difference is less than a second' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 11, 24, 16, 20, 0))).to eq 'a split second' end + it 'returns "a second" if difference is a second' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 11, 24, 16, 20, 1))).to eq 'a second' end + it 'returns "2 seconds" if difference is 2 seconds' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 11, 24, 16, 20, 2))).to eq '2 seconds' end + it 'returns "59 seconds" if difference is just shy of 1 minute' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 11, 24, 16, 20, 59.9))).to eq '59 seconds' end + it 'returns "a minute" if difference is 1 minute' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 11, 24, 16, 21, 0))).to eq 'a minute' end + it 'returns "2 minutes" if difference is 2 minutes' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 11, 24, 16, 22, 0))).to eq '2 minutes' end + it 'returns "59 minutes" if difference is just shy of 1 hour' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 11, 24, 17, 19, 59.9))).to eq '59 minutes' end + it 'returns "an hour" if difference is 1 hour' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 11, 24, 17, 20, 0))).to eq 'an hour' end + it 'returns "2 hours" if difference is 2 hours' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 11, 24, 18, 20, 0))).to eq '2 hours' end + it 'returns "23 hours" if difference is just shy of 23.5 hours' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 11, 25, 15, 49, 59.9))).to eq '23 hours' end + it 'returns "a day" if difference is 23.5 hours' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 11, 25, 15, 50, 0))).to eq 'a day' end + it 'returns "2 days" if difference is 2 days' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 11, 26, 16, 20, 0))).to eq '2 days' end + it 'returns "29 days" if difference is just shy of 29.5 days' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 12, 24, 4, 19, 59.9))).to eq '29 days' end + it 'returns "a month" if difference is 29.5 days' do expect(@test.send(:distance_of_time_in_words, Time.utc(2011, 12, 24, 4, 20, 0))).to eq 'a month' end + it 'returns "2 months" if difference is 2 months' do expect(@test.send(:distance_of_time_in_words, Time.utc(2012, 1, 24, 16, 20, 0))).to eq '2 months' end + it 'returns "11 months" if difference is just shy of 11.5 months' do expect(@test.send(:distance_of_time_in_words, Time.utc(2012, 11, 8, 11, 19, 59.9))).to eq '11 months' end + it 'returns "a year" if difference is 11.5 months' do expect(@test.send(:distance_of_time_in_words, Time.utc(2012, 11, 8, 11, 20, 0))).to eq 'a year' end + it 'returns "2 years" if difference is 2 years' do expect(@test.send(:distance_of_time_in_words, Time.utc(2013, 11, 24, 16, 20, 0))).to eq '2 years' end @@ -87,6 +104,7 @@ class Test; end it 'returns number with delimiter' do expect(@test.send(:number_with_delimiter, 1_234_567_890)).to eq '1,234,567,890' end + context 'with custom delimiter' do it 'returns number with custom delimiter' do expect(@test.send(:number_with_delimiter, 1_234_567_890, '.')).to eq '1.234.567.890'