openapi_rspec 0.4 → 0.6.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
  SHA256:
3
- metadata.gz: 6bea441305836e75d93b65e38d4cb5297c16501228e286d6f444d2870a2bfc30
4
- data.tar.gz: 3fa60f7de6682ba67b56b17562ad5e35d0548a51e8e61a5afe3f5462a38cbd36
3
+ metadata.gz: ed454989937d48a4eeef30f34682c4bff0f7e2a40da349eea0eeb8b5a19afb8d
4
+ data.tar.gz: 4df1828cf06d45281a58b9f3f90c2a8f8d89ca1271303611087e0c90d17d5d2d
5
5
  SHA512:
6
- metadata.gz: 6df382e223c149c2c250b8bb97a19470be4d784fe8bdd0cebc1161b806f69aef13cc13f6ca299a9c8f3df9792d2606bb64ecb893183d669769fb4b95aed27a6f
7
- data.tar.gz: e4cf9b350d38b189fdf73e451143ccd5388e19104f9b557f62636e41791cfc2d28aec5e3e813f0868dc95eaa84165b3471585f3fa74b5f445e0e1743ac7f59a0
6
+ metadata.gz: 667444e7e303fbb92082a8c1a1dd796633cafaf532bdfdecae27521c1c5f3e2b70a70816e63c460ec75f414a9a869b834d1864829bd6958e34d3e1f9885e8765
7
+ data.tar.gz: 3f4328e0214bf15036c8f628bc034dadf497fab685737122cb6f5e80330024ca8328baa832b8b91716a5c80ba0da83c974ae47a2c6fe2c17b95578e7d893e6f3
data/README.md CHANGED
@@ -1,12 +1,10 @@
1
1
  [gem]: https://rubygems.org/gems/openapi_rspec
2
- [travis]: https://travis-ci.org/medsolutions/openapi_rspec
3
- [codeclimate]: https://codeclimate.com/github/medsolutions/openapi_rspec
2
+ [codeclimate]: https://codeclimate.com/github/skryukov/openapi_rspec
4
3
 
5
4
  # openapi_rspec
6
5
  [![Gem Version](https://badge.fury.io/rb/openapi_rspec.svg)][gem]
7
- [![Build Status](https://travis-ci.org/medsolutions/openapi_rspec.svg?branch=master)][travis]
8
- [![Code Climate](https://codeclimate.com/github/medsolutions/openapi_rspec/badges/gpa.svg)][codeclimate]
9
- [![Test Coverage](https://codeclimate.com/github/medsolutions/openapi_rspec/badges/coverage.svg)][codeclimate]
6
+ [![Build](https://github.com/skryukov/openapi_rspec/workflows/Build/badge.svg)](https://github.com/skryukov/openapi_rspec/actions)
7
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/testdouble/standard)
10
8
 
11
9
  Test your API against OpenApi v3 documentation
12
10
 
@@ -147,7 +145,7 @@ To validate response use:
147
145
  # ...
148
146
  ```
149
147
 
150
- To set **request body** use `params` helper method:
148
+ To set **request body** (as form data) use `params` helper method and provide a `Hash`:
151
149
 
152
150
  ```ruby
153
151
  # ...
@@ -159,6 +157,19 @@ To set **request body** use `params` helper method:
159
157
  # ...
160
158
  ```
161
159
 
160
+ To set **raw request body** use the `params` helper method and provide a `String`:
161
+
162
+ ```ruby
163
+ # ...
164
+ post "/pets" do
165
+ params { JSON.dump(name: "Lucky") }
166
+
167
+ validate_code(201)
168
+ end
169
+ # ...
170
+ ```
171
+
172
+
162
173
  To set **path parameter** use `let` helper method:
163
174
 
164
175
  ```ruby
@@ -252,7 +263,7 @@ This will raise an error if any of the documented paths are not validated.
252
263
 
253
264
  ## Contributing
254
265
 
255
- Bug reports and pull requests are welcome on GitHub at https://github.com/medsolutions/openapi_rspec.
266
+ Bug reports and pull requests are welcome on GitHub at https://github.com/skryukov/openapi_rspec.
256
267
 
257
268
  ## License
258
269
 
@@ -8,7 +8,7 @@ module OpenapiRspec
8
8
  end
9
9
 
10
10
  def description
11
- 'be a valid OpenAPI documentation'
11
+ "be a valid OpenAPI documentation"
12
12
  end
13
13
 
14
14
  def failure_message
@@ -5,10 +5,12 @@ module OpenapiRspec
5
5
  def request_params(metadata)
6
6
  path = defined?(uri) ? uri : metadata[:uri]
7
7
  method = defined?(http_method) ? http_method : metadata[:method]
8
+
8
9
  {
9
10
  method: method,
10
11
  path: path,
11
- params: path_params(path).merge!(openapi_rspec_params),
12
+ params: openapi_rspec_params,
13
+ path_params: path_params(path),
12
14
  headers: openapi_rspec_headers,
13
15
  query: openapi_rspec_query,
14
16
  media_type: openapi_rspec_media_type
@@ -17,7 +19,7 @@ module OpenapiRspec
17
19
 
18
20
  def path_params(path)
19
21
  path_params = {}
20
- path.scan(/\{([^\}]*)\}/).each do |param|
22
+ path.scan(/\{([^}]*)\}/).each do |param|
21
23
  key = param.first.to_sym
22
24
  path_params[key] = public_send(key) if respond_to?(key)
23
25
  end
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'openapi_rspec/documentation_validator'
4
- require 'openapi_rspec/request_validator'
3
+ require "openapi_rspec/documentation_validator"
4
+ require "openapi_rspec/request_validator"
5
5
 
6
6
  module OpenapiRspec
7
7
  module Matchers
@@ -7,7 +7,7 @@ module OpenapiRspec
7
7
  metadata = example.metadata[:openapi_rspec]
8
8
  validator = RequestValidator.new(**request_params(metadata), code: code)
9
9
  expect(subject).to validator
10
- instance_exec validator, &block if block_given?
10
+ instance_exec validator, &block if block
11
11
  end
12
12
  end
13
13
 
@@ -52,8 +52,8 @@ module OpenapiRspec
52
52
  end
53
53
 
54
54
  def process(method, uri)
55
- metadata[:openapi_rspec] = { uri: uri, method: method }
56
- let(:openapi_rspec_media_type) { 'application/json' }
55
+ metadata[:openapi_rspec] = {uri: uri, method: method}
56
+ let(:openapi_rspec_media_type) { "application/json" }
57
57
  let(:openapi_rspec_params) { {} }
58
58
  let(:openapi_rspec_headers) { {} }
59
59
  let(:openapi_rspec_query) { {} }
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry-initializer'
4
- require 'rack/test'
5
- require 'uri'
3
+ require "dry-initializer"
4
+ require "rack/test"
5
+ require "uri"
6
6
 
7
7
  module OpenapiRspec
8
8
  class RequestValidator
@@ -13,6 +13,7 @@ module OpenapiRspec
13
13
  option :method
14
14
  option :code
15
15
  option :media_type
16
+ option :path_params
16
17
  option :params
17
18
  option :query
18
19
  option :headers
@@ -46,27 +47,27 @@ module OpenapiRspec
46
47
 
47
48
  private
48
49
 
50
+ def perform_request(doc)
51
+ headers.each do |key, value|
52
+ header key, value
53
+ end
54
+ request(request_uri(doc), method: method, **request_params)
55
+ @response = last_response
56
+ end
57
+
49
58
  def request_uri(doc)
50
- path.scan(/\{([^\}]*)\}/).each do |param|
59
+ path.scan(/\{([^}]*)\}/).each do |param|
51
60
  key = param.first.to_sym
52
- if params && params[key]
53
- @path = path.gsub "{#{key}}", params.delete(key).to_s
61
+ if path_params && path_params[key]
62
+ @path = path.gsub "{#{key}}", path_params[key].to_s
54
63
  else
55
- raise URI::InvalidURIError, "No substitution data found for {#{key}}"\
64
+ raise URI::InvalidURIError, "No substitution data found for {#{key}}" \
56
65
  " to test the path #{path}."
57
66
  end
58
67
  end
59
68
  "#{doc.api_base_path}#{path}?#{URI.encode_www_form(query)}"
60
69
  end
61
70
 
62
- def perform_request(doc)
63
- headers.each do |key, value|
64
- header key, value
65
- end
66
- request(request_uri(doc), method: method, **request_params)
67
- @response = last_response
68
- end
69
-
70
71
  def request_params
71
72
  {
72
73
  headers: headers,
@@ -13,7 +13,7 @@ module OpenapiRspec
13
13
  rescue JSON::ParserError
14
14
  YAML.safe_load(schema)
15
15
  end
16
- rescue StandardError => e
16
+ rescue => e
17
17
  raise "Unable to parse OpenAPI schema. #{e}"
18
18
  end
19
19
 
@@ -22,10 +22,10 @@ module OpenapiRspec
22
22
  response = session.get(path)
23
23
 
24
24
  raise "Response code: #{response.status}" unless response.successful?
25
- raise 'Empty body' if response.body.empty?
25
+ raise "Empty body" if response.body.empty?
26
26
 
27
27
  response.body
28
- rescue StandardError => e
28
+ rescue => e
29
29
  raise "Unable to perform GET request for the OpenAPI schema '#{path}'. #{e}"
30
30
  end
31
31
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenapiRspec
4
- VERSION = '0.4'
4
+ VERSION = "0.6.0"
5
5
  end
data/lib/openapi_rspec.rb CHANGED
@@ -1,14 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'dry-configurable'
4
- require 'openapi_validator'
5
- require 'rspec'
3
+ require "dry-configurable"
4
+ require "openapi_validator"
5
+ require "rspec"
6
6
 
7
- require 'openapi_rspec/helpers'
8
- require 'openapi_rspec/matchers'
9
- require 'openapi_rspec/module_helpers'
10
- require 'openapi_rspec/schema_loader'
11
- require 'openapi_rspec/version'
7
+ require "openapi_rspec/helpers"
8
+ require "openapi_rspec/matchers"
9
+ require "openapi_rspec/module_helpers"
10
+ require "openapi_rspec/schema_loader"
11
+ require "openapi_rspec/version"
12
12
 
13
13
  module OpenapiRspec
14
14
  extend Dry::Configurable
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openapi_rspec
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.4'
4
+ version: 0.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svyatoslav Kryukov
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-10-07 00:00:00.000000000 Z
11
+ date: 2022-11-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '1.1'
61
+ version: '2.0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '1.1'
68
+ version: '2.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -98,17 +98,17 @@ dependencies:
98
98
  name: rake
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - "~>"
101
+ - - ">="
102
102
  - !ruby/object:Gem::Version
103
- version: '10.0'
103
+ version: 12.3.3
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - "~>"
108
+ - - ">="
109
109
  - !ruby/object:Gem::Version
110
- version: '10.0'
111
- description:
110
+ version: 12.3.3
111
+ description:
112
112
  email:
113
113
  - s.g.kryukov@yandex.ru
114
114
  executables: []
@@ -129,7 +129,7 @@ homepage: https://github.com/medsolutions/openapi_rspec
129
129
  licenses:
130
130
  - MIT
131
131
  metadata: {}
132
- post_install_message:
132
+ post_install_message:
133
133
  rdoc_options: []
134
134
  require_paths:
135
135
  - lib
@@ -144,8 +144,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  - !ruby/object:Gem::Version
145
145
  version: '0'
146
146
  requirements: []
147
- rubygems_version: 3.0.3
148
- signing_key:
147
+ rubygems_version: 3.3.7
148
+ signing_key:
149
149
  specification_version: 4
150
150
  summary: Test your API against OpenApi v3 documentation
151
151
  test_files: []