Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
  • 4 commits
  • 11 files changed
  • 0 commit comments
  • 2 contributors
View
1 README.md
@@ -36,6 +36,7 @@ See the `example` folder for a sample Rails app that has been documented.
- url_prefix - Add before all links on the index page, useful if docs are located in `public/docs`, must include a leading `/`, no trailing `/`; eg `/docs`
- curl_host - Used when adding a cURL output to the docs
- keep_source_order - By default examples and resources are ordered by description. Set to true keep the source order.
+- api_name - Change the name of the API on index pages, default is "API Documentation"
### Example Configuration
`spec/spec_helper.rb`
View
5 example/spec/acceptance/orders_spec.rb
@@ -2,7 +2,8 @@
require 'rspec_api_documentation/dsl'
resource "Orders" do
- let(:client) { RspecApiDocumentation::RackTestClient.new(self, :headers => {"HTTP_ACCEPT" => "application/json", "CONTENT_TYPE" => "application/json"}) }
+ header "Accept", "application/json"
+ header "Content-Type", "application/json"
let(:order) { Order.create(:name => "Old Name", :paid => true, :email => "email@example.com") }
@@ -49,7 +50,7 @@
order = JSON.parse(response_body)
- client.get(URI.parse(response_headers["location"]).path)
+ client.get(URI.parse(response_headers["location"]).path, {}, headers)
status.should == 200
end
end
View
1 example/spec/spec_helper.rb
@@ -40,4 +40,5 @@
#config.format = [:json, :html]
config.url_prefix = "/docs"
config.curl_host = 'http://localhost:3000'
+ config.api_name = "Example App API"
end
View
2 features/html_documentation.feature
@@ -20,6 +20,7 @@ Feature: Generate HTML documentation from test examples
RspecApiDocumentation.configure do |config|
config.app = App
+ config.api_name = "Example API"
end
resource "Greetings" do
@@ -53,6 +54,7 @@ Feature: Generate HTML documentation from test examples
When I open the index
Then I should see the following resources:
| Greetings |
+ And I should see the api name "Example API"
Scenario: Example HTML documentation includes the parameters
When I open the index
View
11 features/step_definitions/html_steps.rb
@@ -13,6 +13,7 @@
Then /^I should see the following parameters:$/ do |table|
names = all(".parameters .name").map(&:text)
descriptions = all(".parameters .description").map(&:text)
+
names.zip(descriptions).should == table.rows
end
@@ -20,6 +21,7 @@
text = page.find("pre.#{part}.headers").text
actual_headers = text.split("\n")
expected_headers = table.raw.map { |row| row.join(": ") }
+
actual_headers.should =~ expected_headers
end
@@ -31,6 +33,7 @@
text = page.find("pre.request.query_parameters").text
actual = text.split("\n")
expected = table.raw.map { |row| row.join(": ") }
+
actual.should =~ expected
end
@@ -45,3 +48,11 @@
Then /^I should see the following response body:$/ do |response_body|
page.should have_css("div.response.body", :text => response_body)
end
+
+Then /^I should see the api name "(.*?)"$/ do |name|
+ title = find("title").text
+ header = find("h1").text
+
+ title.should eq(name)
+ header.should eq(name)
+end
View
1 lib/rspec_api_documentation/configuration.rb
@@ -58,6 +58,7 @@ def self.add_setting(name, opts = {})
add_setting :curl_host, :default => nil
add_setting :keep_source_order, :default => false
+ add_setting :api_name, :default => "API Documentation"
def settings
@settings ||= {}
View
4 lib/rspec_api_documentation/html_writer.rb
@@ -35,6 +35,10 @@ def initialize(index, configuration)
self.template_path = configuration.template_path
end
+ def api_name
+ @configuration.api_name
+ end
+
def sections
IndexWriter.sections(examples, @configuration)
end
View
4 lib/rspec_api_documentation/wurl_writer.rb
@@ -35,6 +35,10 @@ def initialize(index, configuration)
self.template_path = configuration.template_path
end
+ def api_name
+ @configuration.api_name
+ end
+
def sections
IndexWriter.sections(examples, @configuration)
end
View
1 spec/configuration_spec.rb
@@ -51,6 +51,7 @@
its(:curl_host) { should be_nil }
its(:url_prefix) { should be_blank }
its(:keep_source_order) { should be_false }
+ its(:api_name) { should == "API Documentation" }
end
describe "#define_groups" do
View
4 templates/rspec_api_documentation/html_index.mustache
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<html>
<head>
- <title>API Documentation</title>
+ <title>{{ api_name }}</title>
<link rel="stylesheet" href="{{ url_prefix }}/assets/stylesheets/bootstrap.css"/>
</head>
<body>
<div class="container">
- <h1>API Documentation</h1>
+ <h1>{{ api_name }}</h1>
{{# sections }}
<div class="article">
View
4 templates/rspec_api_documentation/wurl_index.mustache
@@ -1,12 +1,12 @@
<!DOCTYPE html>
<html>
<head>
- <title>API Documentation</title>
+ <title>{{ api_name }}</title>
<link rel="stylesheet" href="{{ url_prefix }}/assets/stylesheets/bootstrap.css"/>
</head>
<body>
<div class="container">
- <h1>API Documentation</h1>
+ <h1>{{ api_name }}</h1>
{{# sections }}
<div class="article">

No commit comments for this range

Something went wrong with that request. Please try again.