fix specs

Andrew Cantino 9 ans auparavant
Parent
Commettre
70dd8fee33
1 fichiers modifiés avec 10 ajouts et 11 suppressions
  1. 10 11
      spec/models/agents/twitter_stream_agent_spec.rb

+ 10 - 11
spec/models/agents/twitter_stream_agent_spec.rb

@@ -221,20 +221,20 @@ describe Agents::TwitterStreamAgent do
221 221
       context "callback handling" do
222 222
         it "logs error messages" do
223 223
           stub_without(:on_error).on_error.yields('woups')
224
-          mock(STDERR).puts(" --> Twitter error: woups <--")
224
+          mock(STDERR).puts(anything) { |text| expect(text).to match(/woups/) }
225 225
           @worker.send(:stream!, ['agent'], @agent)
226 226
         end
227 227
 
228 228
         it "stop when no data was received"do
229 229
           stub_without(:on_no_data).on_no_data.yields
230 230
           mock(@worker).restart!
231
-          mock(STDERR).puts(" --> Got no data for awhile; trying to reconnect.")
231
+          mock(STDERR).puts(anything)
232 232
           @worker.send(:stream!, ['agent'], @agent)
233 233
         end
234 234
 
235 235
         it "sleeps for 60 seconds on_max_reconnects" do
236 236
           stub_without(:on_max_reconnects).on_max_reconnects.yields
237
-          mock(STDERR).puts(" --> Oops, tried too many times! <--")
237
+          mock(STDERR).puts(anything)
238 238
           mock(@worker).sleep(60)
239 239
           mock(@worker).restart!
240 240
           @worker.send(:stream!, ['agent'], @agent)
@@ -251,22 +251,21 @@ describe Agents::TwitterStreamAgent do
251 251
 
252 252
     context "#handle_status" do
253 253
       it "skips retweets" do
254
-        mock.instance_of(IO).puts('Skipping retweet: retweet')
255
-        @worker.send(:handle_status, {'text' => 'retweet', 'retweeted_status' => {one: true}})
254
+        @worker.send(:handle_status, {'text' => 'retweet', 'retweeted_status' => {one: true}, 'id_str' => '123' })
255
+        expect(@worker.instance_variable_get(:'@recent_tweets')).not_to include('123')
256 256
       end
257 257
 
258 258
       it "deduplicates tweets" do
259
-        mock.instance_of(IO).puts("dup")
260
-        @worker.send(:handle_status, {'text' => 'dup', 'id_str' => 1})
261
-        mock.instance_of(IO).puts("Skipping duplicate tweet: dup")
262
-        @worker.send(:handle_status, {'text' => 'dup', 'id_str' => 1})
259
+        @worker.send(:handle_status, {'text' => 'dup', 'id_str' => '1'})
260
+        @worker.send(:handle_status, {'text' => 'dup', 'id_str' => '1'})
261
+        expect(@worker.instance_variable_get(:'@recent_tweets').select { |str| str == '1' }.length).to eq 1
263 262
       end
264 263
 
265 264
       it "calls the agent to process the tweet" do
266
-        stub.instance_of(IO).puts
267 265
         mock(@mock_agent).name { 'mock' }
268 266
         mock(@mock_agent).process_tweet('agent', {'text' => 'agent'})
269
-        @worker.send(:handle_status, {'text' => 'agent'})
267
+        @worker.send(:handle_status, {'text' => 'agent', 'id_str' => '123'})
268
+        expect(@worker.instance_variable_get(:'@recent_tweets')).to include('123')
270 269
       end
271 270
     end
272 271
   end