Created
October 8, 2015 13:07
-
-
Save ceritium/52dee02775e913f10d96 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Feature: Document callbacks | |
Background: # features/callbacks.feature:3 | |
Given a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
RspecApiDocumentation.configure do |config| | |
config.app = lambda do | |
uri = URI.parse("http://example.net/callback") | |
Net::HTTP.start(uri.host, uri.port) do |http| | |
request = Net::HTTP::Post.new(uri.path) | |
request.body = '{"message":"Something interesting happened!"}' | |
request["Content-Type"] = "application/json" | |
request["User-Agent"] = "InterestingThingApp" | |
http.request request | |
end | |
[200, {}, []] | |
end | |
end | |
resource "Interesting Thing" do | |
callback "/interesting_thing" do | |
let(:callback_url) { "http://example.net/callback" } | |
trigger_callback do | |
app.call | |
end | |
example "Receiving a callback when interesting things happen" do | |
do_callback | |
expect(request_method).to eq("POST") | |
expect(request_headers["Content-Type"]).to eq("application/json") | |
expect(request_headers["User-Agent"]).to eq("InterestingThingApp") | |
expect(request_body).to eq('{"message":"Something interesting happened!"}') | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Scenario: Output helpful progress to the console # features/callbacks.feature:43 | |
Then the output should contain: # aruba-0.6.1/lib/aruba/cucumber.rb:156 | |
""" | |
Generating API Docs | |
Interesting Thing | |
/interesting_thing | |
* Receiving a callback when interesting things happen | |
""" | |
expected "Generating API Docs\n\nRandomized with seed 39954\n Interesting Thing\n /interesting_thing\n * Receiving a callback when interesting things happen\n\nFinished in 0.0058 seconds (files took 0.24679 seconds to load)\n1 example, 0 failures\n\nRandomized with seed 39954\n\n" to include "Generating API Docs\n Interesting Thing\n /interesting_thing\n * Receiving a callback when interesting things happen" | |
Diff: | |
@@ -1,2 +1,12 @@ | |
-Generating API Docs\n Interesting Thing\n /interesting_thing\n * Receiving a callback when interesting things happen | |
+Generating API Docs | |
+ | |
+Randomized with seed 39954 | |
+ Interesting Thing | |
+ /interesting_thing | |
+ * Receiving a callback when interesting things happen | |
+ | |
+Finished in 0.0058 seconds (files took 0.24679 seconds to load) | |
+1 example, 0 failures | |
+ | |
+Randomized with seed 39954 | |
(RSpec::Expectations::ExpectationNotMetError) | |
features/callbacks.feature:44:in `Then the output should contain:' | |
And the output should contain "1 example, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
Scenario: Create an index of all API examples, including all resources # features/callbacks.feature:54 | |
When I open the index # features/step_definitions/html_steps.rb:1 | |
Then I should see the following resources: # features/step_definitions/html_steps.rb:9 | |
| Interesting Thing | | |
Scenario: Example HTML documentation includes the request information # features/callbacks.feature:59 | |
When I open the index # features/step_definitions/html_steps.rb:1 | |
And I navigate to "Receiving a callback when interesting things happen" # features/step_definitions/html_steps.rb:5 | |
Then I should see the route is "POST /callback" # features/step_definitions/html_steps.rb:45 | |
And I should see the following request headers: # features/step_definitions/html_steps.rb:27 | |
| Content-Type | application/json | | |
| Accept | */* | | |
| User-Agent | InterestingThingApp | | |
And I should see the following request body: # features/step_definitions/html_steps.rb:61 | |
""" | |
{"message":"Something interesting happened!"} | |
""" | |
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: # features/combined_json.feature:6 | |
Given a file named "app.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
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: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
config.format = :combined_json | |
config.request_headers_to_include = %w[Host] | |
config.response_headers_to_include = %w[Content-Type] | |
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" | |
response_headers["Content-Type"].should eq("text/plain") | |
status.should eq(200) | |
response_body.should eq('Hello, rspec_api_documentation!') | |
end | |
example "Greeting your favorite developers of your favorite gem" do | |
do_request :target => "Sam & Eric" | |
response_headers["Content-Type"].should eq("text/plain") | |
status.should eq(200) | |
response_body.should eq('Hello, Sam & Eric!') | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Scenario: Output helpful progress to the console # features/combined_json.feature:55 | |
Then the output should contain: # aruba-0.6.1/lib/aruba/cucumber.rb:156 | |
""" | |
Generating API Docs | |
Greetings | |
GET /greetings | |
* Greeting your favorite gem | |
* Greeting your favorite developers of your favorite gem | |
""" | |
expected "Generating API Docs\n\nRandomized with seed 22270\n Greetings\n GET /greetings\n * Greeting your favorite gem\n * Greeting your favorite developers of your favorite gem\n\n1 deprecation warning total\n\nFinished in 0.02445 seconds (files took 0.13992 seconds to load)\n2 examples, 0 failures\n\nRandomized with seed 22270\n\n\nDeprecation Warnings:\n\nUsing `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:18:in `block (3 levels) in <top (required)>'.\n\n\nIf you need more of the backtrace for any of these deprecations to\nidentify where to make the necessary changes, you can configure\n`config.raise_errors_for_deprecations!`, and it will turn the\ndeprecation warnings into errors, giving you the full backtrace.\n" to include "Generating API Docs\n Greetings\n GET /greetings\n * Greeting your favorite gem\n * Greeting your favorite developers of your favorite gem" | |
Diff: | |
@@ -1,2 +1,26 @@ | |
-Generating API Docs\n Greetings\n GET /greetings\n * Greeting your favorite gem\n * Greeting your favorite developers of your favorite gem | |
+Generating API Docs | |
+ | |
+Randomized with seed 22270 | |
+ Greetings | |
+ GET /greetings | |
+ * Greeting your favorite gem | |
+ * Greeting your favorite developers of your favorite gem | |
+ | |
+1 deprecation warning total | |
+ | |
+Finished in 0.02445 seconds (files took 0.13992 seconds to load) | |
+2 examples, 0 failures | |
+ | |
+Randomized with seed 22270 | |
+ | |
+ | |
+Deprecation Warnings: | |
+ | |
+Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:18:in `block (3 levels) in <top (required)>'. | |
+ | |
+ | |
+If you need more of the backtrace for any of these deprecations to | |
+identify where to make the necessary changes, you can configure | |
+`config.raise_errors_for_deprecations!`, and it will turn the | |
+deprecation warnings into errors, giving you the full backtrace. | |
(RSpec::Expectations::ExpectationNotMetError) | |
features/combined_json.feature:56:in `Then the output should contain:' | |
And the output should contain "2 examples, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
Scenario: File should look like we expect # features/combined_json.feature:67 | |
Then the file "doc/api/combined.json" should contain JSON exactly like: # features/step_definitions/json_steps.rb:1 | |
""" | |
[ | |
{ | |
"resource": "Greetings", | |
"http_method": "GET", | |
"route": "/greetings", | |
"description": "Greeting your favorite gem", | |
"explanation": null, | |
"parameters": [ | |
{ | |
"name": "target", | |
"description": "The thing you want to greet" | |
} | |
], | |
"response_fields": [], | |
"requests": [ | |
{ | |
"request_method": "GET", | |
"request_path": "/greetings?target=rspec_api_documentation", | |
"request_body": null, | |
"request_headers": { | |
"Host": "example.org" | |
}, | |
"request_query_parameters": { | |
"target": "rspec_api_documentation" | |
}, | |
"request_content_type": null, | |
"response_status": 200, | |
"response_status_text": "OK", | |
"response_body": "Hello, rspec_api_documentation!", | |
"response_headers": { | |
"Content-Type": "text/plain" | |
}, | |
"response_content_type": "text/plain", | |
"curl": null | |
} | |
] | |
}, | |
{ | |
"resource": "Greetings", | |
"http_method": "GET", | |
"route": "/greetings", | |
"description": "Greeting your favorite developers of your favorite gem", | |
"explanation": null, | |
"parameters": [ | |
{ | |
"name": "target", | |
"description": "The thing you want to greet" | |
} | |
], | |
"response_fields": [], | |
"requests": [ | |
{ | |
"request_method": "GET", | |
"request_path": "/greetings?target=Sam+%26+Eric", | |
"request_body": null, | |
"request_headers": { | |
"Host": "example.org" | |
}, | |
"request_query_parameters": { | |
"target": "Sam & Eric" | |
}, | |
"request_content_type": null, | |
"response_status": 200, | |
"response_status_text": "OK", | |
"response_body": "Hello, Sam & Eric!", | |
"response_headers": { | |
"Content-Type": "text/plain" | |
}, | |
"response_content_type": "text/plain", | |
"curl": null | |
} | |
] | |
} | |
] | |
""" | |
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: # features/combined_text.feature:6 | |
Given a file named "app.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
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: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
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" | |
response_headers["Content-Type"].should eq("text/plain") | |
status.should eq(200) | |
response_body.should eq('Hello, rspec_api_documentation!') | |
end | |
example "Greeting your favorite developers of your favorite gem" do | |
do_request :target => "Sam & Eric" | |
response_headers["Content-Type"].should eq("text/plain") | |
status.should eq(200) | |
response_body.should 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` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Scenario: Output helpful progress to the console # features/combined_text.feature:58 | |
Then the output should contain: # aruba-0.6.1/lib/aruba/cucumber.rb:156 | |
""" | |
Generating API Docs | |
Greetings | |
GET /greetings | |
* Greeting your favorite gem | |
* Greeting your favorite developers of your favorite gem | |
""" | |
expected "Generating API Docs\n\nRandomized with seed 5081\n Greetings\n GET /greetings\n * Greeting your favorite gem\n * Greeting your favorite developers of your favorite gem\n * Multiple Requests\n\n1 deprecation warning total\n\nFinished in 0.02478 seconds (files took 0.13947 seconds to load)\n3 examples, 0 failures\n\nRandomized with seed 5081\n\n\nDeprecation Warnings:\n\nUsing `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:16:in `block (3 levels) in <top (required)>'.\n\n\nIf you need more of the backtrace for any of these deprecations to\nidentify where to make the necessary changes, you can configure\n`config.raise_errors_for_deprecations!`, and it will turn the\ndeprecation warnings into errors, giving you the full backtrace.\n" to include "Generating API Docs\n Greetings\n GET /greetings\n * Greeting your favorite gem\n * Greeting your favorite developers of your favorite gem" | |
Diff: | |
@@ -1,2 +1,27 @@ | |
-Generating API Docs\n Greetings\n GET /greetings\n * Greeting your favorite gem\n * Greeting your favorite developers of your favorite gem | |
+Generating API Docs | |
+ | |
+Randomized with seed 5081 | |
+ Greetings | |
+ GET /greetings | |
+ * Greeting your favorite gem | |
+ * Greeting your favorite developers of your favorite gem | |
+ * Multiple Requests | |
+ | |
+1 deprecation warning total | |
+ | |
+Finished in 0.02478 seconds (files took 0.13947 seconds to load) | |
+3 examples, 0 failures | |
+ | |
+Randomized with seed 5081 | |
+ | |
+ | |
+Deprecation Warnings: | |
+ | |
+Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:16:in `block (3 levels) in <top (required)>'. | |
+ | |
+ | |
+If you need more of the backtrace for any of these deprecations to | |
+identify where to make the necessary changes, you can configure | |
+`config.raise_errors_for_deprecations!`, and it will turn the | |
+deprecation warnings into errors, giving you the full backtrace. | |
(RSpec::Expectations::ExpectationNotMetError) | |
features/combined_text.feature:59:in `Then the output should contain:' | |
And the output should contain "3 examples, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
Scenario: File should look like we expect # features/combined_text.feature:70 | |
Then the file "doc/api/greetings/index.txt" should contain exactly: # aruba-0.6.1/lib/aruba/cucumber.rb:355 | |
""" | |
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! | |
""" | |
expected: "Greeting your favorite gem\n--------------------------\n\nParameters:\n * target - The thing you want to greet\n\nRequest:\n GET /greetings?target=rspec_api_documentation\n Cookie: \n Host: example.org\n\n target=rspec_api_documentation\n\nResponse:\n Status: 200 OK\n Content-Length: 31\n Content-Type: text/plain\n\n Hello, rspec_api_documentation!\n\n\nGreeting your favorite developers of your favorite gem\n------------------------------------------------------\n\nParameters:\n * target - The thing you want to greet\n\nRequest:\n GET /greetings?target=Sam+%26+Eric\n Cookie: \n Host: example.org\n\n target=Sam & Eric\n\nResponse:\n Status: 200 OK\n Content-Length: 18\n Content-Type: text/plain\n\n Hello, Sam & Eric!\n\n\nMultiple Requests\n-----------------\n\nParameters:\n * target - The thing you want to greet\n\nRequest:\n GET /greetings?target=Sam\n Cookie: \n Host: example.org\n\n target=Sam\n\nResponse:\n Status: 200 OK\n Content-Length: 11\n Content-Type: text/plain\n\n Hello, Sam!\n\nRequest:\n GET /greetings?target=Eric\n Cookie: \n Host: example.org\n\n target=Eric\n\nResponse:\n Status: 200 OK\n Content-Length: 12\n Content-Type: text/plain\n\n Hello, Eric!\n" | |
got: "Greeting your favorite developers of your favorite gem\n------------------------------------------------------\n\nParameters:\n * target - The thing you want to greet\n\nRequest:\n GET /greetings?target=Sam+%26+Eric\n Cookie: \n Host: example.org\n\n target=Sam & Eric\n\nResponse:\n Status: 200 OK\n Content-Length: 18\n Content-Type: text/plain\n\n Hello, Sam & Eric!\n\n\nGreeting your favorite gem\n--------------------------\n\nParameters:\n * target - The thing you want to greet\n\nRequest:\n GET /greetings?target=rspec_api_documentation\n Cookie: \n Host: example.org\n\n target=rspec_api_documentation\n\nResponse:\n Status: 200 OK\n Content-Length: 31\n Content-Type: text/plain\n\n Hello, rspec_api_documentation!\n\n\nMultiple Requests\n-----------------\n\nParameters:\n * target - The thing you want to greet\n\nRequest:\n GET /greetings?target=Sam\n Cookie: \n Host: example.org\n\n target=Sam\n\nResponse:\n Status: 200 OK\n Content-Length: 11\n Content-Type: text/plain\n\n Hello, Sam!\n\nRequest:\n GET /greetings?target=Eric\n Cookie: \n Host: example.org\n\n target=Eric\n\nResponse:\n Status: 200 OK\n Content-Length: 12\n Content-Type: text/plain\n\n Hello, Eric!\n" | |
(compared using ==) | |
Diff: | |
@@ -1,43 +1,43 @@ | |
-Greeting your favorite gem | |
--------------------------- | |
+Greeting your favorite developers of your favorite gem | |
+------------------------------------------------------ | |
Parameters: | |
* target - The thing you want to greet | |
Request: | |
- GET /greetings?target=rspec_api_documentation | |
+ GET /greetings?target=Sam+%26+Eric | |
Cookie: | |
Host: example.org | |
- target=rspec_api_documentation | |
+ target=Sam & Eric | |
Response: | |
Status: 200 OK | |
- Content-Length: 31 | |
+ Content-Length: 18 | |
Content-Type: text/plain | |
- Hello, rspec_api_documentation! | |
+ Hello, Sam & Eric! | |
-Greeting your favorite developers of your favorite gem | |
------------------------------------------------------- | |
+Greeting your favorite gem | |
+-------------------------- | |
Parameters: | |
* target - The thing you want to greet | |
Request: | |
- GET /greetings?target=Sam+%26+Eric | |
+ GET /greetings?target=rspec_api_documentation | |
Cookie: | |
Host: example.org | |
- target=Sam & Eric | |
+ target=rspec_api_documentation | |
Response: | |
Status: 200 OK | |
- Content-Length: 18 | |
+ Content-Length: 31 | |
Content-Type: text/plain | |
- Hello, Sam & Eric! | |
+ Hello, rspec_api_documentation! | |
Multiple Requests | |
(RSpec::Expectations::ExpectationNotMetError) | |
features/combined_text.feature:71:in `Then the file "doc/api/greetings/index.txt" should contain exactly:' | |
Feature: cURL output | |
Background: # features/curl.feature:2 | |
Given a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
class App | |
def self.call(env) | |
if env["HTTP_ACCEPT"] == "foo" | |
[200, {}, ["foo"]] | |
else | |
[406, {}, ["unknown content type"]] | |
end | |
end | |
end | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
config.curl_host = "example.org" | |
end | |
resource "FooBars" do | |
get "/foobar" do | |
header "Accept", "foo" | |
example "Getting Foo" do | |
do_request | |
response_body.should == "foo" | |
end | |
end | |
end | |
""" | |
Scenario: Not filtering headers in cURL # features/curl.feature:35 | |
Given a file named "config.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
""" | |
When I run `rspec app_spec.rb --require ./config.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Then the outputted docs should not filter out headers # features/step_definitions/curl_steps.rb:1 | |
Scenario: Filtering out headers in cURL # features/curl.feature:43 | |
Given a file named "config.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
RspecApiDocumentation.configure do |config| | |
config.curl_headers_to_filter = ["Host", "Cookie"] | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./config.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Then the outputted docs should filter out headers # features/step_definitions/curl_steps.rb:1 | |
Feature: Disable DSL features | |
Background: # features/disable_dsl.feature:2 | |
Given a file named "app.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
class App | |
def self.call(env) | |
request = Rack::Request.new(env) | |
response = Rack::Response.new | |
response["Content-Type"] = "text/plain" | |
response.write(request.params["status"]) | |
response.write(request.params["method"]) | |
response.finish | |
end | |
end | |
""" | |
And a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
config.disable_dsl_status! | |
config.disable_dsl_method! | |
end | |
resource "Orders" do | |
get "/orders" do | |
parameter :status, "Order status to search for" | |
parameter :method, "Method of delivery to search for" | |
example "Viewing all orders" do | |
do_request :status => "pending" | |
expect(response_status).to eq(200) | |
expect(response_body).to eq("pending") | |
end | |
example "Checking the method" do | |
do_request :method => "ground" | |
expect(http_method).to eq(:get) | |
expect(response_body).to eq("ground") | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Scenario: Output should have the correct error line # features/disable_dsl.feature:48 | |
Then the output should contain "2 examples, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
Feature: Example Request | |
Background: # features/example_request.feature:2 | |
Given a file named "app.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
class App | |
def self.call(env) | |
[200, {}, ["Hello, world"]] | |
end | |
end | |
""" | |
Scenario: Output should have the correct error line # features/example_request.feature:12 | |
Given a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
end | |
resource "Example Request" do | |
get "/" do | |
example_request "Greeting your favorite gem" do | |
expect(status).to eq(201) | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Then the output should contain "expected: 201" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
Then the output should not contain "endpoint.rb" # aruba-0.6.1/lib/aruba/cucumber.rb:152 | |
Then the output should contain: # aruba-0.6.1/lib/aruba/cucumber.rb:156 | |
""" | |
rspec ./app_spec.rb:10 # Example Request GET / Greeting your favorite gem | |
""" | |
Scenario: should work with RSpec monkey patching disabled # features/example_request.feature:38 | |
When a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation/dsl" | |
RSpec.configure do |config| | |
config.disable_monkey_patching! | |
end | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
end | |
RSpec.resource "Example Request" do | |
get "/" do | |
example_request "Greeting your favorite gem" do | |
expect(status).to eq(200) | |
end | |
end | |
end | |
""" | |
Then I successfully run `rspec app_spec.rb --require ./app.rb` # aruba-0.6.1/lib/aruba/cucumber.rb:104 | |
Feature: Folder Structure | |
Background: # features/folder_structure.feature:2 | |
Given a file named "app.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
class App | |
def self.call(env) | |
[200, {}, ["hello"]] | |
end | |
end | |
""" | |
And a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
end | |
resource "Namespace::Greetings" do | |
get "/greetings" do | |
example_request "Greeting your favorite gem" do | |
expect(status).to eq(200) | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Scenario: Folder structure does not contain :: # features/folder_structure.feature:30 | |
When I open the index # features/step_definitions/html_steps.rb:1 | |
And I navigate to "Greeting your favorite gem" # features/step_definitions/html_steps.rb:5 | |
Then I should see the route is "GET /greetings" # features/step_definitions/html_steps.rb:45 | |
Feature: Specifying request headers | |
Background: # features/headers.feature:3 | |
Given a file named "app.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
class App | |
def self.call(env) | |
if env["HTTP_ACCEPT"] == "foo" | |
[200, {}, ["foo"]] | |
else | |
[406, {}, ["unknown content type"]] | |
end | |
end | |
end | |
""" | |
And a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
end | |
resource "FooBars" do | |
get "/foobar" do | |
header "Accept", "foo" | |
example "Getting Foo" do | |
do_request | |
response_body.should == "foo" | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Scenario: Sending headers along with the request # features/headers.feature:38 | |
Then the output should not contain "unknown content type" # aruba-0.6.1/lib/aruba/cucumber.rb:152 | |
Feature: Generate HTML documentation from test examples | |
Background: # features/html_documentation.feature:3 | |
Given a file named "app.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
class App | |
def self.call(env) | |
request = Rack::Request.new(env) | |
response = Rack::Response.new | |
response["Content-Type"] = "application/json" | |
response.write({ "hello" => request.params["target"] }.to_json) | |
response.finish | |
end | |
end | |
""" | |
And a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
config.api_name = "Example API" | |
config.request_headers_to_include = %w[Cookie] | |
config.response_headers_to_include = %w[Content-Type] | |
end | |
resource "Greetings" do | |
get "/greetings" do | |
parameter :target, "The thing you want to greet" | |
parameter :scoped, "This is a scoped variable", :scope => :scope | |
parameter :sub, "This is scoped", :scope => [:scope, :further] | |
response_field :hello, "The greeted thing" | |
example "Greeting your favorite gem" do | |
do_request :target => "rspec_api_documentation" | |
response_headers["Content-Type"].should eq("application/json") | |
status.should eq(200) | |
response_body.should eq('{"hello":"rspec_api_documentation"}') | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Scenario: Output helpful progress to the console # features/html_documentation.feature:48 | |
Then the output should contain: # aruba-0.6.1/lib/aruba/cucumber.rb:156 | |
""" | |
Generating API Docs | |
Greetings | |
GET /greetings | |
* Greeting your favorite gem | |
""" | |
expected "Generating API Docs\n\nRandomized with seed 6726\n Greetings\n GET /greetings\n * Greeting your favorite gem\n\n1 deprecation warning total\n\nFinished in 0.0237 seconds (files took 0.14196 seconds to load)\n1 example, 0 failures\n\nRandomized with seed 6726\n\n\nDeprecation Warnings:\n\nUsing `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:22:in `block (3 levels) in <top (required)>'.\n\n\nIf you need more of the backtrace for any of these deprecations to\nidentify where to make the necessary changes, you can configure\n`config.raise_errors_for_deprecations!`, and it will turn the\ndeprecation warnings into errors, giving you the full backtrace.\n" to include "Generating API Docs\n Greetings\n GET /greetings\n * Greeting your favorite gem" | |
Diff: | |
@@ -1,2 +1,25 @@ | |
-Generating API Docs\n Greetings\n GET /greetings\n * Greeting your favorite gem | |
+Generating API Docs | |
+ | |
+Randomized with seed 6726 | |
+ Greetings | |
+ GET /greetings | |
+ * Greeting your favorite gem | |
+ | |
+1 deprecation warning total | |
+ | |
+Finished in 0.0237 seconds (files took 0.14196 seconds to load) | |
+1 example, 0 failures | |
+ | |
+Randomized with seed 6726 | |
+ | |
+ | |
+Deprecation Warnings: | |
+ | |
+Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:22:in `block (3 levels) in <top (required)>'. | |
+ | |
+ | |
+If you need more of the backtrace for any of these deprecations to | |
+identify where to make the necessary changes, you can configure | |
+`config.raise_errors_for_deprecations!`, and it will turn the | |
+deprecation warnings into errors, giving you the full backtrace. | |
(RSpec::Expectations::ExpectationNotMetError) | |
features/html_documentation.feature:49:in `Then the output should contain:' | |
And the output should contain "1 example, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
Scenario: Create an index of all API examples, including all resources # features/html_documentation.feature:59 | |
When I open the index # features/step_definitions/html_steps.rb:1 | |
Then I should see the following resources: # features/step_definitions/html_steps.rb:9 | |
| Greetings | | |
And I should see the api name "Example API" # features/step_definitions/html_steps.rb:69 | |
Scenario: Example HTML documentation includes the parameters # features/html_documentation.feature:65 | |
When I open the index # features/step_definitions/html_steps.rb:1 | |
And I navigate to "Greeting your favorite gem" # features/step_definitions/html_steps.rb:5 | |
Then I should see the following parameters: # features/step_definitions/html_steps.rb:13 | |
| name | description | | |
| target | The thing you want to greet | | |
| scope[scoped] | This is a scoped variable | | |
| scope[further][sub] | This is scoped | | |
Scenario: Examle HTML documentation should include the response fields # features/html_documentation.feature:74 | |
When I open the index # features/step_definitions/html_steps.rb:1 | |
And I navigate to "Greeting your favorite gem" # features/step_definitions/html_steps.rb:5 | |
Then I should see the following response fields: # features/step_definitions/html_steps.rb:20 | |
| name | description | | |
| hello | The greeted thing | | |
Scenario: Example HTML documentation includes the request information # features/html_documentation.feature:81 | |
When I open the index # features/step_definitions/html_steps.rb:1 | |
And I navigate to "Greeting your favorite gem" # features/step_definitions/html_steps.rb:5 | |
Then I should see the route is "GET /greetings?target=rspec_api_documentation" # features/step_definitions/html_steps.rb:45 | |
And I should see the following request headers: # features/step_definitions/html_steps.rb:27 | |
| Cookie | | | |
And I should not see the following request headers: # features/step_definitions/html_steps.rb:36 | |
| Host | example.org | | |
And I should see the following query parameters: # features/step_definitions/html_steps.rb:49 | |
| target | rspec_api_documentation | | |
Scenario: Example HTML documentation includes the response information # features/html_documentation.feature:92 | |
When I open the index # features/step_definitions/html_steps.rb:1 | |
And I navigate to "Greeting your favorite gem" # features/step_definitions/html_steps.rb:5 | |
Then I should see the response status is "200 OK" # features/step_definitions/html_steps.rb:57 | |
And I should see the following response headers: # features/step_definitions/html_steps.rb:27 | |
| Content-Type | application/json | | |
And I should not see the following response headers: # features/step_definitions/html_steps.rb:36 | |
| Content-Length | 35 | | |
And I should see the following response body: # features/step_definitions/html_steps.rb:65 | |
""" | |
{ "hello": "rspec_api_documentation" } | |
""" | |
Feature: Json Iodocs | |
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: # features/json_iodocs.feature:6 | |
Given a file named "app.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
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: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
config.api_name = "app" | |
config.format = :json_iodocs | |
config.io_docs_protocol = "https" | |
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" | |
response_headers["Content-Type"].should eq("text/plain") | |
status.should eq(200) | |
response_body.should eq('Hello, rspec_api_documentation!') | |
end | |
example "Greeting your favorite developers of your favorite gem" do | |
do_request :target => "Sam & Eric" | |
response_headers["Content-Type"].should eq("text/plain") | |
status.should eq(200) | |
response_body.should eq('Hello, Sam & Eric!') | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Scenario: Output helpful progress to the console # features/json_iodocs.feature:55 | |
Then the output should contain: # aruba-0.6.1/lib/aruba/cucumber.rb:156 | |
""" | |
Generating API Docs | |
Greetings | |
GET /greetings | |
* Greeting your favorite gem | |
* Greeting your favorite developers of your favorite gem | |
""" | |
expected "Generating API Docs\n\nRandomized with seed 52697\n Greetings\n GET /greetings\n * Greeting your favorite gem\n * Greeting your favorite developers of your favorite gem\n\n1 deprecation warning total\n\nFinished in 0.02945 seconds (files took 0.14074 seconds to load)\n2 examples, 0 failures\n\nRandomized with seed 52697\n\n\nDeprecation Warnings:\n\nUsing `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:18:in `block (3 levels) in <top (required)>'.\n\n\nIf you need more of the backtrace for any of these deprecations to\nidentify where to make the necessary changes, you can configure\n`config.raise_errors_for_deprecations!`, and it will turn the\ndeprecation warnings into errors, giving you the full backtrace.\n" to include "Generating API Docs\n Greetings\n GET /greetings\n * Greeting your favorite gem\n * Greeting your favorite developers of your favorite gem" | |
Diff: | |
@@ -1,2 +1,26 @@ | |
-Generating API Docs\n Greetings\n GET /greetings\n * Greeting your favorite gem\n * Greeting your favorite developers of your favorite gem | |
+Generating API Docs | |
+ | |
+Randomized with seed 52697 | |
+ Greetings | |
+ GET /greetings | |
+ * Greeting your favorite gem | |
+ * Greeting your favorite developers of your favorite gem | |
+ | |
+1 deprecation warning total | |
+ | |
+Finished in 0.02945 seconds (files took 0.14074 seconds to load) | |
+2 examples, 0 failures | |
+ | |
+Randomized with seed 52697 | |
+ | |
+ | |
+Deprecation Warnings: | |
+ | |
+Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:18:in `block (3 levels) in <top (required)>'. | |
+ | |
+ | |
+If you need more of the backtrace for any of these deprecations to | |
+identify where to make the necessary changes, you can configure | |
+`config.raise_errors_for_deprecations!`, and it will turn the | |
+deprecation warnings into errors, giving you the full backtrace. | |
(RSpec::Expectations::ExpectationNotMetError) | |
features/json_iodocs.feature:56:in `Then the output should contain:' | |
And the output should contain "2 examples, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
Scenario: File should look like we expect # features/json_iodocs.feature:67 | |
Then the file "doc/api/apiconfig.json" should contain JSON exactly like: # features/step_definitions/json_steps.rb:1 | |
""" | |
{ | |
"app" : { | |
"name" : "app", | |
"protocol" : "https", | |
"publicPath" : "", | |
"baseURL" : null | |
} | |
} | |
""" | |
Then the file "doc/api/app.json" should contain JSON exactly like: # features/step_definitions/json_steps.rb:1 | |
""" | |
{ | |
"endpoints": [ | |
{ | |
"name": "Greetings", | |
"methods": [ | |
{ | |
"MethodName": "Greeting your favorite developers of your favorite gem", | |
"Synopsis": null, | |
"HTTPMethod": "GET", | |
"URI": "/greetings?target=Sam+%26+Eric", | |
"RequiresOAuth": "N", | |
"parameters": [ | |
{ | |
"Name": "target", | |
"Description": "The thing you want to greet", | |
"Default": "", | |
"Required": "N" | |
} | |
] | |
}, | |
{ | |
"MethodName": "Greeting your favorite gem", | |
"Synopsis": null, | |
"HTTPMethod": "GET", | |
"URI": "/greetings?target=rspec_api_documentation", | |
"RequiresOAuth": "N", | |
"parameters": [ | |
{ | |
"Name": "target", | |
"Description": "The thing you want to greet", | |
"Default": "", | |
"Required": "N" | |
} | |
] | |
} | |
] | |
} | |
] | |
} | |
""" | |
Feature: Generate Markdown documentation from test examples | |
Background: # features/markdown_documentation.feature:3 | |
Given a file named "app.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require 'sinatra' | |
class App < Sinatra::Base | |
get '/orders' do | |
content_type :json | |
[200, { | |
:page => 1, | |
:orders => [ | |
{ name: 'Order 1', amount: 9.99, description: nil }, | |
{ name: 'Order 2', amount: 100.0, description: 'A great order' } | |
] | |
}.to_json] | |
end | |
get '/orders/:id' do | |
content_type :json | |
[200, { order: { name: 'Order 1', amount: 100.0, description: 'A great order' } }.to_json] | |
end | |
post '/orders' do | |
201 | |
end | |
put '/orders/:id' do | |
200 | |
end | |
delete '/orders/:id' do | |
200 | |
end | |
get '/help' do | |
[200, 'Welcome Henry !'] | |
end | |
end | |
""" | |
And a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
config.api_name = "Example API" | |
config.format = :markdown | |
config.request_headers_to_include = %w[Content-Type Host] | |
config.response_headers_to_include = %w[Content-Type Content-Length] | |
end | |
resource 'Orders' do | |
get '/orders' do | |
response_field :page, "Current page" | |
example_request 'Getting a list of orders' do | |
status.should eq(200) | |
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"}]}') | |
end | |
end | |
get '/orders/:id' do | |
let(:id) { 1 } | |
example_request 'Getting a specific order' do | |
status.should eq(200) | |
response_body.should == '{"order":{"name":"Order 1","amount":100.0,"description":"A great order"}}' | |
end | |
end | |
post '/orders' do | |
parameter :name, 'Name of order', :required => true | |
parameter :amount, 'Amount paid', :required => true | |
parameter :description, 'Some comments on the order' | |
let(:name) { "Order 3" } | |
let(:amount) { 33.0 } | |
example_request 'Creating an order' do | |
status.should == 201 | |
end | |
end | |
put '/orders/:id' do | |
parameter :name, 'Name of order', :required => true | |
parameter :amount, 'Amount paid', :required => true | |
parameter :description, 'Some comments on the order' | |
let(:id) { 2 } | |
let(:name) { "Updated name" } | |
example_request 'Updating an order' do | |
status.should == 200 | |
end | |
end | |
delete "/orders/:id" do | |
let(:id) { 1 } | |
example_request "Deleting an order" do | |
status.should == 200 | |
end | |
end | |
end | |
resource 'Help' do | |
get '/help' do | |
example_request 'Getting welcome message' do | |
status.should eq(200) | |
response_body.should == 'Welcome Henry !' | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Scenario: Output helpful progress to the console # features/markdown_documentation.feature:123 | |
Then the output should contain: # aruba-0.6.1/lib/aruba/cucumber.rb:156 | |
""" | |
Generating API Docs | |
Orders | |
GET /orders | |
* Getting a list of orders | |
GET /orders/:id | |
* Getting a specific order | |
POST /orders | |
* Creating an order | |
PUT /orders/:id | |
* Updating an order | |
DELETE /orders/:id | |
* Deleting an order | |
Help | |
GET /help | |
* Getting welcome message | |
""" | |
expected "Generating API Docs\n\nRandomized with seed 37019\n Help\n GET /help\n * Getting welcome message\n Orders\n GET /orders\n * Getting a list of orders\n POST /orders\n * Creating an order\n PUT /orders/:id\n * Updating an order\n DELETE /orders/:id\n * Deleting an order\n GET /orders/:id\n * Getting a specific order\n\n1 deprecation warning total\n\nFinished in 0.03366 seconds (files took 0.1559 seconds to load)\n6 examples, 0 failures\n\nRandomized with seed 37019\n\n\nDeprecation Warnings:\n\nUsing `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:69:in `block (3 levels) in <top (required)>'.\n\n\nIf you need more of the backtrace for any of these deprecations to\nidentify where to make the necessary changes, you can configure\n`config.raise_errors_for_deprecations!`, and it will turn the\ndeprecation warnings into errors, giving you the full backtrace.\n" to include "Generating API Docs\n Orders\n GET /orders\n * Getting a list of orders\n GET /orders/:id\n * Getting a specific order\n POST /orders\n * Creating an order\n PUT /orders/:id\n * Updating an order\n DELETE /orders/:id\n * Deleting an order\n Help\n GET /help\n * Getting welcome message" | |
Diff: | |
@@ -1,2 +1,36 @@ | |
-Generating API Docs\n Orders\n GET /orders\n * Getting a list of orders\n GET /orders/:id\n * Getting a specific order\n POST /orders\n * Creating an order\n PUT /orders/:id\n * Updating an order\n DELETE /orders/:id\n * Deleting an order\n Help\n GET /help\n * Getting welcome message | |
+Generating API Docs | |
+ | |
+Randomized with seed 37019 | |
+ Help | |
+ GET /help | |
+ * Getting welcome message | |
+ Orders | |
+ GET /orders | |
+ * Getting a list of orders | |
+ POST /orders | |
+ * Creating an order | |
+ PUT /orders/:id | |
+ * Updating an order | |
+ DELETE /orders/:id | |
+ * Deleting an order | |
+ GET /orders/:id | |
+ * Getting a specific order | |
+ | |
+1 deprecation warning total | |
+ | |
+Finished in 0.03366 seconds (files took 0.1559 seconds to load) | |
+6 examples, 0 failures | |
+ | |
+Randomized with seed 37019 | |
+ | |
+ | |
+Deprecation Warnings: | |
+ | |
+Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:69:in `block (3 levels) in <top (required)>'. | |
+ | |
+ | |
+If you need more of the backtrace for any of these deprecations to | |
+identify where to make the necessary changes, you can configure | |
+`config.raise_errors_for_deprecations!`, and it will turn the | |
+deprecation warnings into errors, giving you the full backtrace. | |
(RSpec::Expectations::ExpectationNotMetError) | |
features/markdown_documentation.feature:124:in `Then the output should contain:' | |
And the output should contain "6 examples, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
Scenario: Index file should look like we expect # features/markdown_documentation.feature:145 | |
Then the file "doc/api/index.markdown" should contain exactly: # aruba-0.6.1/lib/aruba/cucumber.rb:355 | |
""" | |
# Example API | |
## Help | |
* [Getting welcome message](help/getting_welcome_message.markdown) | |
## Orders | |
* [Creating an order](orders/creating_an_order.markdown) | |
* [Deleting an order](orders/deleting_an_order.markdown) | |
* [Getting a list of orders](orders/getting_a_list_of_orders.markdown) | |
* [Getting a specific order](orders/getting_a_specific_order.markdown) | |
* [Updating an order](orders/updating_an_order.markdown) | |
""" | |
Scenario: Example 'Getting al ist of orders' file should look like we expect # features/markdown_documentation.feature:165 | |
Then the file "doc/api/orders/getting_a_list_of_orders.markdown" should contain exactly: # aruba-0.6.1/lib/aruba/cucumber.rb:355 | |
""" | |
# Orders API | |
## Getting a list of orders | |
### GET /orders | |
### Response Fields | |
Name : page | |
Description : Current page | |
### Request | |
#### Headers | |
<pre>Host: example.org</pre> | |
#### Route | |
<pre>GET /orders</pre> | |
### Response | |
#### Headers | |
<pre>Content-Type: application/json | |
Content-Length: 137</pre> | |
#### Status | |
<pre>200 OK</pre> | |
#### Body | |
<pre>{ | |
"page": 1, | |
"orders": [ | |
{ | |
"name": "Order 1", | |
"amount": 9.99, | |
"description": null | |
}, | |
{ | |
"name": "Order 2", | |
"amount": 100.0, | |
"description": "A great order" | |
} | |
] | |
}</pre> | |
""" | |
Scenario: Example 'Creating an order' file should look like we expect # features/markdown_documentation.feature:220 | |
Then the file "doc/api/orders/creating_an_order.markdown" should contain exactly: # aruba-0.6.1/lib/aruba/cucumber.rb:355 | |
""" | |
# Orders API | |
## Creating an order | |
### POST /orders | |
### Parameters | |
Name : name *- required -* | |
Description : Name of order | |
Name : amount *- required -* | |
Description : Amount paid | |
Name : description | |
Description : Some comments on the order | |
### Request | |
#### Headers | |
<pre>Host: example.org | |
Content-Type: application/x-www-form-urlencoded</pre> | |
#### Route | |
<pre>POST /orders</pre> | |
#### Body | |
<pre>name=Order+3&amount=33.0</pre> | |
### Response | |
#### Headers | |
<pre>Content-Type: text/html;charset=utf-8 | |
Content-Length: 0</pre> | |
#### Status | |
<pre>201 Created</pre> | |
""" | |
Scenario: Example 'Deleting an order' file should be created # features/markdown_documentation.feature:269 | |
Then a file named "doc/api/orders/deleting_an_order.markdown" should exist # aruba-0.6.1/lib/aruba/cucumber.rb:307 | |
Scenario: Example 'Getting a list of orders' file should be created # features/markdown_documentation.feature:272 | |
Then a file named "doc/api/orders/getting_a_list_of_orders.markdown" should exist # aruba-0.6.1/lib/aruba/cucumber.rb:307 | |
Scenario: Example 'Getting a specific order' file should be created # features/markdown_documentation.feature:275 | |
Then a file named "doc/api/orders/getting_a_specific_order.markdown" should exist # aruba-0.6.1/lib/aruba/cucumber.rb:307 | |
Scenario: Example 'Updating an order' file should be created # features/markdown_documentation.feature:278 | |
Then a file named "doc/api/orders/updating_an_order.markdown" should exist # aruba-0.6.1/lib/aruba/cucumber.rb:307 | |
Scenario: Example 'Getting welcome message' file should be created # features/markdown_documentation.feature:281 | |
Then a file named "doc/api/help/getting_welcome_message.markdown" should exist # aruba-0.6.1/lib/aruba/cucumber.rb:307 | |
Feature: Use OAuth2 MAC client as a test client | |
Background: # features/oauth2_mac_client.feature:2 | |
Given a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
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" | |
response_headers["Content-Type"].should eq("text/plain") | |
status.should eq(200) | |
response_body.should 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 | |
response_headers["Content-Type"].should eq("text/plain") | |
status.should eq(200) | |
response_body.should 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 | |
response_headers["Content-Type"].should eq("text/plain") | |
status.should eq(200) | |
response_body.should 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` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Scenario: Output should contain # features/oauth2_mac_client.feature:118 | |
Then the output should contain: # aruba-0.6.1/lib/aruba/cucumber.rb:156 | |
""" | |
Generating API Docs | |
Greetings | |
GET / | |
* Greeting your favorite gem | |
GET /multiple | |
* Greeting your favorite people | |
GET /multiple_nested | |
* Greeting your favorite companies | |
""" | |
expected "Generating API Docs\n\nRandomized with seed 10822\n Greetings\n GET /\n * Greeting your favorite gem\n GET /multiple\n * Greeting your favorite people\n GET /multiple_nested\n * Greeting your favorite companies\n\n1 deprecation warning total\n\nFinished in 0.1831 seconds (files took 0.13738 seconds to load)\n3 examples, 0 failures\n\nRandomized with seed 10822\n\n\nDeprecation Warnings:\n\nUsing `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:76:in `block (3 levels) in <top (required)>'.\n\n\nIf you need more of the backtrace for any of these deprecations to\nidentify where to make the necessary changes, you can configure\n`config.raise_errors_for_deprecations!`, and it will turn the\ndeprecation warnings into errors, giving you the full backtrace.\n" to include "Generating API Docs\n Greetings\n GET /\n * Greeting your favorite gem\n GET /multiple\n * Greeting your favorite people\n GET /multiple_nested\n * Greeting your favorite companies" | |
Diff: | |
@@ -1,2 +1,29 @@ | |
-Generating API Docs\n Greetings\n GET /\n * Greeting your favorite gem\n GET /multiple\n * Greeting your favorite people\n GET /multiple_nested\n * Greeting your favorite companies | |
+Generating API Docs | |
+ | |
+Randomized with seed 10822 | |
+ Greetings | |
+ GET / | |
+ * Greeting your favorite gem | |
+ GET /multiple | |
+ * Greeting your favorite people | |
+ GET /multiple_nested | |
+ * Greeting your favorite companies | |
+ | |
+1 deprecation warning total | |
+ | |
+Finished in 0.1831 seconds (files took 0.13738 seconds to load) | |
+3 examples, 0 failures | |
+ | |
+Randomized with seed 10822 | |
+ | |
+ | |
+Deprecation Warnings: | |
+ | |
+Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:76:in `block (3 levels) in <top (required)>'. | |
+ | |
+ | |
+If you need more of the backtrace for any of these deprecations to | |
+identify where to make the necessary changes, you can configure | |
+`config.raise_errors_for_deprecations!`, and it will turn the | |
+deprecation warnings into errors, giving you the full backtrace. | |
(RSpec::Expectations::ExpectationNotMetError) | |
features/oauth2_mac_client.feature:119:in `Then the output should contain:' | |
And the output should contain "3 examples, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
Feature: Example Request with PATCH | |
Background: # features/patch.feature:2 | |
Given a file named "app.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
class App | |
def self.call(env) | |
if env["REQUEST_METHOD"] == "PATCH" | |
[200, {}, ["Hello, world"]] | |
else | |
[404, {}, ["ERROR"]] | |
end | |
end | |
end | |
""" | |
And a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
end | |
resource "Example Request" do | |
patch "/" do | |
example_request "Trying out patch" do | |
status.should eq(200) | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Scenario: Output should have the correct error line # features/patch.feature:34 | |
Then the output should contain "1 example, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
Feature: Redefining the client method | |
Background: # features/redefining_client.feature:2 | |
Given a file named "app.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
class App | |
def self.call(env) | |
[200, {}, ["Hello, world"]] | |
end | |
end | |
""" | |
And a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
config.client_method = :different_client | |
end | |
resource "Example Request" do | |
let(:client) { double(:client) } | |
get "/" do | |
example_request "Trying out get" do | |
status.should eq(200) | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Scenario: Output should have the correct error line # features/redefining_client.feature:33 | |
Then the output should contain "1 example, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
Feature: Generate Textile documentation from test examples | |
Background: # features/textile_documentation.feature:3 | |
Given a file named "app.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require 'sinatra' | |
class App < Sinatra::Base | |
get '/orders' do | |
content_type :json | |
[200, { | |
:page => 1, | |
:orders => [ | |
{ name: 'Order 1', amount: 9.99, description: nil }, | |
{ name: 'Order 2', amount: 100.0, description: 'A great order' } | |
] | |
}.to_json] | |
end | |
get '/orders/:id' do | |
content_type :json | |
[200, { order: { name: 'Order 1', amount: 100.0, description: 'A great order' } }.to_json] | |
end | |
post '/orders' do | |
201 | |
end | |
put '/orders/:id' do | |
200 | |
end | |
delete '/orders/:id' do | |
200 | |
end | |
get '/help' do | |
[200, 'Welcome Henry !'] | |
end | |
end | |
""" | |
And a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
config.api_name = "Example API" | |
config.format = :textile | |
config.request_headers_to_include = %w[Content-Type Host] | |
config.response_headers_to_include = %w[Content-Type Content-Length] | |
end | |
resource 'Orders' do | |
get '/orders' do | |
response_field :page, "Current page" | |
example_request 'Getting a list of orders' do | |
status.should eq(200) | |
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"}]}') | |
end | |
end | |
get '/orders/:id' do | |
let(:id) { 1 } | |
example_request 'Getting a specific order' do | |
status.should eq(200) | |
response_body.should == '{"order":{"name":"Order 1","amount":100.0,"description":"A great order"}}' | |
end | |
end | |
post '/orders' do | |
parameter :name, 'Name of order', :required => true | |
parameter :amount, 'Amount paid', :required => true | |
parameter :description, 'Some comments on the order' | |
let(:name) { "Order 3" } | |
let(:amount) { 33.0 } | |
example_request 'Creating an order' do | |
status.should == 201 | |
end | |
end | |
put '/orders/:id' do | |
parameter :name, 'Name of order', :required => true | |
parameter :amount, 'Amount paid', :required => true | |
parameter :description, 'Some comments on the order' | |
let(:id) { 2 } | |
let(:name) { "Updated name" } | |
example_request 'Updating an order' do | |
status.should == 200 | |
end | |
end | |
delete "/orders/:id" do | |
let(:id) { 1 } | |
example_request "Deleting an order" do | |
status.should == 200 | |
end | |
end | |
end | |
resource 'Help' do | |
get '/help' do | |
example_request 'Getting welcome message' do | |
status.should eq(200) | |
response_body.should == 'Welcome Henry !' | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./app.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Scenario: Output helpful progress to the console # features/textile_documentation.feature:123 | |
Then the output should contain: # aruba-0.6.1/lib/aruba/cucumber.rb:156 | |
""" | |
Generating API Docs | |
Orders | |
GET /orders | |
* Getting a list of orders | |
GET /orders/:id | |
* Getting a specific order | |
POST /orders | |
* Creating an order | |
PUT /orders/:id | |
* Updating an order | |
DELETE /orders/:id | |
* Deleting an order | |
Help | |
GET /help | |
* Getting welcome message | |
""" | |
expected "Generating API Docs\n\nRandomized with seed 31599\n Help\n GET /help\n * Getting welcome message\n Orders\n PUT /orders/:id\n * Updating an order\n POST /orders\n * Creating an order\n DELETE /orders/:id\n * Deleting an order\n GET /orders\n * Getting a list of orders\n GET /orders/:id\n * Getting a specific order\n\n1 deprecation warning total\n\nFinished in 0.03428 seconds (files took 0.16107 seconds to load)\n6 examples, 0 failures\n\nRandomized with seed 31599\n\n\nDeprecation Warnings:\n\nUsing `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:69:in `block (3 levels) in <top (required)>'.\n\n\nIf you need more of the backtrace for any of these deprecations to\nidentify where to make the necessary changes, you can configure\n`config.raise_errors_for_deprecations!`, and it will turn the\ndeprecation warnings into errors, giving you the full backtrace.\n" to include "Generating API Docs\n Orders\n GET /orders\n * Getting a list of orders\n GET /orders/:id\n * Getting a specific order\n POST /orders\n * Creating an order\n PUT /orders/:id\n * Updating an order\n DELETE /orders/:id\n * Deleting an order\n Help\n GET /help\n * Getting welcome message" | |
Diff: | |
@@ -1,2 +1,36 @@ | |
-Generating API Docs\n Orders\n GET /orders\n * Getting a list of orders\n GET /orders/:id\n * Getting a specific order\n POST /orders\n * Creating an order\n PUT /orders/:id\n * Updating an order\n DELETE /orders/:id\n * Deleting an order\n Help\n GET /help\n * Getting welcome message | |
+Generating API Docs | |
+ | |
+Randomized with seed 31599 | |
+ Help | |
+ GET /help | |
+ * Getting welcome message | |
+ Orders | |
+ PUT /orders/:id | |
+ * Updating an order | |
+ POST /orders | |
+ * Creating an order | |
+ DELETE /orders/:id | |
+ * Deleting an order | |
+ GET /orders | |
+ * Getting a list of orders | |
+ GET /orders/:id | |
+ * Getting a specific order | |
+ | |
+1 deprecation warning total | |
+ | |
+Finished in 0.03428 seconds (files took 0.16107 seconds to load) | |
+6 examples, 0 failures | |
+ | |
+Randomized with seed 31599 | |
+ | |
+ | |
+Deprecation Warnings: | |
+ | |
+Using `should` from rspec-expectations' old `:should` syntax without explicitly enabling the syntax is deprecated. Use the new `:expect` syntax or explicitly enable `:should` with `config.expect_with(:rspec) { |c| c.syntax = :should }` instead. Called from /home/ceritium/work/rspec_api_documentation/tmp/aruba/app_spec.rb:69:in `block (3 levels) in <top (required)>'. | |
+ | |
+ | |
+If you need more of the backtrace for any of these deprecations to | |
+identify where to make the necessary changes, you can configure | |
+`config.raise_errors_for_deprecations!`, and it will turn the | |
+deprecation warnings into errors, giving you the full backtrace. | |
(RSpec::Expectations::ExpectationNotMetError) | |
features/textile_documentation.feature:124:in `Then the output should contain:' | |
And the output should contain "6 examples, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
Scenario: Index file should look like we expect # features/textile_documentation.feature:145 | |
Then the file "doc/api/index.textile" should contain exactly: # aruba-0.6.1/lib/aruba/cucumber.rb:355 | |
""" | |
h1. Example API | |
h2. Help | |
* "Getting welcome message":help/getting_welcome_message.textile | |
h2. Orders | |
* "Creating an order":orders/creating_an_order.textile | |
* "Deleting an order":orders/deleting_an_order.textile | |
* "Getting a list of orders":orders/getting_a_list_of_orders.textile | |
* "Getting a specific order":orders/getting_a_specific_order.textile | |
* "Updating an order":orders/updating_an_order.textile | |
""" | |
Scenario: Example 'Getting al ist of orders' file should look like we expect # features/textile_documentation.feature:165 | |
Then the file "doc/api/orders/getting_a_list_of_orders.textile" should contain exactly: # aruba-0.6.1/lib/aruba/cucumber.rb:355 | |
""" | |
h1. Orders API | |
h2. Getting a list of orders | |
h3. GET /orders | |
h3. Response Fields | |
Name : page | |
Description : Current page | |
h3. Request | |
h4. Headers | |
<pre>Host: example.org</pre> | |
h4. Route | |
<pre>GET /orders</pre> | |
h3. Response | |
h4. Headers | |
<pre>Content-Type: application/json | |
Content-Length: 137</pre> | |
h4. Status | |
<pre>200 OK</pre> | |
h4. Body | |
<pre>{ | |
"page": 1, | |
"orders": [ | |
{ | |
"name": "Order 1", | |
"amount": 9.99, | |
"description": null | |
}, | |
{ | |
"name": "Order 2", | |
"amount": 100.0, | |
"description": "A great order" | |
} | |
] | |
}</pre> | |
""" | |
Scenario: Example 'Creating an order' file should look like we expect # features/textile_documentation.feature:221 | |
Then the file "doc/api/orders/creating_an_order.textile" should contain exactly: # aruba-0.6.1/lib/aruba/cucumber.rb:355 | |
""" | |
h1. Orders API | |
h2. Creating an order | |
h3. POST /orders | |
h3. Parameters | |
Name : name *- required -* | |
Description : Name of order | |
Name : amount *- required -* | |
Description : Amount paid | |
Name : description | |
Description : Some comments on the order | |
h3. Request | |
h4. Headers | |
<pre>Host: example.org | |
Content-Type: application/x-www-form-urlencoded</pre> | |
h4. Route | |
<pre>POST /orders</pre> | |
h4. Body | |
<pre>name=Order+3&amount=33.0</pre> | |
h3. Response | |
h4. Headers | |
<pre>Content-Type: text/html;charset=utf-8 | |
Content-Length: 0</pre> | |
h4. Status | |
<pre>201 Created</pre> | |
""" | |
Scenario: Example 'Deleting an order' file should be created # features/textile_documentation.feature:270 | |
Then a file named "doc/api/orders/deleting_an_order.textile" should exist # aruba-0.6.1/lib/aruba/cucumber.rb:307 | |
Scenario: Example 'Getting a list of orders' file should be created # features/textile_documentation.feature:273 | |
Then a file named "doc/api/orders/getting_a_list_of_orders.textile" should exist # aruba-0.6.1/lib/aruba/cucumber.rb:307 | |
Scenario: Example 'Getting a specific order' file should be created # features/textile_documentation.feature:276 | |
Then a file named "doc/api/orders/getting_a_specific_order.textile" should exist # aruba-0.6.1/lib/aruba/cucumber.rb:307 | |
Scenario: Example 'Updating an order' file should be created # features/textile_documentation.feature:279 | |
Then a file named "doc/api/orders/updating_an_order.textile" should exist # aruba-0.6.1/lib/aruba/cucumber.rb:307 | |
Scenario: Example 'Getting welcome message' file should be created # features/textile_documentation.feature:282 | |
Then a file named "doc/api/help/getting_welcome_message.textile" should exist # aruba-0.6.1/lib/aruba/cucumber.rb:307 | |
Feature: Uploading a file | |
Background: # features/upload_file.feature:2 | |
Given a file named "nonestedparam.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require 'rack' | |
class App | |
def self.call(env) | |
request = Rack::Request.new(env) | |
[200, {}, [request.params["file"][:filename]]] | |
end | |
end | |
""" | |
Given a file named "nestedparam.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require 'rack' | |
class App | |
def self.call(env) | |
request = Rack::Request.new(env) | |
[200, {}, [request.params["post"]["file"][:filename]]] | |
end | |
end | |
""" | |
Scenario: Uploading a text file with nested parameters # features/upload_file.feature:26 | |
Given a file named "file.txt" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
a file to upload | |
""" | |
And a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
require "rack/test" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
end | |
resource "FooBars" do | |
post "/foobar" do | |
parameter :post, "Post paramter" | |
let(:post) do | |
{ | |
id: 1, | |
file: Rack::Test::UploadedFile.new("file.txt", "text/plain") | |
} | |
end | |
example_request "Uploading a file" do | |
response_body.should == "file.txt" | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./nestedparam.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Then the output should contain "1 example, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
Scenario: Uploading a text file, no nested parameters # features/upload_file.feature:64 | |
Given a file named "file.txt" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
a file to upload | |
""" | |
And a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
require "rack/test" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
end | |
resource "FooBars" do | |
post "/foobar" do | |
parameter :file, "File to upload" | |
let(:file) do | |
Rack::Test::UploadedFile.new("file.txt", "text/plain") | |
end | |
example_request "Uploading a file" do | |
response_body.should == "file.txt" | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./nonestedparam.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Then the output should contain "1 example, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
Scenario: Uploading an image file, no nested parameters # features/upload_file.feature:99 | |
Given I move the sample image into the workspace # features/step_definitions/image_steps.rb:1 | |
And a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
require "rack/test" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
end | |
resource "FooBars" do | |
post "/foobar" do | |
parameter :file, "File to upload" | |
let(:file) do | |
Rack::Test::UploadedFile.new("file.png", "image/png") | |
end | |
example_request "Uploading a file" do | |
response_body.should == "file.png" | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./nonestedparam.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Then the output should contain "1 example, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
And the generated documentation should be encoded correctly # features/step_definitions/image_steps.rb:5 | |
Scenario: Uploading an image file, no nested parameters # features/upload_file.feature:132 | |
Given I move the sample image into the workspace # features/step_definitions/image_steps.rb:1 | |
And a file named "app_spec.rb" with: # aruba-0.6.1/lib/aruba/cucumber.rb:29 | |
""" | |
require "rspec_api_documentation" | |
require "rspec_api_documentation/dsl" | |
require "rack/test" | |
RspecApiDocumentation.configure do |config| | |
config.app = App | |
end | |
resource "FooBars" do | |
post "/foobar" do | |
parameter :post, "Post parameter" | |
let(:post) do | |
{ | |
id: 10, | |
file: Rack::Test::UploadedFile.new("file.png", "image/png") | |
} | |
end | |
example_request "Uploading a file" do | |
response_body.should == "file.png" | |
end | |
end | |
end | |
""" | |
When I run `rspec app_spec.rb --require ./nestedparam.rb --format RspecApiDocumentation::ApiFormatter` # aruba-0.6.1/lib/aruba/cucumber.rb:93 | |
Then the output should contain "1 example, 0 failures" # aruba-0.6.1/lib/aruba/cucumber.rb:140 | |
And the exit status should be 0 # aruba-0.6.1/lib/aruba/cucumber.rb:197 | |
And the generated documentation should be encoded correctly # features/step_definitions/image_steps.rb:5 | |
Failing Scenarios: | |
cucumber features/callbacks.feature:43 # Scenario: Output helpful progress to the console | |
cucumber features/combined_json.feature:55 # Scenario: Output helpful progress to the console | |
cucumber features/combined_text.feature:58 # Scenario: Output helpful progress to the console | |
cucumber features/combined_text.feature:70 # Scenario: File should look like we expect | |
cucumber features/html_documentation.feature:48 # Scenario: Output helpful progress to the console | |
cucumber features/json_iodocs.feature:55 # Scenario: Output helpful progress to the console | |
cucumber features/markdown_documentation.feature:123 # Scenario: Output helpful progress to the console | |
cucumber features/oauth2_mac_client.feature:118 # Scenario: Output should contain | |
cucumber features/textile_documentation.feature:123 # Scenario: Output helpful progress to the console | |
47 scenarios (9 failed, 38 passed) | |
242 steps (9 failed, 16 skipped, 217 passed) | |
0m28.502s |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment