diff --git a/test/fixtures/not_found.json b/test/fixtures/not_found.json new file mode 100644 index 000000000..3c36d5964 --- /dev/null +++ b/test/fixtures/not_found.json @@ -0,0 +1 @@ +{"error":"No status found with that ID.","request":"/1/statuses/show/1.json"} \ No newline at end of file diff --git a/test/fixtures/unauthorized.json b/test/fixtures/unauthorized.json new file mode 100644 index 000000000..614a485b3 --- /dev/null +++ b/test/fixtures/unauthorized.json @@ -0,0 +1 @@ +{"error":"Not authorized","request":"/1/statuses/user_timeline/sferik.json"} \ No newline at end of file diff --git a/test/twitter_test.rb b/test/twitter_test.rb index 1d586490d..b7c044b96 100644 --- a/test/twitter_test.rb +++ b/test/twitter_test.rb @@ -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 @@ -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