File: message_parser_spec.rb

package info (click to toggle)
ruby-twitter 7.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,856 kB
  • sloc: ruby: 10,919; makefile: 6
file content (52 lines) | stat: -rw-r--r-- 1,893 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
require 'helper'

describe Twitter::Streaming::MessageParser do
  subject do
    Twitter::Streaming::MessageParser
  end

  describe '.parse' do
    it 'returns a tweet if the data has an id' do
      data = {id: 1}
      object = subject.parse(data)
      expect(object).to be_a Twitter::Tweet
      expect(object.id).to eq(1)
    end
    it 'returns an event if the data has an event' do
      data = {event: 'favorite', source: {id: 1}, target: {id: 2}, target_object: {id: 1}}
      object = subject.parse(data)
      expect(object).to be_a Twitter::Streaming::Event
      expect(object.name).to eq(:favorite)
      expect(object.source).to be_a Twitter::User
      expect(object.source.id).to eq(1)
      expect(object.target).to be_a Twitter::User
      expect(object.target.id).to eq(2)
      expect(object.target_object).to be_a Twitter::Tweet
      expect(object.target_object.id).to eq(1)
    end
    it 'returns a direct message if the data has a direct_message' do
      data = {direct_message: {id: 1}}
      object = subject.parse(data)
      expect(object).to be_a Twitter::DirectMessage
      expect(object.id).to eq(1)
    end
    it 'returns a friend list if the data has friends' do
      data = {friends: [1]}
      object = subject.parse(data)
      expect(object).to be_a Twitter::Streaming::FriendList
      expect(object.first).to eq(1)
    end
    it 'returns a deleted tweet if the data has a deleted status' do
      data = {delete: {status: {id: 1}}}
      object = subject.parse(data)
      expect(object).to be_a Twitter::Streaming::DeletedTweet
      expect(object.id).to eq(1)
    end
    it 'returns a stall warning if the data has a warning' do
      data = {warning: {code: 'FALLING_BEHIND'}}
      object = subject.parse(data)
      expect(object).to be_a Twitter::Streaming::StallWarning
      expect(object.code).to eq('FALLING_BEHIND')
    end
  end
end