Skip to content

Commit fb3511e

Browse files
committed
Merge remote-tracking branch 'zipmark/master'
2 parents 1dbbce6 + c6a470b commit fb3511e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+854
-155
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

Gemfile.lock

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
PATH
22
remote: .
33
specs:
4-
rspec_api_documentation (4.7.0)
4+
rspec_api_documentation (4.9.0)
55
activesupport (>= 3.0.0)
6-
json (~> 1.4, >= 1.4.6)
76
mustache (~> 1.0, >= 0.99.4)
8-
rspec (~> 3.0, >= 3.0.0)
7+
rspec (~> 3.0)
98

109
GEM
1110
remote: http://rubygems.org/
@@ -76,7 +75,7 @@ GEM
7675
multi_json (1.11.2)
7776
multi_test (0.1.2)
7877
multipart-post (2.0.0)
79-
mustache (1.0.2)
78+
mustache (1.0.3)
8079
nokogiri (1.6.7.2)
8180
mini_portile2 (~> 2.0.0.rc2)
8281
pry (0.10.3)
@@ -158,4 +157,4 @@ DEPENDENCIES
158157
webmock (~> 1.7)
159158

160159
BUNDLED WITH
161-
1.11.2
160+
1.13.6

README.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Check out a [sample](http://rad-example.herokuapp.com).
1414

1515
Please see the wiki for latest [changes](https://github.com/zipmark/rspec_api_documentation/wiki/Changes).
1616

17+
## RSpec 3.5 Beta
18+
19+
Use the `rspec-3.5` branch until RSpec 3.5 is out of beta.
20+
1721
## Installation
1822

1923
Add rspec_api_documentation to your Gemfile
@@ -85,7 +89,7 @@ RspecApiDocumentation.configure do |config|
8589

8690
# An array of output format(s).
8791
# Possible values are :json, :html, :combined_text, :combined_json,
88-
# :json_iodocs, :textile, :markdown, :append_json
92+
# :json_iodocs, :textile, :markdown, :append_json, :slate
8993
config.format = [:html]
9094

9195
# Location of templates
@@ -369,6 +373,22 @@ resource "Orders" do
369373
end
370374
```
371375

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+
372392
#### header
373393

374394
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.
@@ -396,8 +416,12 @@ Special values:
396416

397417
* `:required => true` Will display a red '*' to show it's required
398418
* `:scope => :the_scope` Will scope parameters in the hash, scoping can be nested. See example
419+
* `:method => :method_name` Will use specified method as a parameter value
399420

400-
The value of scoped parameters can be set with both scoped (`let(:order_item_item_id)`) and unscoped (`let(:item_id)`) methods. It always searches for the scoped method first and falls back to the unscoped method.
421+
Retrieving of parameter value goes through several steps:
422+
1. if `method` option is defined and test case responds to this method then this method is used;
423+
2. if test case responds to scoped method then this method is used;
424+
3. overwise unscoped method is used.
401425

402426
```ruby
403427
resource "Orders" do
@@ -408,10 +432,13 @@ resource "Orders" do
408432
post "/orders" do
409433
parameter :name, "Order Name", :required => true, :scope => :order
410434
parameter :item, "Order items", :scope => :order
411-
parameter :item_id, "Item id", :scope => [:order, :item]
435+
parameter :item_id, "Item id", :scope => [:order, :item], method: :custom_item_id
412436

413-
let(:name) { "My Order" } # OR let(:order_name) { "My Order" }
414-
let(:item_id) { 1 } # OR let(:order_item_item_id) { 1 }
437+
let(:name) { "My Order" }
438+
# OR let(:order_name) { "My Order" }
439+
let(:item_id) { 1 }
440+
# OR let(:custom_item_id) { 1 }
441+
# OR let(:order_item_item_id) { 1 }
415442

416443
example "Creating an order" do
417444
params.should eq({

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: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ Feature: Generate HTML documentation from test examples
88
request = Rack::Request.new(env)
99
response = Rack::Response.new
1010
response["Content-Type"] = "application/json"
11-
response.write({ "hello" => request.params["target"] }.to_json)
11+
response.write({
12+
"hello" => request.params["target"],
13+
"more_greetings" => { "bonjour" => { "message" => "le monde" } }
14+
}.to_json)
1215
response.finish
1316
end
1417
end
@@ -31,14 +34,15 @@ Feature: Generate HTML documentation from test examples
3134
parameter :scoped, "This is a scoped variable", :scope => :scope
3235
parameter :sub, "This is scoped", :scope => [:scope, :further]
3336
34-
response_field :hello, "The greeted thing"
37+
response_field :hello, "The greeted thing"
38+
response_field :message, "Translated greeting", scope: [:more_greetings, :bonjour]
3539
3640
example "Greeting your favorite gem" do
3741
do_request :target => "rspec_api_documentation"
3842
39-
response_headers["Content-Type"].should eq("application/json")
40-
status.should eq(200)
41-
response_body.should eq('{"hello":"rspec_api_documentation"}')
43+
expect(response_headers["Content-Type"]).to eq("application/json")
44+
expect(status).to eq(200)
45+
expect(response_body).to eq('{"hello":"rspec_api_documentation","more_greetings":{"bonjour":{"message":"le monde"}}}')
4246
end
4347
end
4448
end
@@ -71,12 +75,13 @@ Feature: Generate HTML documentation from test examples
7175
| scope[scoped] | This is a scoped variable |
7276
| scope[further][sub] | This is scoped |
7377

74-
Scenario: Examle HTML documentation should include the response fields
78+
Scenario: Example HTML documentation should include the response fields
7579
When I open the index
7680
And I navigate to "Greeting your favorite gem"
7781
Then I should see the following response fields:
78-
| name | description |
79-
| hello | The greeted thing |
82+
| name | description |
83+
| hello | The greeted thing |
84+
| more_greetings[bonjour][message] | Translated greeting |
8085

8186
Scenario: Example HTML documentation includes the request information
8287
When I open the index
@@ -99,5 +104,5 @@ Feature: Generate HTML documentation from test examples
99104
| Content-Length | 35 |
100105
And I should see the following response body:
101106
"""
102-
{ "hello": "rspec_api_documentation" }
107+
{ "hello": "rspec_api_documentation", "more_greetings": { "bonjour": { "message": "le monde" } } }
103108
"""

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: 18 additions & 18 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
@@ -226,14 +229,11 @@ Feature: Generate Markdown documentation from test examples
226229
227230
### Parameters
228231
229-
Name : name *- required -*
230-
Description : Name of order
231-
232-
Name : amount *- required -*
233-
Description : Amount paid
234-
235-
Name : description
236-
Description : Some comments on the order
232+
| Name | Description | Required | Scope |
233+
|------|-------------|----------|-------|
234+
| name | Name of order | true | |
235+
| amount | Amount paid | true | |
236+
| description | Some comments on the order | false | |
237237
238238
### Request
239239

0 commit comments

Comments
 (0)