rspec_api_documentation 4.2.0 → 4.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33e8850c767dbaf09a5469f45db448b6119a1d9d
4
- data.tar.gz: 7b83d526470ad8734fa2bdaa8c22d48792da4dd7
3
+ metadata.gz: cb2fb26b05b35089944ce6878bb2d866b2c64831
4
+ data.tar.gz: af9e4d78d7b53feb8233e9bf0770b1b0d168fbd7
5
5
  SHA512:
6
- metadata.gz: c75314c9d799bc9296b7b3217e08261cf0df0b6bb4ba3ece99faaf36f2b08fa31a4ffba57a4b745bf877aa919937ecbbe2237ccd66bd62e0ad62d27da34c04a8
7
- data.tar.gz: 50ef1cca010fb51adaaf3d8776e17d6fb5ed6b89baa65d377b5eb4153d59c0ea4396e482f206f6592d8044df50258ade305466e324f03789627dc7c7396cafcb
6
+ metadata.gz: 9677cb19ce2dc7e77067feaa666cda455ea57bf018b16119f2b94a1d188fb1e8d433e1cba207a400f43e7050a0161d19b391744940257e0734a31b6749eb92f5
7
+ data.tar.gz: 381d5c452e78ebd9ea62f8435d41211cb1c28ab48de53f0b8bd392a44ef89fd297bdf9b789e1305caf5e6ac5f50904ea023b08bc9a99e5804367705ef7a1b992
@@ -19,6 +19,7 @@ module RspecApiDocumentation
19
19
  autoload :Index
20
20
  autoload :ClientBase
21
21
  autoload :Headers
22
+ autoload :HttpTestClient
22
23
  end
23
24
 
24
25
  autoload :DSL
@@ -43,12 +43,16 @@ module RspecApiDocumentation
43
43
  document_example(method.to_s.upcase, path)
44
44
  end
45
45
 
46
+ def read_request_body
47
+ input = last_request.env["rack.input"]
48
+ input.rewind
49
+ input.read
50
+ end
51
+
46
52
  def document_example(method, path)
47
53
  return unless metadata[:document]
48
54
 
49
- input = last_request.env["rack.input"]
50
- input.rewind
51
- request_body = input.read
55
+ request_body = read_request_body
52
56
 
53
57
  request_metadata = {}
54
58
 
@@ -58,7 +62,7 @@ module RspecApiDocumentation
58
62
 
59
63
  request_metadata[:request_method] = method
60
64
  request_metadata[:request_path] = path
61
- request_metadata[:request_body] = request_body.empty? ? nil : request_body
65
+ request_metadata[:request_body] = request_body.empty? ? nil : request_body.force_encoding("UTF-8")
62
66
  request_metadata[:request_headers] = request_headers
63
67
  request_metadata[:request_query_parameters] = query_hash
64
68
  request_metadata[:request_content_type] = request_content_type
@@ -1,26 +1,36 @@
1
+ require "rspec_api_documentation"
1
2
  require "rspec_api_documentation/dsl/resource"
2
3
  require "rspec_api_documentation/dsl/endpoint"
3
4
  require "rspec_api_documentation/dsl/callback"
4
5
 
5
- # Custom describe block that sets metadata to enable the rest of RAD
6
- #
7
- # resource "Orders", :meta => :data do
8
- # # ...
9
- # end
10
- #
11
- # Params:
12
- # +args+:: Glob of RSpec's `describe` arguments
13
- # +block+:: Block to pass into describe
14
- #
15
- def self.resource(*args, &block)
16
- options = if args.last.is_a?(Hash) then args.pop else {} end
17
- options[:api_doc_dsl] = :resource
18
- options[:resource_name] = args.first
19
- options[:document] ||= :all
20
- args.push(options)
21
- describe(*args, &block)
6
+
7
+ module RspecApiDocumentation
8
+ module DSL
9
+
10
+ # Custom describe block that sets metadata to enable the rest of RAD
11
+ #
12
+ # resource "Orders", :meta => :data do
13
+ # # ...
14
+ # end
15
+ #
16
+ # Params:
17
+ # +args+:: Glob of RSpec's `describe` arguments
18
+ # +block+:: Block to pass into describe
19
+ #
20
+ def resource(*args, &block)
21
+ options = if args.last.is_a?(Hash) then args.pop else {} end
22
+ options[:api_doc_dsl] = :resource
23
+ options[:resource_name] = args.first
24
+ options[:document] ||= :all
25
+ args.push(options)
26
+ describe(*args, &block)
27
+ end
28
+ end
22
29
  end
23
30
 
31
+ RSpec::Core::ExampleGroup.extend(RspecApiDocumentation::DSL)
32
+ RSpec::Core::DSL.expose_example_group_alias(:resource)
33
+
24
34
  RSpec.configuration.include RspecApiDocumentation::DSL::Resource, :api_doc_dsl => :resource
25
35
  RSpec.configuration.include RspecApiDocumentation::DSL::Endpoint, :api_doc_dsl => :endpoint
26
36
  RSpec.configuration.include RspecApiDocumentation::DSL::Callback, :api_doc_dsl => :callback
@@ -0,0 +1,120 @@
1
+ begin
2
+ require 'faraday'
3
+ rescue LoadError
4
+ raise "Faraday needs to be installed before using the HttpTestClient"
5
+ end
6
+
7
+ Faraday::Request.register_middleware :request_saver => lambda { RspecApiDocumentation::RequestSaver }
8
+
9
+ module RspecApiDocumentation
10
+ class RequestSaver < Faraday::Middleware
11
+ attr_reader :client
12
+
13
+ def initialize(app, client)
14
+ super(app)
15
+ @client = client
16
+ end
17
+
18
+ def call(env)
19
+ client.last_request = env
20
+
21
+ @app.call(env).on_complete do |env|
22
+ client.last_response = env
23
+ end
24
+ end
25
+ end
26
+
27
+ class HttpTestClient < ClientBase
28
+ attr_reader :last_response, :last_request
29
+
30
+ LastRequest = Struct.new(:url, :method, :request_headers, :body)
31
+
32
+ def request_headers
33
+ env_to_headers(last_request.request_headers)
34
+ end
35
+
36
+ def response_headers
37
+ last_response.response_headers
38
+ end
39
+
40
+ def query_string
41
+ last_request.url.query
42
+ end
43
+
44
+ def status
45
+ last_response.status
46
+ end
47
+
48
+ def response_body
49
+ last_response.body
50
+ end
51
+
52
+ def request_content_type
53
+ last_request.request_headers["CONTENT_TYPE"]
54
+ end
55
+
56
+ def response_content_type
57
+ last_response.request_headers["CONTENT_TYPE"]
58
+ end
59
+
60
+ def do_request(method, path, params, request_headers)
61
+ http_test_session.send(method, path, params, headers(method, path, params, request_headers))
62
+ end
63
+
64
+ def last_request=(env)
65
+ @last_request = LastRequest.new(env.url, env.method, env.request_headers, env.body)
66
+ end
67
+
68
+ def last_response=(env)
69
+ @last_response = env
70
+ end
71
+
72
+ protected
73
+
74
+ def headers(*args)
75
+ headers_to_env(super)
76
+ end
77
+
78
+ def handle_multipart_body(request_headers, request_body)
79
+ parsed_parameters = Rack::Request.new({
80
+ "CONTENT_TYPE" => request_headers["Content-Type"],
81
+ "rack.input" => StringIO.new(request_body)
82
+ }).params
83
+
84
+ clean_out_uploaded_data(parsed_parameters, request_body)
85
+ end
86
+
87
+ def read_request_body
88
+ if [:post, :put].include?(last_request.method)
89
+ last_request.body || ""
90
+ else
91
+ ""
92
+ end
93
+ end
94
+
95
+ private
96
+
97
+ def clean_out_uploaded_data(params, request_body)
98
+ params.each do |_, value|
99
+ if value.is_a?(Hash)
100
+ if value.has_key?(:tempfile)
101
+ data = value[:tempfile].read
102
+ request_body = request_body.gsub(data, "[uploaded data]")
103
+ else
104
+ request_body = clean_out_uploaded_data(value,request_body)
105
+ end
106
+ end
107
+ end
108
+ request_body
109
+ end
110
+
111
+
112
+ def http_test_session
113
+ ::Faraday.new(:url => options[:host]) do |faraday|
114
+ faraday.request :url_encoded # form-encode POST params
115
+ faraday.request :request_saver, self # save the request and response
116
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
117
+ end
118
+ end
119
+ end
120
+ end
@@ -4,7 +4,7 @@
4
4
  <title>{{resource_name}} API</title>
5
5
  <meta charset="utf-8">
6
6
  <style>
7
- {{ styles }}
7
+ {{{ styles }}}
8
8
  </style>
9
9
  </head>
10
10
  <body>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rspec_api_documentation
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Cahoon
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2014-09-24 00:00:00.000000000 Z
13
+ date: 2014-10-09 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -206,6 +206,34 @@ dependencies:
206
206
  - - "~>"
207
207
  - !ruby/object:Gem::Version
208
208
  version: '1.0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: faraday
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: 0.9.0
216
+ type: :development
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: 0.9.0
223
+ - !ruby/object:Gem::Dependency
224
+ name: thin
225
+ requirement: !ruby/object:Gem::Requirement
226
+ requirements:
227
+ - - ">="
228
+ - !ruby/object:Gem::Version
229
+ version: '0'
230
+ type: :development
231
+ prerelease: false
232
+ version_requirements: !ruby/object:Gem::Requirement
233
+ requirements:
234
+ - - ">="
235
+ - !ruby/object:Gem::Version
236
+ version: '0'
209
237
  description: Generate API docs from your test suite
210
238
  email:
211
239
  - chris@smartlogicsolutions.com
@@ -228,6 +256,7 @@ files:
228
256
  - lib/rspec_api_documentation/dsl/resource.rb
229
257
  - lib/rspec_api_documentation/example.rb
230
258
  - lib/rspec_api_documentation/headers.rb
259
+ - lib/rspec_api_documentation/http_test_client.rb
231
260
  - lib/rspec_api_documentation/index.rb
232
261
  - lib/rspec_api_documentation/oauth2_mac_client.rb
233
262
  - lib/rspec_api_documentation/rack_test_client.rb