forked from zipmark/rspec_api_documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoauth2_mac_client.feature
131 lines (106 loc) · 4.42 KB
/
oauth2_mac_client.feature
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
Feature: Use OAuth2 MAC client as a test client
Background:
Given a file named "app_spec.rb" with:
"""
require "rspec_api_documentation"
require "rspec_api_documentation/dsl"
require "rack/builder"
RspecApiDocumentation.configure do |config|
config.app = Rack::Builder.new do
map "/oauth2/token" do
app = lambda do |env|
headers = {"Pragma"=>"no-cache", "Content-Type"=>"application/json", "Content-Length"=>"274", "Cache-Control"=>"no-store"}
body = ["{\"mac_algorithm\":\"hmac-sha-256\",\"expires_in\":29,\"access_token\":\"HfIBIMe/hxNKSMogD33OJmLN+i9x3d2iM7WLzrN1RQvINOFz+QT8hiMiY+avbp2mc8IpzrxoupHyy0DeKuB05Q==\",\"token_type\":\"mac\",\"mac_key\":\"jb59zUztvDIC0AeaNZz+BptWvmFd4C41JyZS1DfWqKCkZTErxSMfkdjkePUcpE9/joqFt0ELyV/oIsFAf0V1ew==\"}"]
[200, headers, body]
end
run app
end
map "/" do
app = lambda do |env|
if env["HTTP_AUTHORIZATION"].blank?
return [401, {"Content-Type" => "text/plain"}, [""]]
end
request = Rack::Request.new(env)
response = Rack::Response.new
response["Content-Type"] = "text/plain"
response.write("hello #{request.params["target"]}")
response.finish
end
run app
end
map "/multiple" do
app = lambda do |env|
if env["HTTP_AUTHORIZATION"].blank?
return [401, {"Content-Type" => "text/plain"}, [""]]
end
request = Rack::Request.new(env)
response = Rack::Response.new
response["Content-Type"] = "text/plain"
response.write("hello #{request.params["targets"].join(", ")}")
response.finish
end
run app
end
map "/multiple_nested" do
app = lambda do |env|
if env["HTTP_AUTHORIZATION"].blank?
return [401, {"Content-Type" => "text/plain"}, [""]]
end
request = Rack::Request.new(env)
response = Rack::Response.new
response["Content-Type"] = "text/plain"
response.write("hello #{request.params["targets"].sort.map {|company, products| company.to_s + ' with ' + products.join(' and ')}.join(", ")}")
response.finish
end
run app
end
end
end
resource "Greetings" do
let(:client) { RspecApiDocumentation::OAuth2MACClient.new(self, {:identifier => "1", :secret => "secret"}) }
get "/" do
parameter :target, "The thing you want to greet"
example "Greeting your favorite gem" do
do_request :target => "rspec_api_documentation"
expect(response_headers["Content-Type"]).to eq("text/plain")
expect(status).to eq(200)
expect(response_body).to eq('hello rspec_api_documentation')
end
end
get "/multiple" do
parameter :targets, "The people you want to greet"
let(:targets) { ["eric", "sam"] }
example "Greeting your favorite people" do
do_request
expect(response_headers["Content-Type"]).to eq("text/plain")
expect(status).to eq(200)
expect(response_body).to eq("hello eric, sam")
end
end
get "/multiple_nested" do
parameter :targets, "The companies you want to greet"
let(:targets) { { "apple" => ['mac', 'ios'], "google" => ['search', 'mail']} }
example "Greeting your favorite companies" do
do_request
expect(response_headers["Content-Type"]).to eq("text/plain")
expect(status).to eq(200)
expect(response_body).to eq("hello apple with mac and ios, google with search and mail")
end
end
end
"""
When I run `rspec app_spec.rb --format RspecApiDocumentation::ApiFormatter`
Scenario: Output should contain
Then the output should contain:
"""
Generating API Docs
Greetings
GET /
* Greeting your favorite gem
GET /multiple
* Greeting your favorite people
GET /multiple_nested
* Greeting your favorite companies
"""
And the output should contain "3 examples, 0 failures"
And the exit status should be 0