-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhttp_mock_test_spec.rb
More file actions
24 lines (19 loc) · 945 Bytes
/
http_mock_test_spec.rb
File metadata and controls
24 lines (19 loc) · 945 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
require "./http_mock_test"
require 'webmock/rspec'
describe TwitterBearerTokens do
it do
stub_request(:post, "https://api.twitter.com/oauth2/token").
with(:body => "grant_type=client_credentials",
:headers => {'Authorization'=>"Basic #{Base64.strict_encode64("AAA:BBB")}"}).
to_return(:status => 200, :body => JSON.dump(access_token: 'this is the new token'))
result = TwitterBearerTokens.getBearerToken(conkey: 'AAA', consec: 'BBB')
expect(result).to eq('this is the new token')
end
it do
stub_request(:post, "https://api.twitter.com/oauth2/token").
with(:body => "grant_type=client_credentials",
:headers => {'Authorization'=>"Basic #{Base64.strict_encode64("AAA:BBB")}"}).
to_return(:status => 500)
expect { TwitterBearerTokens.getBearerToken(conkey: 'AAA', consec: 'BBB') }.to raise_error('There was a problem with the Twitter server')
end
end