avocado-docs 2.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,46 @@
1
+ module Avocado
2
+ class Middleware::RequestSerialization
3
+
4
+ def call(example, request, response)
5
+ @request = request
6
+ Avocado::Cache.json.merge! request: serialize(@request)
7
+ yield
8
+ end
9
+
10
+ private
11
+
12
+ def serialize(request)
13
+ {
14
+ method: request.method,
15
+ path: request.path,
16
+ params: sanitize_params(request.params).to_h,
17
+ headers: headers
18
+ }
19
+ end
20
+
21
+ def headers
22
+ hash = {}
23
+ Avocado::Config.headers.each do |name|
24
+ hash[name] = @request.headers.env["HTTP_#{name.tr('-', '_')}".upcase]
25
+ end
26
+ hash.select { |_, value| !value.nil? }
27
+ end
28
+
29
+ def sanitize_params(params)
30
+ params = params.except(*Avocado::Config.ignored_params.flatten)
31
+ deep_replace_file_uploads_with_text(params)
32
+ params
33
+ end
34
+
35
+ def deep_replace_file_uploads_with_text(hash)
36
+ hash.each do |k, v|
37
+ if Hash === v
38
+ deep_replace_file_uploads_with_text(v)
39
+ else
40
+ hash[k] = '<Multipart File Upload>' if v.respond_to? :path
41
+ end
42
+ end
43
+ end
44
+
45
+ end
46
+ end
@@ -0,0 +1,22 @@
1
+ module Avocado
2
+ class Middleware::ResourceSerialization
3
+
4
+ def call(example, request, response)
5
+ name = infer_name_from_route(request.path, request.method) || ""
6
+ Avocado::Cache.json.merge! resource: { name: name }
7
+ yield
8
+ end
9
+
10
+ private
11
+
12
+ def infer_name_from_route(path, method)
13
+ controller = Rails.application.routes.recognize_path(path, method: method)[:controller]
14
+ name = controller.partition('/').reject(&:blank?).last
15
+ name.titleize.split('/').last
16
+ rescue ActionController::RoutingError
17
+ puts "Path #{path} not found in controller routes; Defaulting name to path."
18
+ path
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ module Avocado
2
+ class Middleware::ResponseSerialization
3
+
4
+ def call(example, request, response)
5
+ Avocado::Cache.json.merge! response: serialize(response)
6
+ yield
7
+ end
8
+
9
+ private
10
+
11
+ def serialize(response)
12
+ {
13
+ status: response.status,
14
+ body: response.body
15
+ }
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,27 @@
1
+ RSpec.configure do |config|
2
+
3
+ config.before(:suite) do
4
+ ActionController::Base.send :include, Avocado::Controller
5
+ ActionController::API.send :include, Avocado::Controller if defined?(ActionController::API)
6
+ end
7
+
8
+ # Invoke all middleware with the request/response stored from the after_action in the controller
9
+ # The final action is to store the request JSON in the Avocado module until after(:suite) executes
10
+ config.after(:each) do |ex|
11
+ _example = defined?(example) ? example : ex
12
+ request = Avocado::Cache.request
13
+ response = Avocado::Cache.response
14
+
15
+ if request && response
16
+ Avocado::Middleware.invoke(_example, request, response) do
17
+ Avocado.payload << Avocado::Cache.json
18
+ end
19
+ end
20
+
21
+ Avocado::Cache.clean
22
+ end
23
+
24
+ # Upload avocado.yml to the configured URL if one is given
25
+ config.after(:suite) { Avocado.upload! }
26
+
27
+ end
@@ -0,0 +1,26 @@
1
+ module Avocado
2
+ class Uploader
3
+
4
+ def upload(filename)
5
+ WebMock.allow_net_connect!
6
+ uri = URI.parse Avocado::Config.url
7
+ file = File.open(filename)
8
+ req = Net::HTTP::Post::Multipart.new uri.path, 'file' => UploadIO.new(file, 'text/yaml', 'avocado.yml')
9
+ Net::HTTP.start(uri.host, uri.port) { |http| http.request(req) }
10
+ ensure
11
+ WebMock.disable_net_connect!
12
+ file.close
13
+ File.delete file.path
14
+ end
15
+
16
+ private
17
+
18
+ def uri
19
+ @uri ||= URI.parse Avocado::Config.url
20
+ rescue URI::InvalidURIError
21
+ raise "Avocado::Config.url is set but is not a valid URL!"
22
+ end
23
+
24
+ end
25
+ end
26
+
@@ -0,0 +1,3 @@
1
+ module Avocado
2
+ VERSION = "2.0.5"
3
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: avocado-docs
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.5
5
+ platform: ruby
6
+ authors:
7
+ - Logan Serman
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: multipart-post
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '1.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '2.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '2.14'
69
+ - !ruby/object:Gem::Dependency
70
+ name: combustion
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.5'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '1.15'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '1.15'
97
+ description: Avocado listens for JSON responses in the test environment and generates
98
+ a YAML file describing them, which it sends to a configurable URL.
99
+ email:
100
+ - loganserman@gmail.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - app/assets/javascripts/avocado/application.js
106
+ - app/assets/stylesheets/avocado/application.css.scss
107
+ - app/assets/stylesheets/avocado/bootstrap.css
108
+ - app/controllers/avocado/avocado_controller.rb
109
+ - app/controllers/avocado/specs_controller.rb
110
+ - app/helpers/avocado/application_helper.rb
111
+ - app/models/avocado/endpoint.rb
112
+ - app/models/avocado/parser.rb
113
+ - app/models/avocado/request.rb
114
+ - app/models/avocado/resource.rb
115
+ - app/views/layouts/avocado/avocado.html.erb
116
+ - app/views/template.html.erb
117
+ - config/routes.rb
118
+ - lib/avocado/cache.rb
119
+ - lib/avocado/config.rb
120
+ - lib/avocado/controller.rb
121
+ - lib/avocado/engine.rb
122
+ - lib/avocado/middleware/defaults.rb
123
+ - lib/avocado/middleware/document_if_configuration.rb
124
+ - lib/avocado/middleware/document_metadata.rb
125
+ - lib/avocado/middleware/example_serialization.rb
126
+ - lib/avocado/middleware/request_serialization.rb
127
+ - lib/avocado/middleware/resource_serialization.rb
128
+ - lib/avocado/middleware/response_serialization.rb
129
+ - lib/avocado/middleware.rb
130
+ - lib/avocado/rspec.rb
131
+ - lib/avocado/uploader.rb
132
+ - lib/avocado/version.rb
133
+ - lib/avocado.rb
134
+ - MIT-LICENSE
135
+ - Rakefile
136
+ homepage: http://github.com/metova/avocado
137
+ licenses: []
138
+ metadata: {}
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - '>='
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '>='
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.0.0
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: Automatic API documentation from RSpec tests
159
+ test_files: []