Skip to content

Commit cd433b2

Browse files
committed
Add wURL console to raddocs
1 parent 2597cca commit cd433b2

Some content is hidden

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

44 files changed

+20966
-218
lines changed

Gemfile.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ PATH
33
specs:
44
rspec_api_documentation (0.5.2)
55
activesupport (>= 3.0.0)
6-
coderay (>= 1.0.7.rc1)
76
i18n (>= 0.1.0)
87
json (>= 1.4.6)
98
mustache (>= 0.99.4)
@@ -33,7 +32,6 @@ GEM
3332
xpath (~> 0.1.4)
3433
childprocess (0.3.2)
3534
ffi (~> 1.0.6)
36-
coderay (1.0.7.rc1)
3735
crack (0.3.1)
3836
cucumber (1.2.0)
3937
builder (>= 2.1.2)

example/Gemfile.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ PATH
33
specs:
44
rspec_api_documentation (0.5.2)
55
activesupport (>= 3.0.0)
6-
coderay (>= 1.0.7.rc1)
76
i18n (>= 0.1.0)
87
json (>= 1.4.6)
98
mustache (>= 0.99.4)
@@ -44,7 +43,6 @@ GEM
4443
addressable (2.2.8)
4544
arel (2.2.1)
4645
builder (3.0.0)
47-
coderay (1.0.7.rc1)
4846
coffee-rails (3.1.1)
4947
coffee-script (>= 2.2.0)
5048
railties (~> 3.1.0)

example/spec/acceptance/orders_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
scope_parameters :order, :all
4040

4141
example_request "Creating an order" do
42+
explanation "First, create an order, then make a later request to get it back"
4243
response_body.should be_json_eql({
4344
"name" => name,
4445
"paid" => paid,

example/spec/spec_helper.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
end
3434

3535
RspecApiDocumentation.configure do |config|
36+
config.docs_dir = Rails.root.join("public", "docs")
3637
config.format = [:html, :json]
3738
config.url_prefix = "docs/"
3839
config.curl_host = 'http://localhost:3000'

example/test/fixtures/.gitkeep

Whitespace-only changes.

example/test/functional/.gitkeep

Whitespace-only changes.

example/test/integration/.gitkeep

Whitespace-only changes.

example/test/performance/browsing_test.rb

Lines changed: 0 additions & 12 deletions
This file was deleted.

example/test/test_helper.rb

Lines changed: 0 additions & 13 deletions
This file was deleted.

example/test/unit/.gitkeep

Whitespace-only changes.

example/vendor/assets/stylesheets/.gitkeep

Whitespace-only changes.

example/vendor/plugins/.gitkeep

Whitespace-only changes.

features/callbacks.feature

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,5 @@ Feature: Document callbacks
6666
| User-Agent | InterestingThingApp |
6767
And I should see the following request body:
6868
"""
69-
{
70-
"message": "Something interesting happened!"
71-
}
69+
{"message":"Something interesting happened!"}
7270
"""

features/html_documentation.feature

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,5 @@ Feature: Generate HTML documentation from test examples
8080
| Content-Length | 35 |
8181
And I should see the following response body:
8282
"""
83-
{
84-
"hello": "rspec_api_documentation"
85-
}
83+
{"hello":"rspec_api_documentation"}
8684
"""

gemfiles/minimum_dependencies

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ gem "i18n", "0.3.6"
88
gem "mustache", "0.99.4"
99
gem "webmock", "1.8.0"
1010
gem "json", "1.4.6"
11-
gem "coderay", "1.0.7.rc1"
1211
gem "rack-test", "0.5.5"
1312
gem "rack-oauth2", "0.14.4"
1413

lib/rspec_api_documentation.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ module RspecApiDocumentation
1818
autoload :Index
1919
autoload :ClientBase
2020
autoload :Headers
21-
autoload :Syntax
2221
end
2322

2423
autoload :DSL

lib/rspec_api_documentation/api_documentation.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def clear_docs
1414
FileUtils.rm_rf(docs_dir, :secure => true)
1515
end
1616
FileUtils.mkdir_p(docs_dir)
17+
FileUtils.cp_r(File.join(configuration.template_path, "assets"), docs_dir)
1718
end
1819

1920
def document_example(rspec_example)

lib/rspec_api_documentation/client_base.rb

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module RspecApiDocumentation
22
class ClientBase < Struct.new(:context, :options)
33
include Headers
4-
include Syntax
54

65
delegate :example, :app, :to => :context
76
delegate :metadata, :to => :example
@@ -40,13 +39,15 @@ def document_example(method, path, params)
4039

4140
request_metadata[:request_method] = method
4241
request_metadata[:request_path] = path
43-
request_metadata[:request_body] = highlight_syntax(request_body, content_type, true)
44-
request_metadata[:request_headers] = format_headers(request_headers)
45-
request_metadata[:request_query_parameters] = format_query_hash(query_hash)
42+
request_metadata[:request_body] = request_body.empty? ? nil : request_body
43+
request_metadata[:request_headers] = request_headers
44+
request_metadata[:request_query_parameters] = query_hash
45+
request_metadata[:request_content_type] = request_content_type
4646
request_metadata[:response_status] = status
4747
request_metadata[:response_status_text] = Rack::Utils::HTTP_STATUS_CODES[status]
48-
request_metadata[:response_body] = highlight_syntax(response_body, response_headers['Content-Type'])
49-
request_metadata[:response_headers] = format_headers(response_headers)
48+
request_metadata[:response_body] = response_body.empty? ? nil : response_body
49+
request_metadata[:response_headers] = response_headers
50+
request_metadata[:response_content_type] = response_content_type
5051
request_metadata[:curl] = Curl.new(method, path, request_body, request_headers)
5152

5253
metadata[:requests] ||= []
@@ -56,18 +57,12 @@ def document_example(method, path, params)
5657
def query_hash
5758
strings = query_string.split("&")
5859
arrays = strings.map do |segment|
59-
segment.split("=")
60+
k,v = segment.split("=")
61+
[k, CGI.unescape(v)]
6062
end
6163
Hash[arrays]
6264
end
6365

64-
def format_query_hash(query_hash)
65-
return if query_hash.blank?
66-
query_hash.map do |key, value|
67-
"#{key}: #{CGI.unescape(value)}"
68-
end.join("\n")
69-
end
70-
7166
def headers(method, path, params)
7267
if options && options[:headers]
7368
options[:headers]

lib/rspec_api_documentation/curl.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ def output(config_host)
1010
end
1111

1212
def post
13-
"curl #{url} #{post_data} -X POST #{headers}"
13+
"curl \"#{url}\" #{post_data} -X POST #{headers}"
1414
end
1515

1616
def get
17-
"curl #{url}#{get_data} -X GET #{headers}"
17+
"curl \"#{url}#{get_data}\" -X GET #{headers}"
1818
end
1919

2020
def put
21-
"curl #{url} #{post_data} -X PUT #{headers}"
21+
"curl \"#{url}\" #{post_data} -X PUT #{headers}"
2222
end
2323

2424
def delete
25-
"curl #{url} -X DELETE #{headers}"
25+
"curl \"#{url}\" #{post_data} -X DELETE #{headers}"
2626
end
2727

2828
def url

lib/rspec_api_documentation/html_writer.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,14 @@ def filename
6969
end
7070

7171
def requests
72-
super.map do |hash|
72+
super.collect do |hash|
73+
hash[:request_headers_hash] = hash[:request_headers].collect { |k, v| {:name => k, :value => v} }
74+
hash[:request_headers_text] = format_hash(hash[:request_headers])
75+
hash[:request_path_no_query] = hash[:request_path].split('?').first
76+
hash[:request_query_parameters_text] = format_hash(hash[:request_query_parameters])
77+
hash[:request_query_parameters_hash] = hash[:request_query_parameters].collect { |k, v| {:name => k, :value => v} } if hash[:request_query_parameters].present?
78+
hash[:response_headers_text] = format_hash(hash[:response_headers])
79+
hash[:response_status] = hash[:response_status].to_s + " " + Rack::Utils::HTTP_STATUS_CODES[hash[:response_status]].to_s
7380
if @host
7481
hash[:curl] = hash[:curl].output(@host) if hash[:curl].is_a? RspecApiDocumentation::Curl
7582
else
@@ -82,5 +89,13 @@ def requests
8289
def url_prefix
8390
configuration.url_prefix
8491
end
92+
93+
private
94+
def format_hash(hash = {})
95+
return "" unless hash.present?
96+
hash.collect do |k, v|
97+
"#{k}: #{v}"
98+
end.join("\n")
99+
end
85100
end
86101
end

lib/rspec_api_documentation/oauth2_mac_client.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,14 @@ def response_body
3232
last_response.body
3333
end
3434

35-
def content_type
35+
def request_content_type
3636
last_request.content_type
3737
end
3838

39+
def response_content_type
40+
last_response.content_type
41+
end
42+
3943
protected
4044

4145
def do_request(method, path, params)

lib/rspec_api_documentation/rack_test_client.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,14 @@ def response_body
2424
last_response.body
2525
end
2626

27-
def content_type
27+
def request_content_type
2828
last_request.content_type
2929
end
3030

31+
def response_content_type
32+
last_response.content_type
33+
end
34+
3135
protected
3236

3337
def do_request(method, path, params)

lib/rspec_api_documentation/syntax.rb

Lines changed: 0 additions & 33 deletions
This file was deleted.

lib/rspec_api_documentation/test_server.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module RspecApiDocumentation
22
class TestServer < Struct.new(:context)
33
include Headers
4-
include Syntax
54

65
delegate :example, :to => :context
76
delegate :metadata, :to => :example
@@ -18,10 +17,10 @@ def call(env)
1817

1918
request_metadata = {}
2019

21-
request_metadata[:request_method] = request_method
20+
request_metadata[:request_method] = @request_method
2221
request_metadata[:request_path] = env["PATH_INFO"]
23-
request_metadata[:request_body] = highlight_syntax(request_body, request_headers["Content-Type"], true)
24-
request_metadata[:request_headers] = format_headers(@request_headers)
22+
request_metadata[:request_body] = @request_body
23+
request_metadata[:request_headers] = @request_headers
2524

2625
metadata[:requests] ||= []
2726
metadata[:requests] << request_metadata

rspec_api_documentation.gemspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ Gem::Specification.new do |s|
2020
s.add_runtime_dependency "mustache", ">= 0.99.4"
2121
s.add_runtime_dependency "webmock", ">= 1.7.0"
2222
s.add_runtime_dependency "json", ">= 1.4.6"
23-
s.add_runtime_dependency "coderay", ">= 1.0.7.rc1"
2423

2524
s.add_development_dependency "fakefs"
2625
s.add_development_dependency "sinatra"

spec/api_documentation_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
test_file = configuration.docs_dir.join("test")
1616
FileUtils.mkdir_p configuration.docs_dir
1717
FileUtils.touch test_file
18-
18+
FileUtils.stub(:cp_r)
1919
subject.clear_docs
2020

2121
File.directory?(configuration.docs_dir).should be_true

spec/rack_test_client_spec.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,15 @@ class StubApp < Sinatra::Base
127127
metadata[:request_method].should eq("POST")
128128
metadata[:request_path].should eq("/greet?query=test+query")
129129
metadata[:request_body].should be_present
130-
metadata[:request_headers].should match(/^Content-Type: application\/json/)
131-
metadata[:request_headers].should match(/^X-Custom-Header: custom header value$/)
132-
metadata[:request_query_parameters].should eq("query: test query")
130+
metadata[:request_headers].should include({'Content-Type' => 'application/json;charset=utf-8'})
131+
metadata[:request_headers].should include({'X-Custom-Header' => 'custom header value'})
132+
metadata[:request_query_parameters].should == {"query" => "test query"}
133+
metadata[:request_content_type].should match(/application\/json/)
133134
metadata[:response_status].should eq(200)
134-
metadata[:response_status_text].should eq("OK")
135135
metadata[:response_body].should be_present
136-
metadata[:response_headers].should match(/^Content-Type: application\/json/)
137-
metadata[:response_headers].should match(/^Content-Length: 17$/)
136+
metadata[:response_headers]['Content-Type'].should match(/application\/json/)
137+
metadata[:response_headers]['Content-Length'].should == '17'
138+
metadata[:response_content_type].should match(/application\/json/)
138139
metadata[:curl].should eq(RspecApiDocumentation::Curl.new("POST", "/greet?query=test+query", post_data, {"Content-Type" => "application/json;charset=utf-8", "X-Custom-Header" => "custom header value", "Host" => "example.org", "Cookie" => ""}))
139140
end
140141

@@ -151,8 +152,8 @@ class StubApp < Sinatra::Base
151152
context "when post data is nil" do
152153
let(:post_data) { }
153154

154-
it "should not nil out request_body" do
155-
example.metadata[:requests].first[:request_body].should eq(nil)
155+
it "should nil out request_body" do
156+
example.metadata[:requests].first[:request_body].should be_nil
156157
end
157158
end
158159
end
Loading
13.5 KB
Loading

0 commit comments

Comments
 (0)