openapi_rspec 0.2.0 → 0.2.1

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: 0bc7e1b91f162a32c1d4be8d87814ebd2f62175f4d8846ac570179ee46c2d389
4
- data.tar.gz: 11b302ed09c95e037be7732f0b388b912f076224ac24fb81047e9da70b53c901
3
+ metadata.gz: a8ce3f1674f46c2c7791386f64e694d0170a7693d16b89a5c21923cb23cc58b2
4
+ data.tar.gz: 615878aa004e98712a802c0dd44ca42465edd5b86c5bd6744cfe1f10dd79c953
5
5
  SHA512:
6
- metadata.gz: 3d6edc80d5593740000f0ac64315c9eeab1dd514dc8a49fbedb216f89d10cac8a088fbfefc33ea10c180e8bc74f0238a0c8b9668ebd6a89434e799636c40eea9
7
- data.tar.gz: 020771cf2c6aacdd5aa85f7cbfe8fbd499f46bcfb0096ba29c0f4e9eb03079a8e1d588172cb7df5d9aad3c10034e1fc69eab71c5de87afc4837e41ec0c0a508e
6
+ metadata.gz: d71a291c462a84e94878134ec1e006d0063ee8fb9ef2ba5ece050e821af5b4075d8fcba40670beaa35dfef3cce5d00d369ed12666a0e218e62d8cd98efc82846
7
+ data.tar.gz: e3a4c671f8ffb61f9e1db4c89c857acf6c700c9f02dca499d2f727eb70c924fab8bbc509bf486e960a02e220a4536ec79d448a6b0772b3492dfc880526c0a0e0
@@ -3,18 +3,19 @@ module OpenapiRspec
3
3
  def expect_validate_request(code, metadata: {})
4
4
  expect(subject).to validate_request(**request_params(metadata), code: code)
5
5
  end
6
-
6
+
7
7
  def request_params(metadata)
8
- Hash.new.tap do |hash|
8
+ {}.tap do |hash|
9
9
  hash[:method] = defined?(http_method) ? http_method : metadata[:method]
10
10
  hash[:path] = defined?(uri) ? uri : metadata[:uri]
11
+ hash[:media_type] = openapi_rspec_media_type if defined? openapi_rspec_media_type
11
12
  hash[:params] = path_params(hash[:path])
12
13
  hash[:params].merge!(openapi_rspec_params) if defined? openapi_rspec_params
13
14
  hash[:headers] = openapi_rspec_headers if defined? openapi_rspec_headers
14
15
  hash[:query] = openapi_rspec_query if defined? openapi_rspec_query
15
16
  end
16
17
  end
17
-
18
+
18
19
  def path_params(path)
19
20
  path_params = {}
20
21
  path.scan(/\{([^\}]*)\}/).each do |param|
@@ -10,39 +10,43 @@ module OpenapiRspec
10
10
  def params(&block)
11
11
  let(:openapi_rspec_params, &block)
12
12
  end
13
-
13
+
14
+ def media_type(&block)
15
+ let(:openapi_rspec_media_type, &block)
16
+ end
17
+
14
18
  def headers(&block)
15
19
  let(:openapi_rspec_headers, &block)
16
20
  end
17
-
21
+
18
22
  def query(&block)
19
23
  let(:openapi_rspec_query, &block)
20
24
  end
21
-
25
+
22
26
  def get(*args, &block)
23
27
  process(:get, *args, &block)
24
28
  end
25
-
29
+
26
30
  def post(*args, &block)
27
31
  process(:post, *args, &block)
28
32
  end
29
-
33
+
30
34
  def put(*args, &block)
31
35
  process(:put, *args, &block)
32
36
  end
33
-
37
+
34
38
  def delete(*args, &block)
35
39
  process(:delete, *args, &block)
36
40
  end
37
-
41
+
38
42
  def head(*args, &block)
39
43
  process(:head, *args, &block)
40
44
  end
41
-
45
+
42
46
  def patch(*args, &block)
43
47
  process(:patch, *args, &block)
44
48
  end
45
-
49
+
46
50
  def process(method, uri)
47
51
  metadata[:openapi_rspec] = {
48
52
  uri: uri,
@@ -9,19 +9,21 @@ module OpenapiRspec
9
9
  OpenapiRspec.app
10
10
  end
11
11
 
12
- def initialize(path:, method:, code:, params: {}, query: {}, headers: {})
12
+ def initialize(path:, method:, code:, media_type: "application/json", params: {}, query: {}, headers: {})
13
13
  @path = path
14
14
  @method = method
15
15
  @code = code
16
+ @media_type = media_type
16
17
  @query = query
17
18
  @headers = headers
18
19
  @params = params
19
20
  end
20
21
 
21
- attr_reader :method, :path, :code, :query, :headers, :params
22
+ attr_reader :method, :path, :code, :media_type, :query, :headers, :params
22
23
 
23
24
  def matches?(doc)
24
- @result = doc.validate_request(path: path, method: method, code: code)
25
+ @result = doc.validate_request(path: path, method: method, code: code, media_type: media_type)
26
+
25
27
  return false unless @result.valid?
26
28
 
27
29
  headers.each do |key, value|
@@ -1,3 +1,3 @@
1
1
  module OpenapiRspec
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
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.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Svyatoslav Kryukov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-27 00:00:00.000000000 Z
11
+ date: 2019-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable