openapi_rspec 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2b9f9ec3e1e0cb9018ac93737caeac7449033514d8394f2059e3f7f26b9e75d0
4
- data.tar.gz: acfb5e12dec63680f74203c8e8d3356b4421952f969237bd3ba5b32c7f74c8d4
3
+ metadata.gz: 0bc7e1b91f162a32c1d4be8d87814ebd2f62175f4d8846ac570179ee46c2d389
4
+ data.tar.gz: 11b302ed09c95e037be7732f0b388b912f076224ac24fb81047e9da70b53c901
5
5
  SHA512:
6
- metadata.gz: 4cba7fc2504377bcb3a975d62c6d04bb8f5bcd8409fc9571a90fc65748427af5feac6c927c3992f57be463e431855b2d4f62628783fd0c13b71d572d58e2c7f1
7
- data.tar.gz: a86a7efecf68cf4330d8efa5bcfa9b86eb6229488f85f6d33eb35d9a69e69dde8c87ed710a5c48a7437134e816084bf01920625cf13a9e4e475c178a537501db
6
+ metadata.gz: 3d6edc80d5593740000f0ac64315c9eeab1dd514dc8a49fbedb216f89d10cac8a088fbfefc33ea10c180e8bc74f0238a0c8b9668ebd6a89434e799636c40eea9
7
+ data.tar.gz: 020771cf2c6aacdd5aa85f7cbfe8fbd499f46bcfb0096ba29c0f4e9eb03079a8e1d588172cb7df5d9aad3c10034e1fc69eab71c5de87afc4837e41ec0c0a508e
data/README.md CHANGED
@@ -1,12 +1,12 @@
1
1
  [gem]: https://rubygems.org/gems/openapi_rspec
2
- [travis]: https://travis-ci.org/llcmedsolutions/openapi_rspec
3
- [codeclimate]: https://codeclimate.com/github/llcmedsolutions/openapi_rspec
2
+ [travis]: https://travis-ci.org/medsolutions/openapi_rspec
3
+ [codeclimate]: https://codeclimate.com/github/medsolutions/openapi_rspec
4
4
 
5
5
  # openapi_rspec
6
6
  [![Gem Version](https://badge.fury.io/rb/openapi_rspec.svg)][gem]
7
- [![Build Status](https://travis-ci.org/llcmedsolutions/openapi_rspec.svg?branch=master)][travis]
8
- [![Code Climate](https://codeclimate.com/github/llcmedsolutions/openapi_rspec/badges/gpa.svg)][codeclimate]
9
- [![Test Coverage](https://codeclimate.com/github/llcmedsolutions/openapi_rspec/badges/coverage.svg)][codeclimate]
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]
10
10
 
11
11
  Test your API against OpenApi v3 documentation
12
12
 
@@ -30,7 +30,7 @@ Or install it yourself as:
30
30
 
31
31
  ## Usage
32
32
 
33
- TODO: Write usage instructions here
33
+ See spec/example_spec.rb
34
34
 
35
35
  ## Development
36
36
 
@@ -40,7 +40,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
40
40
 
41
41
  ## Contributing
42
42
 
43
- Bug reports and pull requests are welcome on GitHub at https://github.com/llcmedsolutions/openapi_rspec.
43
+ Bug reports and pull requests are welcome on GitHub at https://github.com/medsolutions/openapi_rspec.
44
44
 
45
45
  ## License
46
46
 
@@ -0,0 +1,27 @@
1
+ module OpenapiRspec
2
+ module Helpers
3
+ def expect_validate_request(code, metadata: {})
4
+ expect(subject).to validate_request(**request_params(metadata), code: code)
5
+ end
6
+
7
+ def request_params(metadata)
8
+ Hash.new.tap do |hash|
9
+ hash[:method] = defined?(http_method) ? http_method : metadata[:method]
10
+ hash[:path] = defined?(uri) ? uri : metadata[:uri]
11
+ hash[:params] = path_params(hash[:path])
12
+ hash[:params].merge!(openapi_rspec_params) if defined? openapi_rspec_params
13
+ hash[:headers] = openapi_rspec_headers if defined? openapi_rspec_headers
14
+ hash[:query] = openapi_rspec_query if defined? openapi_rspec_query
15
+ end
16
+ end
17
+
18
+ def path_params(path)
19
+ path_params = {}
20
+ path.scan(/\{([^\}]*)\}/).each do |param|
21
+ key = param.first.to_sym
22
+ path_params[key] = public_send(key) if respond_to?(key)
23
+ end
24
+ path_params
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,56 @@
1
+ module OpenapiRspec
2
+ module ModuleHelpers
3
+ def validate_code(code, &block)
4
+ specify do |example|
5
+ expect_validate_request(code, metadata: example.metadata[:openapi_rspec])
6
+ instance_eval &block if block_given?
7
+ end
8
+ end
9
+
10
+ def params(&block)
11
+ let(:openapi_rspec_params, &block)
12
+ end
13
+
14
+ def headers(&block)
15
+ let(:openapi_rspec_headers, &block)
16
+ end
17
+
18
+ def query(&block)
19
+ let(:openapi_rspec_query, &block)
20
+ end
21
+
22
+ def get(*args, &block)
23
+ process(:get, *args, &block)
24
+ end
25
+
26
+ def post(*args, &block)
27
+ process(:post, *args, &block)
28
+ end
29
+
30
+ def put(*args, &block)
31
+ process(:put, *args, &block)
32
+ end
33
+
34
+ def delete(*args, &block)
35
+ process(:delete, *args, &block)
36
+ end
37
+
38
+ def head(*args, &block)
39
+ process(:head, *args, &block)
40
+ end
41
+
42
+ def patch(*args, &block)
43
+ process(:patch, *args, &block)
44
+ end
45
+
46
+ def process(method, uri)
47
+ metadata[:openapi_rspec] = {
48
+ uri: uri,
49
+ method: method
50
+ }
51
+ context "#{method.to_s.upcase} #{uri}" do
52
+ yield if block_given?
53
+ end
54
+ end
55
+ end
56
+ end
@@ -28,8 +28,8 @@ module OpenapiRspec
28
28
  header key, value
29
29
  end
30
30
  request(request_uri(doc), method: method, **request_params)
31
- response = last_response
32
- @result.validate_response(body: response.body, code: response.status)
31
+ @response = last_response
32
+ @result.validate_response(body: @response.body, code: @response.status)
33
33
  @result.valid?
34
34
  end
35
35
 
@@ -58,8 +58,8 @@ module OpenapiRspec
58
58
  end
59
59
 
60
60
  def failure_message
61
- if last_response
62
- (%W(Response: #{last_response.body}) + @result.errors).join("\n")
61
+ if @response
62
+ (%W(Response: #{@response.body}) + @result.errors).join("\n")
63
63
  else
64
64
  @result.errors.join("\n")
65
65
  end
@@ -1,3 +1,3 @@
1
1
  module OpenapiRspec
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/openapi_rspec.rb CHANGED
@@ -3,7 +3,9 @@ require "openapi_validator"
3
3
  require "openapi_builder"
4
4
  require "rspec"
5
5
 
6
+ require "openapi_rspec/helpers"
6
7
  require "openapi_rspec/matchers"
8
+ require "openapi_rspec/module_helpers"
7
9
  require "openapi_rspec/version"
8
10
 
9
11
  module OpenapiRspec
@@ -17,6 +19,8 @@ module OpenapiRspec
17
19
  end
18
20
 
19
21
  RSpec.configure do |config|
22
+ config.extend ModuleHelpers
23
+ config.include Helpers
20
24
  config.include Matchers
21
25
  end
22
26
  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.1.0
4
+ version: 0.2.0
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-15 00:00:00.000000000 Z
11
+ date: 2019-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-configurable
@@ -119,10 +119,12 @@ files:
119
119
  - README.md
120
120
  - lib/openapi_rspec.rb
121
121
  - lib/openapi_rspec/documentation_validator.rb
122
+ - lib/openapi_rspec/helpers.rb
122
123
  - lib/openapi_rspec/matchers.rb
124
+ - lib/openapi_rspec/module_helpers.rb
123
125
  - lib/openapi_rspec/request_validator.rb
124
126
  - lib/openapi_rspec/version.rb
125
- homepage: https://github.com/llcmedsolutions/openapi_rspec
127
+ homepage: https://github.com/medsolutions/openapi_rspec
126
128
  licenses:
127
129
  - MIT
128
130
  metadata: {}