Skip to content

Commit 595a8a3

Browse files
authored
Merge pull request #269 from artcom/master
Another attempt at adding explanations to resources
2 parents fce1cd5 + 7a53848 commit 595a8a3

28 files changed

+141
-66
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
tmp
22
.rvmrc
33
.ruby-version
4+
.ruby-gemset
45
example/docs
56
example/public/docs
67
*.gem

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,22 @@ resource "Orders" do
373373
end
374374
```
375375

376+
A resource can also have an explanation.
377+
378+
```ruby
379+
resource "Orders" do
380+
explanation "Orders are top-level business objects. They can be created by a POST request"
381+
post "/orders" do
382+
example "Creating an order" do
383+
explanation "This method creates a new order."
384+
do_request
385+
# make assertions
386+
end
387+
end
388+
end
389+
```
390+
391+
376392
#### header
377393

378394
This method takes the header name and value. The value can be a string or a symbol. If it is a symbol it will `send` the symbol, allowing you to `let` header values.

features/combined_json.feature

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,25 @@ Feature: Combined text
2929
end
3030
3131
resource "Greetings" do
32+
explanation "Welcome to the party"
33+
3234
get "/greetings" do
3335
parameter :target, "The thing you want to greet"
3436
3537
example "Greeting your favorite gem" do
3638
do_request :target => "rspec_api_documentation"
3739
38-
response_headers["Content-Type"].should eq("text/plain")
39-
status.should eq(200)
40-
response_body.should eq('Hello, rspec_api_documentation!')
40+
expect(response_headers["Content-Type"]).to eq("text/plain")
41+
expect(status).to eq(200)
42+
expect(response_body).to eq('Hello, rspec_api_documentation!')
4143
end
4244
4345
example "Greeting your favorite developers of your favorite gem" do
4446
do_request :target => "Sam & Eric"
4547
46-
response_headers["Content-Type"].should eq("text/plain")
47-
status.should eq(200)
48-
response_body.should eq('Hello, Sam & Eric!')
48+
expect(response_headers["Content-Type"]).to eq("text/plain")
49+
expect(status).to eq(200)
50+
expect(response_body).to eq('Hello, Sam & Eric!')
4951
end
5052
end
5153
end
@@ -70,6 +72,7 @@ Feature: Combined text
7072
[
7173
{
7274
"resource": "Greetings",
75+
"resource_explanation": "Welcome to the party",
7376
"http_method": "GET",
7477
"route": "/greetings",
7578
"description": "Greeting your favorite gem",
@@ -106,6 +109,7 @@ Feature: Combined text
106109
},
107110
{
108111
"resource": "Greetings",
112+
"resource_explanation": "Welcome to the party",
109113
"http_method": "GET",
110114
"route": "/greetings",
111115
"description": "Greeting your favorite developers of your favorite gem",

features/combined_text.feature

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,17 @@ Feature: Combined text
3333
example "Greeting your favorite gem" do
3434
do_request :target => "rspec_api_documentation"
3535
36-
response_headers["Content-Type"].should eq("text/plain")
37-
status.should eq(200)
38-
response_body.should eq('Hello, rspec_api_documentation!')
36+
expect(response_headers["Content-Type"]).to eq("text/plain")
37+
expect(status).to eq(200)
38+
expect(response_body).to eq('Hello, rspec_api_documentation!')
3939
end
4040
4141
example "Greeting your favorite developers of your favorite gem" do
4242
do_request :target => "Sam & Eric"
4343
44-
response_headers["Content-Type"].should eq("text/plain")
45-
status.should eq(200)
46-
response_body.should eq('Hello, Sam & Eric!')
44+
expect(response_headers["Content-Type"]).to eq("text/plain")
45+
expect(status).to eq(200)
46+
expect(response_body).to eq('Hello, Sam & Eric!')
4747
end
4848
4949
example "Multiple Requests" do
@@ -145,6 +145,5 @@ Feature: Combined text
145145
Content-Type: text/plain
146146
147147
Hello, Eric!
148-
149148
"""
150149

features/curl.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Feature: cURL output
2626
2727
example "Getting Foo" do
2828
do_request
29-
response_body.should == "foo"
29+
expect(response_body).to eq("foo")
3030
end
3131
end
3232
end

features/headers.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Feature: Specifying request headers
2828
2929
example "Getting Foo" do
3030
do_request
31-
response_body.should == "foo"
31+
expect(response_body).to eq("foo")
3232
end
3333
end
3434
end

features/html_documentation.feature

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ Feature: Generate HTML documentation from test examples
3636
example "Greeting your favorite gem" do
3737
do_request :target => "rspec_api_documentation"
3838
39-
response_headers["Content-Type"].should eq("application/json")
40-
status.should eq(200)
41-
response_body.should eq('{"hello":"rspec_api_documentation"}')
39+
expect(response_headers["Content-Type"]).to eq("application/json")
40+
expect(status).to eq(200)
41+
expect(response_body).to eq('{"hello":"rspec_api_documentation"}')
4242
end
4343
end
4444
end

features/json_iodocs.feature

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,17 @@ Feature: Json Iodocs
3535
example "Greeting your favorite gem" do
3636
do_request :target => "rspec_api_documentation"
3737
38-
response_headers["Content-Type"].should eq("text/plain")
39-
status.should eq(200)
40-
response_body.should eq('Hello, rspec_api_documentation!')
38+
expect(response_headers["Content-Type"]).to eq("text/plain")
39+
expect(status).to eq(200)
40+
expect(response_body).to eq('Hello, rspec_api_documentation!')
4141
end
4242
4343
example "Greeting your favorite developers of your favorite gem" do
4444
do_request :target => "Sam & Eric"
4545
46-
response_headers["Content-Type"].should eq("text/plain")
47-
status.should eq(200)
48-
response_body.should eq('Hello, Sam & Eric!')
46+
expect(response_headers["Content-Type"]).to eq("text/plain")
47+
expect(status).to eq(200)
48+
expect(response_body).to eq('Hello, Sam & Eric!')
4949
end
5050
end
5151
end

features/markdown_documentation.feature

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ Feature: Generate Markdown documentation from test examples
5959
response_field :page, "Current page"
6060
6161
example_request 'Getting a list of orders' do
62-
status.should eq(200)
63-
response_body.should eq('{"page":1,"orders":[{"name":"Order 1","amount":9.99,"description":null},{"name":"Order 2","amount":100.0,"description":"A great order"}]}')
62+
expect(status).to eq(200)
63+
expect(response_body).to eq('{"page":1,"orders":[{"name":"Order 1","amount":9.99,"description":null},{"name":"Order 2","amount":100.0,"description":"A great order"}]}')
6464
end
6565
end
6666
6767
get '/orders/:id' do
6868
let(:id) { 1 }
6969
7070
example_request 'Getting a specific order' do
71-
status.should eq(200)
72-
response_body.should == '{"order":{"name":"Order 1","amount":100.0,"description":"A great order"}}'
71+
expect(status).to eq(200)
72+
expect(response_body).to eq('{"order":{"name":"Order 1","amount":100.0,"description":"A great order"}}')
7373
end
7474
end
7575
@@ -82,7 +82,7 @@ Feature: Generate Markdown documentation from test examples
8282
let(:amount) { 33.0 }
8383
8484
example_request 'Creating an order' do
85-
status.should == 201
85+
expect(status).to eq(201)
8686
end
8787
end
8888
@@ -95,24 +95,26 @@ Feature: Generate Markdown documentation from test examples
9595
let(:name) { "Updated name" }
9696
9797
example_request 'Updating an order' do
98-
status.should == 200
98+
expect(status).to eq(200)
9999
end
100100
end
101101
102102
delete "/orders/:id" do
103103
let(:id) { 1 }
104104
105105
example_request "Deleting an order" do
106-
status.should == 200
106+
expect(status).to eq(200)
107107
end
108108
end
109109
end
110110
111111
resource 'Help' do
112+
explanation 'Getting help'
113+
112114
get '/help' do
113115
example_request 'Getting welcome message' do
114-
status.should eq(200)
115-
response_body.should == 'Welcome Henry !'
116+
expect(status).to eq(200)
117+
expect(response_body).to eq('Welcome Henry !')
116118
end
117119
end
118120
@@ -149,6 +151,8 @@ Feature: Generate Markdown documentation from test examples
149151
150152
## Help
151153
154+
Getting help
155+
152156
* [Getting welcome message](help/getting_welcome_message.markdown)
153157
154158
## Orders
@@ -212,7 +216,6 @@ Feature: Generate Markdown documentation from test examples
212216
}
213217
]
214218
}</pre>
215-
216219
"""
217220

218221
Scenario: Example 'Creating an order' file should look like we expect

features/oauth2_mac_client.feature

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ Feature: Use OAuth2 MAC client as a test client
7777
example "Greeting your favorite gem" do
7878
do_request :target => "rspec_api_documentation"
7979
80-
response_headers["Content-Type"].should eq("text/plain")
81-
status.should eq(200)
82-
response_body.should eq('hello rspec_api_documentation')
80+
expect(response_headers["Content-Type"]).to eq("text/plain")
81+
expect(status).to eq(200)
82+
expect(response_body).to eq('hello rspec_api_documentation')
8383
end
8484
end
8585
@@ -91,9 +91,9 @@ Feature: Use OAuth2 MAC client as a test client
9191
example "Greeting your favorite people" do
9292
do_request
9393
94-
response_headers["Content-Type"].should eq("text/plain")
95-
status.should eq(200)
96-
response_body.should eq("hello eric, sam")
94+
expect(response_headers["Content-Type"]).to eq("text/plain")
95+
expect(status).to eq(200)
96+
expect(response_body).to eq("hello eric, sam")
9797
end
9898
end
9999
@@ -105,9 +105,9 @@ Feature: Use OAuth2 MAC client as a test client
105105
example "Greeting your favorite companies" do
106106
do_request
107107
108-
response_headers["Content-Type"].should eq("text/plain")
109-
status.should eq(200)
110-
response_body.should eq("hello apple with mac and ios, google with search and mail")
108+
expect(response_headers["Content-Type"]).to eq("text/plain")
109+
expect(status).to eq(200)
110+
expect(response_body).to eq("hello apple with mac and ios, google with search and mail")
111111
end
112112
end
113113

features/patch.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Feature: Example Request with PATCH
2424
resource "Example Request" do
2525
patch "/" do
2626
example_request "Trying out patch" do
27-
status.should eq(200)
27+
expect(status).to eq(200)
2828
end
2929
end
3030
end

features/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ See the wiki for additional setup. [Setting up RSpec API Documentation](https://
3030
get "/accounts" do
3131
example "Get a list of all accounts" do
3232
do_request
33-
last_response.status.should be_ok
33+
expect(last_response.status).to be_ok
3434
end
3535
end
3636

@@ -42,7 +42,7 @@ See the wiki for additional setup. [Setting up RSpec API Documentation](https://
4242

4343
example "Get an account", :document => :public do
4444
do_request
45-
last_response.status.should be_ok
45+
expect(last_response.status).to be_ok
4646
end
4747
end
4848
end

features/redefining_client.feature

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Feature: Redefining the client method
2323
2424
get "/" do
2525
example_request "Trying out get" do
26-
status.should eq(200)
26+
expect(status).to eq(200)
2727
end
2828
end
2929
end

features/textile_documentation.feature

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ Feature: Generate Textile documentation from test examples
5959
response_field :page, "Current page"
6060
6161
example_request 'Getting a list of orders' do
62-
status.should eq(200)
63-
response_body.should eq('{"page":1,"orders":[{"name":"Order 1","amount":9.99,"description":null},{"name":"Order 2","amount":100.0,"description":"A great order"}]}')
62+
expect(status).to eq(200)
63+
expect(response_body).to eq('{"page":1,"orders":[{"name":"Order 1","amount":9.99,"description":null},{"name":"Order 2","amount":100.0,"description":"A great order"}]}')
6464
end
6565
end
6666
6767
get '/orders/:id' do
6868
let(:id) { 1 }
6969
7070
example_request 'Getting a specific order' do
71-
status.should eq(200)
72-
response_body.should == '{"order":{"name":"Order 1","amount":100.0,"description":"A great order"}}'
71+
expect(status).to eq(200)
72+
expect(response_body).to eq('{"order":{"name":"Order 1","amount":100.0,"description":"A great order"}}')
7373
end
7474
end
7575
@@ -82,7 +82,7 @@ Feature: Generate Textile documentation from test examples
8282
let(:amount) { 33.0 }
8383
8484
example_request 'Creating an order' do
85-
status.should == 201
85+
expect(status).to eq(201)
8686
end
8787
end
8888
@@ -95,24 +95,26 @@ Feature: Generate Textile documentation from test examples
9595
let(:name) { "Updated name" }
9696
9797
example_request 'Updating an order' do
98-
status.should == 200
98+
expect(status).to eq(200)
9999
end
100100
end
101101
102102
delete "/orders/:id" do
103103
let(:id) { 1 }
104104
105105
example_request "Deleting an order" do
106-
status.should == 200
106+
expect(status).to eq(200)
107107
end
108108
end
109109
end
110110
111111
resource 'Help' do
112+
explanation 'Getting help'
113+
112114
get '/help' do
113115
example_request 'Getting welcome message' do
114-
status.should eq(200)
115-
response_body.should == 'Welcome Henry !'
116+
expect(status).to eq(200)
117+
expect(response_body).to eq('Welcome Henry !')
116118
end
117119
end
118120
@@ -149,6 +151,8 @@ Feature: Generate Textile documentation from test examples
149151
150152
h2. Help
151153
154+
Getting help
155+
152156
* "Getting welcome message":help/getting_welcome_message.textile
153157
154158
h2. Orders
@@ -160,7 +164,7 @@ Feature: Generate Textile documentation from test examples
160164
* "Updating an order":orders/updating_an_order.textile
161165
"""
162166

163-
Scenario: Example 'Getting al ist of orders' file should look like we expect
167+
Scenario: Example 'Getting a list of orders' file should look like we expect
164168
Then the file "doc/api/orders/getting_a_list_of_orders.textile" should contain exactly:
165169
"""
166170
h1. Orders API

0 commit comments

Comments
 (0)