Added v 0.2.3 snapshot.
[twitter4r-core.git] / test / sanity_test.rb
blobd176a580bb71776bc920e2ccd67f1de3522caa6a
1 #!/usr/bin/env ruby
3 require('twitter')
4 require('twitter/console')
6 version = Twitter::Version.to_version
7 puts "Sanity testing #{version}"
8 config_file = File.join(File.dirname(__FILE__), '..', 'config', 'twitter.yml')
9 twitter = Twitter::Client.from_config(config_file)
11 def expect(n, m, message = 'A potential error')
12         puts "WARNING: #{message}:\n\t => #{m} instead of #{n}" unless n.eql?(m)
13 end
15 puts "Public timeline sanity check"
16 timeline = twitter.timeline_for(:public)
17 count = timeline.size
18 expect 20, count, "Retrieved the last #{count} statuses from the public timeline"
20 sleep(5)
21 puts "Friends timeline sanity check"
22 timeline = twitter.timeline_for(:friends)
23 count = timeline.size
24 expect 20, count, "Retrieved the last #{count} statuses from all my friends' timeline"
26 sleep(5)
27 puts "User timeline sanity check"
28 timeline = twitter.timeline_for(:user, 
29         :id => 'mbbx6spp', 
30         :count => 5)
31 count = timeline.size
32 expect 5, count, "Retrieved the last #{count} statuses from one friend"
34 sleep(5)
35 puts "User lookup sanity check"
36 screen_name = 'mbbx6spp'
37 user = twitter.user(screen_name)
38 expect screen_name, user.screen_name, 'Retrieved a different user'
40 sleep(5)
41 puts "User#friends sanity check"
42 friends = twitter.user(screen_name, :friends)
43 expect Array, friends.class, 
44         'Did not retrieve an Array of users for #user(..., :friends)'
46 sleep(5)
47 puts "My user info sanity check"
48 followers = twitter.my(:info).followers
49 expect Array, followers.class, 
50         'Did not retrieve an Array of users for #my(:followers)'
52 sleep(5)
53 puts "Status posting sanity check"
54 posted_status = twitter.status(:post, "Testing Twitter4R v#{version} - http://twitter4r.rubyforge.org")
55 timeline = twitter.timeline_for(:me, :count => 1)
56 expect Twitter::Status, posted_status.class, 'Did not return newly posted status'
57 expect 1, timeline.size, 'Did not retrieve only last status'
58 expect Array, timeline.class, 'Did not retrieve an Array'
59 expect timeline[0], posted_status, 'Did not successfully post new status'
61 sleep(5)
62 puts "Status retrieval sanity check"
63 status = twitter.status(:get, posted_status)
64 expect posted_status, status, 'Did not get proper status'
66 sleep(5)
67 puts "Status deletion sanity check"
68 deleted_status = twitter.status(:delete, posted_status.id)
69 expect posted_status, deleted_status, 'Did not delete same status'
71 sleep(5)
72 puts "Direct messaging sanity check"
73 text = 'This is a test direct message for sanity test script purposes'
74 message = twitter.message(:post, text, user)
75 expect text, message.text, 
76         'Did not post expected text'
77 expect user.screen_name, message.recipient.screen_name, 
78         'Did not post to expected recipient'