Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added tests to ensure correct error handling for unauthenticated methods
  • Loading branch information
sferik committed Mar 24, 2010
1 parent 7f2272c commit 4de5c92
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/fixtures/not_found.json
@@ -0,0 +1 @@
{"error":"No status found with that ID.","request":"/1/statuses/show/1.json"}
1 change: 1 addition & 0 deletions test/fixtures/unauthorized.json
@@ -0,0 +1 @@
{"error":"Not authorized","request":"/1/statuses/user_timeline/sferik.json"}
27 changes: 27 additions & 0 deletions test/twitter_test.rb
Expand Up @@ -24,12 +24,25 @@ class TwitterTest < Test::Unit::TestCase
status.text.should == 'Eating some oatmeal and butterscotch cookies with a cold glass of milk for breakfast. Tasty!'
end

should "raise NotFound for unauthenticated calls to get a deleted or nonexistent status" do
stub_get('http://api.twitter.com:80/1/statuses/show/1.json', 'not_found.json', 404)
lambda {
Twitter.status(1)
}.should raise_error(Twitter::NotFound)
end

should "have a timeline method for unauthenticated calls to get a user's timeline" do
stub_get('http://api.twitter.com:80/1/statuses/user_timeline/jnunemaker.json', 'user_timeline.json')
statuses = Twitter.timeline('jnunemaker')
statuses.first.id.should == 1445986256
statuses.first.user.screen_name.should == 'jnunemaker'
end

should "raise Unauthorized for unauthenticated calls to get a protected user's timeline" do
stub_get('http://api.twitter.com:80/1/statuses/user_timeline/protected.json', 'unauthorized.json', 401)
lambda {
Twitter.timeline('protected')
}.should raise_error(Twitter::Unauthorized)
end

should "have friend_ids method" do
Expand All @@ -38,12 +51,26 @@ class TwitterTest < Test::Unit::TestCase
ids.size.should == 161
end

should "raise Unauthorized for unauthenticated calls to get a protected user's friend_ids" do
stub_get('http://api.twitter.com:80/1/friends/ids/protected.json', 'unauthorized.json', 401)
lambda {
Twitter.friend_ids('protected')
}.should raise_error(Twitter::Unauthorized)
end

should "have follower_ids method" do
stub_get('http://api.twitter.com:80/1/followers/ids/jnunemaker.json', 'follower_ids.json')
ids = Twitter.follower_ids('jnunemaker')
ids.size.should == 1252
end

should "raise Unauthorized for unauthenticated calls to get a protected user's follower_ids" do
stub_get('http://api.twitter.com:80/1/followers/ids/protected.json', 'unauthorized.json', 401)
lambda {
Twitter.follower_ids('protected')
}.should raise_error(Twitter::Unauthorized)
end

context "when using lists" do

should "be able to view list timeline" do
Expand Down

0 comments on commit 4de5c92

Please sign in to comment.