Skip to content

Instantly share code, notes, and snippets.

@mikesutton
Created February 4, 2011 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikesutton/811143 to your computer and use it in GitHub Desktop.
Save mikesutton/811143 to your computer and use it in GitHub Desktop.
the error:
Failure/Error: client = twitterController.sign_in_as_tagoid
WebMock::NetConnectNotAllowedError:
Real HTTP connections are disabled. Unregistered request: GET https://api.twitter.com/1/account/verify_credentials.json with headers {'Accept'=>'application/json', 'Authorization'=>'OAuth oauth_consumer_key="P0O33Z4p4o0XltMlcPZ3A", oauth_nonce="962c77e088b7427895f0628fea5990f7", oauth_signature="1k%2BFVLF%2BqFlogPwNgtwD7xctJA0%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1296828033", oauth_token="14980953-MbJv9wiK8fjZtvYClI7Kyt778R0JurPIxuIOyiQFV", oauth_version="1.0"', 'User-Agent'=>'Twitter Ruby Gem 1.1.1'}
You can stub this request with the following snippet:
stub_request(:get, "https://api.twitter.com/1/account/verify_credentials.json").
with(:headers => {'Accept'=>'application/json', 'Authorization'=>'OAuth oauth_consumer_key="P0O33Z4p4o0XltMlcPZ3A", oauth_nonce="962c77e088b7427895f0628fea5990f7", oauth_signature="1k%2BFVLF%2BqFlogPwNgtwD7xctJA0%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1296828033", oauth_token="14980953-MbJv9wiK8fjZtvYClI7Kyt778R0JurPIxuIOyiQFV", oauth_version="1.0"', 'User-Agent'=>'Twitter Ruby Gem 1.1.1'}).
to_return(:status => 200, :body => "", :headers => {})
My code:
verification_data = File.open("#{Rails.root}/features/fixtures/verify_credentials.json", 'rb') { |file| file.read }
stub_request(:get, "https://api.twitter.com/1/account/verify_credentials.json").
with(:headers => {'Accept'=>'application/json', 'Authorization'=>'OAuth oauth_consumer_key="P0O33Z4p4o0XltMlcPZ3A", oauth_nonce="8829efab5e19b74f6a49e7ad8ad49a86", oauth_signature="jFkvoEQSbIT5lumj%2Bqq00jndAhc%3D", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1296557983", oauth_token="14980953-MbJv9wiK8fjZtvYClI7Kyt778R0JurPIxuIOyiQFV", oauth_version="1.0"', 'User-Agent'=>'Twitter Ruby Gem 1.1.1'}).
to_return(:status => 200, :body => verification_data, :headers => {})
@bblimke
Copy link

bblimke commented Feb 4, 2011

oauth_signature is different

@mikesutton
Copy link
Author

and it changes it time! OK - great thanks for spotting that. Sorry to have poked into you day.

Otherwise I love Webmock!

@mikesutton
Copy link
Author

i mean it changes every call - will sort out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment