Added v 0.3.1 snapshot.
[twitter4r-core.git] / scripts / testsanity.rb
blobc9b8f0d702e400eacdc41f5e479b641553778148
1 #!/usr/bin/env ruby
3 require('rubygems')
4 require('twitter')
5 require('twitter/console')
7 version = Twitter::Version.to_version
8 puts "Sanity testing #{version}"
9 config_file = File.join(File.dirname(__FILE__), '..', 'config', 'twitter.yml')
10 twitter = Twitter::Client.from_config(config_file)
12 def expect(n, m, message = 'A potential error')
13         puts "WARNING: #{message}:\n\t => #{m} instead of #{n}" unless n.eql?(m)
14 end
16 puts "Public timeline sanity check"
17 timeline = twitter.timeline_for(:public)
18 count = timeline.size
19 expect 20, count, "Retrieved the last #{count} statuses from the public timeline"
21 sleep(5)
22 puts "Friends timeline sanity check"
23 timeline = twitter.timeline_for(:friends)
24 count = timeline.size
25 expect 20, count, "Retrieved the last #{count} statuses from all my friends' timeline"
27 sleep(5)
28 puts "User timeline sanity check"
29 timeline = twitter.timeline_for(:user, 
30         :id => 'mbbx6spp', 
31         :count => 5)
32 count = timeline.size
33 expect 5, count, "Retrieved the last #{count} statuses from one friend"
35 sleep(5)
36 puts "User lookup sanity check"
37 screen_name = 'mbbx6spp'
38 user = twitter.user(screen_name)
39 expect screen_name, user.screen_name, 'Retrieved a different user'
41 sleep(5)
42 puts "User#friends sanity check"
43 friends = twitter.user(screen_name, :friends)
44 expect Array, friends.class, 
45         'Did not retrieve an Array of users for #user(..., :friends)'
47 sleep(5)
48 puts "My user info sanity check"
49 followers = twitter.my(:info).followers
50 expect Array, followers.class, 
51         'Did not retrieve an Array of users for #my(:followers)'
53 sleep(5)
54 puts "Status posting sanity check"
55 posted_status = twitter.status(:post, "Testing Twitter4R v#{version} - http://twitter4r.rubyforge.org")
56 timeline = twitter.timeline_for(:me, :count => 1)
57 expect Twitter::Status, posted_status.class, 'Did not return newly posted status'
58 expect 1, timeline.size, 'Did not retrieve only last status'
59 expect Array, timeline.class, 'Did not retrieve an Array'
60 expect timeline[0], posted_status, 'Did not successfully post new status'
62 sleep(5)
63 puts "Status retrieval sanity check"
64 status = twitter.status(:get, posted_status)
65 expect posted_status, status, 'Did not get proper status'
67 sleep(5)
68 puts "Status deletion sanity check"
69 deleted_status = twitter.status(:delete, posted_status.id)
70 expect posted_status, deleted_status, 'Did not delete same status'
72 sleep(5)
73 puts "Direct messaging sanity check"
74 text = 'This is a test direct message for sanity test script purposes'
75 message = twitter.message(:post, text, user)
76 expect text, message.text, 
77         'Did not post expected text'
78 expect user.screen_name, message.recipient.screen_name, 
79         'Did not post to expected recipient'
81 sleep(5)
82 puts "Favorites sanity check"
83 favorites = twitter.favorites
84 expect 0, favorites.size, 'Did not receive expected number of favorites'
86 sleep(5)
87 puts "Add favorite sanity check"
88 status_id = 381975342
89 status = twitter.favorite(:add, status_id)
90 favorites = twitter.favorites
91 expect 1, favorites.size, 'Did not add favorite'
92 expect status_id, status.id, 'Did not add correct favorite'
94 sleep(5)
95 puts "Remove favorite sanity check"
96 status = twitter.favorite(:remove, status_id)
97 favorites = twitter.favorites
98 expect 0, favorites.size, 'Did not remove favorite'
99 expect status_id, status.id, 'Did not remove correct favorite'