Skip to content

Instantly share code, notes, and snippets.

@jonhoman
Created March 21, 2011 00:17
Show Gist options
  • Save jonhoman/878820 to your computer and use it in GitHub Desktop.
Save jonhoman/878820 to your computer and use it in GitHub Desktop.
Hand-rolled Twitter OAuth Stubs
describe "GET 'connect'" do
before do
stub_oauth_request_token!
end
it "should redirect to twitter authorization url" do
get 'connect'
session[:request_token].should == 't'
session[:request_token_secret].should == 's'
response.location.should =~ /api.twitter.com/
end
end
describe "GET 'callback'" do
before do
stub_oauth_access_token!
end
it "should authenticate with twitter" do
get :callback, :oauth_verifier => 'some_key', :handle => 'some_handle'
response.should be_redirect
end
end
def stub_oauth_request_token!
stub_request(:post, "https://api.twitter.com/oauth/request_token")
.to_return(:body => "oauth_token=t&oauth_token_secret=s")
end
def stub_oauth_access_token!
stub_request(:post, "https://api.twitter.com/oauth/access_token")
.to_return(:body => "oauth_token=at&oauth_token_secret=as&screen_name=sn")
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment