forked from zipmark/rspec_api_documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcombined_text.feature
149 lines (115 loc) · 3.59 KB
/
combined_text.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
Feature: Combined text
In order to serve the docs from my API
As Zipmark
I want to generate text files for each of my resources containing their combined docs
Background:
Given a file named "app.rb" with:
"""
class App
def self.call(env)
request = Rack::Request.new(env)
response = Rack::Response.new
response["Content-Type"] = "text/plain"
response.write("Hello, #{request.params["target"]}!")
response.finish
end
end
"""
And a file named "app_spec.rb" with:
"""
require "rspec_api_documentation"
require "rspec_api_documentation/dsl"
RspecApiDocumentation.configure do |config|
config.app = App
config.format = :combined_text
end
resource "Greetings" do
get "/greetings" 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
example "Greeting your favorite developers of your favorite gem" do
do_request :target => "Sam & Eric"
expect(response_headers["Content-Type"]).to eq("text/plain")
expect(status).to eq(200)
expect(response_body).to eq('Hello, Sam & Eric!')
end
example "Multiple Requests" do
do_request :target => "Sam"
do_request :target => "Eric"
end
end
end
"""
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter`
Scenario: Output helpful progress to the console
Then the output should contain:
"""
Generating API Docs
Greetings
GET /greetings
* Greeting your favorite gem
* Greeting your favorite developers of your favorite gem
"""
And the output should contain "3 examples, 0 failures"
And the exit status should be 0
Scenario: File should look like we expect
Then the file "doc/api/greetings/index.txt" should contain exactly:
"""
Greeting your favorite gem
--------------------------
Parameters:
* target - The thing you want to greet
Request:
GET /greetings?target=rspec_api_documentation
Cookie:
Host: example.org
target=rspec_api_documentation
Response:
Status: 200 OK
Content-Length: 31
Content-Type: text/plain
Hello, rspec_api_documentation!
Greeting your favorite developers of your favorite gem
------------------------------------------------------
Parameters:
* target - The thing you want to greet
Request:
GET /greetings?target=Sam+%26+Eric
Cookie:
Host: example.org
target=Sam & Eric
Response:
Status: 200 OK
Content-Length: 18
Content-Type: text/plain
Hello, Sam & Eric!
Multiple Requests
-----------------
Parameters:
* target - The thing you want to greet
Request:
GET /greetings?target=Sam
Cookie:
Host: example.org
target=Sam
Response:
Status: 200 OK
Content-Length: 11
Content-Type: text/plain
Hello, Sam!
Request:
GET /greetings?target=Eric
Cookie:
Host: example.org
target=Eric
Response:
Status: 200 OK
Content-Length: 12
Content-Type: text/plain
Hello, Eric!
"""