Skip to content

Commit a3bdcc4

Browse files
author
Sam Goldman
committed
Add HTML file content matcher and fix unmatched tags in the html example template
1 parent b5561b2 commit a3bdcc4

File tree

3 files changed

+73
-5
lines changed

3 files changed

+73
-5
lines changed

features/html_documentation.feature

Lines changed: 59 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,65 @@ Feature: Generate HTML documentation from test examples
5757

5858
Scenario: Create an index of all API examples, including all resources and examples
5959
Then the file "docs/index.html" should contain "<h2>Greetings</h2>"
60-
And the file "docs/index.html" should contain:
60+
And the file "docs/index.html" should contain HTML:
6161
"""
62-
<a href="greetings/greeting_your_favorite_gem.html">Greeting your favorite gem</a>
62+
<h2>Greetings</h2>
63+
64+
<ul>
65+
<li>
66+
<a href="greetings/greeting_your_favorite_gem.html">Greeting your favorite gem</a>
67+
</li>
68+
</ul>
6369
"""
6470

65-
Scenario: Create a file for each API example
66-
Then the file "docs/greetings/greeting_your_favorite_gem.html" should contain "<h2>Greeting your favorite gem</h2>"
71+
Scenario: Example HTML documentation includes the parameters
72+
Then the file "docs/greetings/greeting_your_favorite_gem.html" should contain HTML:
73+
"""
74+
<h3>Parameters</h3>
75+
<table>
76+
<thead>
77+
<tr>
78+
<th>Name</th>
79+
<th>Description</th>
80+
</tr>
81+
</thead>
82+
<tbody>
83+
<tr>
84+
<th>
85+
<span class="name">target</span>
86+
</th>
87+
<td>
88+
<span class="description">The thing you want to greet</span>
89+
</td>
90+
</tr>
91+
</tbody>
92+
</table>
93+
"""
94+
95+
Scenario: Example HTML documentation includes the request information
96+
Then the file "docs/greetings/greeting_your_favorite_gem.html" should contain HTML:
97+
"""
98+
<h3>Request</h3>
99+
<h4>Headers</h4>
100+
<pre class="headers">Host: example.org
101+
Cookie: </pre>
102+
<h4>Route</h4>
103+
<pre class="request highlight">GET /greetings?target=rspec_api_documentation</pre>
104+
<h4>Query Parameters</h4>
105+
<pre class="request highlight">target: rspec_api_documentation</pre>
106+
"""
107+
108+
Scenario: Example HTML documentation includes the response information
109+
Then the file "docs/greetings/greeting_your_favorite_gem.html" should contain HTML:
110+
"""
111+
<h3>Response</h3>
112+
<h4>Headers</h4>
113+
<pre class="headers">Content-Type: application/json
114+
Content-Length: 35</pre>
115+
<h4>Status</h4>
116+
<pre class="response_status">200 OK</pre>
117+
<h4>Body</h4>
118+
<pre class="response highlight">{
119+
&quot;hello&quot;: &quot;rspec_api_documentation&quot;
120+
}</pre>
121+
"""
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
RSpec::Matchers.define :contain_ignoring_whitespace do |expected|
2+
match do |actual|
3+
insignificant_whitespace = /(^\s*)|(\s*$)/
4+
actual.gsub(insignificant_whitespace, "").should =~ regexp(expected.gsub(insignificant_whitespace, ""))
5+
end
6+
end
7+
8+
Then /^the file "([^"]*)" should contain HTML:$/ do |file, partial_html|
9+
prep_for_fs_check do
10+
content = IO.read(file)
11+
content.should contain_ignoring_whitespace(partial_html)
12+
end
13+
end

templates/rspec_api_documentation/html_example.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
<tbody>
4141
{{# parameters }}
4242
<tr>
43-
<td{{# required }} class="required"{{/ required }}>
43+
<th{{# required }} class="required"{{/ required }}>
4444
<span class="name">{{ name }}</span>
4545
</th>
4646
<td>

0 commit comments

Comments
 (0)