-
Notifications
You must be signed in to change notification settings - Fork 169
Expand file tree
/
Copy pathrequest_spec.rb
More file actions
87 lines (74 loc) · 2.77 KB
/
request_spec.rb
File metadata and controls
87 lines (74 loc) · 2.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
require 'spec_helper'
require 'bitbucket_rest_api/request'
describe BitBucket::Request do
let(:fake_api) do
Class.new do
include BitBucket::Request
def connection(*args)
Faraday.new(:url => 'https://api.bitbucket.org')
end
def new_access_token
"12345"
end
end
end
describe "request" do
it "raises an ArgumentError if an unsupported HTTP verb is used" do
expect { fake_api.new.request(:i_am_a_teapot, {}, '/') }.to raise_error(ArgumentError)
end
context "with a connection" do
it "supports get" do
stub_request(:get, "https://api.bitbucket.org/1.0/endpoint").
with(:headers => {
'Accept' => '*/*',
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization' => 'Bearer 12345',
'User-Agent' => "Faraday v#{Faraday::VERSION}"
})
fake_api.new.request(:get, '/1.0/endpoint', {}, {})
end
it "supports put" do
stub_request(:put, "https://api.bitbucket.org/1.0/endpoint").
with(:body => "{\"data\":{\"key\":\"value\"}}",
:headers => {
'Accept' => '*/*',
'Content-Type'=>'application/x-www-form-urlencoded',
'Authorization' => 'Bearer 12345',
'User-Agent' => "Faraday v#{Faraday::VERSION}"
})
fake_api.new.request(:put, '/1.0/endpoint', { 'data' => { 'key' => 'value'} }, {})
end
it "supports patch" do
stub_request(:patch, "https://api.bitbucket.org/1.0/endpoint").
with(:body => "{\"data\":{\"key\":\"value\"}}",
:headers => {
'Accept' => '*/*',
'Content-Type'=>'application/x-www-form-urlencoded',
'Authorization' => 'Bearer 12345',
'User-Agent' => "Faraday v#{Faraday::VERSION}"
})
fake_api.new.request(:patch, '/1.0/endpoint', { 'data' => { 'key' => 'value'} }, {})
end
it "supports delete" do
stub_request(:delete, "https://api.bitbucket.org/1.0/endpoint").
with(:headers => {
'Accept' => '*/*',
'Authorization' => 'Bearer 12345',
'User-Agent' => "Faraday v#{Faraday::VERSION}"
})
fake_api.new.request(:delete, '/1.0/endpoint', {}, {})
end
it "supports post" do
stub_request(:post, "https://api.bitbucket.org/1.0/endpoint").
with(:body => "{\"data\":{\"key\":\"value\"}}",
:headers => {
'Accept' => '*/*',
'Content-Type'=>'application/x-www-form-urlencoded',
'Authorization' => 'Bearer 12345',
'User-Agent' => "Faraday v#{Faraday::VERSION}"
})
fake_api.new.request(:post, '/1.0/endpoint', { 'data' => { 'key' => 'value'} }, {})
end
end
end
end