pacto 0.3.1 → 0.4.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (204) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +3 -0
  3. data/.rubocop.yml +29 -7
  4. data/.travis.yml +8 -1
  5. data/CONTRIBUTING.md +3 -6
  6. data/Gemfile +13 -2
  7. data/Guardfile +4 -4
  8. data/Procfile +1 -0
  9. data/README.md +47 -13
  10. data/Rakefile +66 -19
  11. data/TODO.md +33 -10
  12. data/bin/pacto +4 -0
  13. data/changelog.md +30 -0
  14. data/docs/configuration.md +69 -0
  15. data/docs/consumer.md +18 -0
  16. data/docs/cops.md +39 -0
  17. data/docs/forensics.md +66 -0
  18. data/docs/generation.md +65 -0
  19. data/docs/rake_tasks.md +10 -0
  20. data/docs/rspec.md +0 -0
  21. data/docs/samples.md +133 -0
  22. data/docs/server.md +34 -0
  23. data/docs/server_cli.md +18 -0
  24. data/docs/stenographer.md +20 -0
  25. data/features/configuration/strict_matchers.feature +10 -10
  26. data/features/evolve/existing_services.feature +12 -10
  27. data/features/generate/generation.feature +11 -11
  28. data/features/steps/pacto_steps.rb +17 -12
  29. data/features/stub/templates.feature +4 -4
  30. data/features/support/env.rb +21 -9
  31. data/features/validate/meta_validation.feature +9 -17
  32. data/features/validate/validation.feature +5 -6
  33. data/lib/pacto.rb +41 -33
  34. data/lib/pacto/actor.rb +5 -0
  35. data/lib/pacto/actors/from_examples.rb +67 -0
  36. data/lib/pacto/actors/json_generator.rb +20 -0
  37. data/lib/pacto/cli.rb +75 -0
  38. data/lib/pacto/cli/helpers.rb +20 -0
  39. data/lib/pacto/consumer.rb +80 -0
  40. data/lib/pacto/consumer/faraday_driver.rb +34 -0
  41. data/lib/pacto/contract.rb +48 -20
  42. data/lib/pacto/contract_builder.rb +125 -0
  43. data/lib/pacto/contract_factory.rb +31 -12
  44. data/lib/pacto/contract_files.rb +1 -0
  45. data/lib/pacto/contract_set.rb +12 -0
  46. data/lib/pacto/cops.rb +46 -0
  47. data/lib/pacto/cops/body_cop.rb +23 -0
  48. data/lib/pacto/cops/request_body_cop.rb +10 -0
  49. data/lib/pacto/cops/response_body_cop.rb +10 -0
  50. data/lib/pacto/{validators/response_header_validator.rb → cops/response_header_cop.rb} +9 -15
  51. data/lib/pacto/cops/response_status_cop.rb +18 -0
  52. data/lib/pacto/core/configuration.rb +16 -5
  53. data/lib/pacto/core/contract_registry.rb +13 -32
  54. data/lib/pacto/core/hook.rb +1 -0
  55. data/lib/pacto/core/http_middleware.rb +23 -0
  56. data/lib/pacto/core/investigation_registry.rb +60 -0
  57. data/lib/pacto/core/modes.rb +1 -0
  58. data/lib/pacto/core/pacto_request.rb +59 -0
  59. data/lib/pacto/core/pacto_response.rb +41 -0
  60. data/lib/pacto/dash.rb +9 -0
  61. data/lib/pacto/erb_processor.rb +1 -0
  62. data/lib/pacto/exceptions/invalid_contract.rb +1 -0
  63. data/lib/pacto/extensions.rb +3 -16
  64. data/lib/pacto/forensics/investigation_filter.rb +90 -0
  65. data/lib/pacto/forensics/investigation_matcher.rb +80 -0
  66. data/lib/pacto/generator.rb +31 -53
  67. data/lib/pacto/generator/filters.rb +8 -7
  68. data/lib/pacto/generator/hint.rb +26 -0
  69. data/lib/pacto/generator/native_contract_generator.rb +74 -0
  70. data/lib/pacto/hooks/erb_hook.rb +2 -1
  71. data/lib/pacto/investigation.rb +49 -0
  72. data/lib/pacto/logger.rb +1 -0
  73. data/lib/pacto/meta_schema.rb +12 -6
  74. data/lib/pacto/native_contract_factory.rb +60 -0
  75. data/lib/pacto/observers/stenographer.rb +42 -0
  76. data/lib/pacto/provider.rb +27 -0
  77. data/lib/pacto/rake_task.rb +25 -70
  78. data/lib/pacto/request_clause.rb +31 -29
  79. data/lib/pacto/request_pattern.rb +20 -3
  80. data/lib/pacto/resettable.rb +22 -0
  81. data/lib/pacto/response_clause.rb +5 -12
  82. data/lib/pacto/rspec.rb +38 -31
  83. data/lib/pacto/server.rb +4 -0
  84. data/lib/pacto/stubs/uri_pattern.rb +21 -11
  85. data/lib/pacto/stubs/webmock_adapter.rb +69 -34
  86. data/lib/pacto/swagger_contract_factory.rb +90 -0
  87. data/lib/pacto/test_helper.rb +37 -0
  88. data/lib/pacto/ui.rb +32 -2
  89. data/lib/pacto/uri.rb +2 -1
  90. data/lib/pacto/version.rb +2 -1
  91. data/pacto-server.gemspec +24 -0
  92. data/pacto.gemspec +13 -9
  93. data/resources/contract_schema.json +46 -18
  94. data/resources/draft-04.json +150 -0
  95. data/sample_apis/album/cover_api.rb +12 -0
  96. data/sample_apis/config.ru +25 -0
  97. data/sample_apis/echo_api.rb +26 -0
  98. data/sample_apis/files_api.rb +50 -0
  99. data/sample_apis/hello_api.rb +14 -0
  100. data/sample_apis/ping_api.rb +11 -0
  101. data/sample_apis/reverse_api.rb +20 -0
  102. data/samples/README.md +11 -0
  103. data/samples/Rakefile +2 -0
  104. data/samples/configuration.rb +33 -0
  105. data/samples/consumer.rb +15 -0
  106. data/samples/contracts/README.md +1 -0
  107. data/samples/contracts/contract.js +93 -0
  108. data/samples/contracts/get_album_cover.json +48 -0
  109. data/samples/contracts/localhost/api/echo.json +37 -0
  110. data/samples/contracts/localhost/api/ping.json +38 -0
  111. data/samples/cops.rb +30 -0
  112. data/samples/forensics.rb +54 -0
  113. data/samples/generation.rb +48 -0
  114. data/samples/rake_tasks.sh +7 -0
  115. data/samples/rspec.rb +1 -0
  116. data/samples/samples.rb +92 -0
  117. data/samples/scripts/bootstrap +2 -0
  118. data/samples/scripts/wrapper +11 -0
  119. data/samples/server.rb +24 -0
  120. data/samples/server_cli.sh +12 -0
  121. data/samples/stenographer.rb +17 -0
  122. data/spec/coveralls_helper.rb +1 -0
  123. data/spec/fabricators/contract_fabricator.rb +94 -0
  124. data/spec/fabricators/http_fabricator.rb +48 -0
  125. data/spec/fabricators/webmock_fabricator.rb +24 -0
  126. data/spec/{unit/data → fixtures/contracts}/contract.json +2 -2
  127. data/spec/fixtures/contracts/contract_with_examples.json +58 -0
  128. data/spec/{unit/data → fixtures/contracts}/simple_contract.json +5 -3
  129. data/spec/{integration/data → fixtures/contracts}/strict_contract.json +5 -3
  130. data/spec/{integration/data → fixtures/contracts}/templating_contract.json +3 -2
  131. data/spec/{integration/data/simple_contract.json → fixtures/deprecated_contracts/deprecated_contract.json} +2 -1
  132. data/spec/fixtures/swagger/petstore.yaml +101 -0
  133. data/spec/integration/e2e_spec.rb +19 -20
  134. data/spec/integration/forensics/integration_matcher_spec.rb +90 -0
  135. data/spec/integration/rspec_spec.rb +22 -25
  136. data/spec/integration/templating_spec.rb +7 -6
  137. data/spec/pacto/dummy_server.rb +4 -0
  138. data/spec/pacto/{server → dummy_server}/dummy.rb +7 -6
  139. data/spec/pacto/dummy_server/jruby_workaround_helper.rb +23 -0
  140. data/spec/pacto/{server → dummy_server}/playback_servlet.rb +3 -2
  141. data/spec/spec_helper.rb +16 -7
  142. data/spec/unit/actors/from_examples_spec.rb +70 -0
  143. data/spec/unit/actors/json_generator_spec.rb +105 -0
  144. data/spec/unit/pacto/actor_spec.rb +23 -0
  145. data/spec/unit/pacto/configuration_spec.rb +7 -6
  146. data/spec/unit/pacto/consumer/faraday_driver_spec.rb +40 -0
  147. data/spec/unit/pacto/contract_builder_spec.rb +89 -0
  148. data/spec/unit/pacto/contract_factory_spec.rb +62 -11
  149. data/spec/unit/pacto/contract_files_spec.rb +1 -0
  150. data/spec/unit/pacto/contract_set_spec.rb +36 -0
  151. data/spec/unit/pacto/contract_spec.rb +51 -39
  152. data/spec/unit/pacto/cops/body_cop_spec.rb +107 -0
  153. data/spec/unit/pacto/{validators/response_header_validator_spec.rb → cops/response_header_cop_spec.rb} +30 -19
  154. data/spec/unit/pacto/cops/response_status_cop_spec.rb +26 -0
  155. data/spec/unit/pacto/cops_spec.rb +75 -0
  156. data/spec/unit/pacto/core/configuration_spec.rb +6 -5
  157. data/spec/unit/pacto/core/contract_registry_spec.rb +16 -83
  158. data/spec/unit/pacto/core/http_middleware_spec.rb +36 -0
  159. data/spec/unit/pacto/core/investigation_spec.rb +62 -0
  160. data/spec/unit/pacto/core/modes_spec.rb +5 -4
  161. data/spec/unit/pacto/erb_processor_spec.rb +3 -2
  162. data/spec/unit/pacto/extensions_spec.rb +10 -20
  163. data/spec/unit/pacto/generator/filters_spec.rb +11 -10
  164. data/spec/unit/pacto/generator/native_contract_generator_spec.rb +171 -0
  165. data/spec/unit/{hooks → pacto/hooks}/erb_hook_spec.rb +18 -11
  166. data/spec/unit/pacto/investigation_registry_spec.rb +77 -0
  167. data/spec/unit/pacto/logger_spec.rb +6 -5
  168. data/spec/unit/pacto/meta_schema_spec.rb +5 -4
  169. data/spec/unit/pacto/native_contract_factory_spec.rb +26 -0
  170. data/spec/unit/pacto/pacto_spec.rb +13 -28
  171. data/spec/unit/pacto/request_clause_spec.rb +16 -51
  172. data/spec/unit/pacto/request_pattern_spec.rb +6 -5
  173. data/spec/unit/pacto/response_clause_spec.rb +6 -19
  174. data/spec/unit/pacto/server/playback_servlet_spec.rb +21 -18
  175. data/spec/unit/pacto/stubs/observers/stenographer_spec.rb +33 -0
  176. data/spec/unit/pacto/stubs/uri_pattern_spec.rb +39 -11
  177. data/spec/unit/pacto/stubs/webmock_adapter_spec.rb +67 -117
  178. data/spec/unit/pacto/swagger_contract_factory_spec.rb +56 -0
  179. data/spec/unit/pacto/uri_spec.rb +1 -0
  180. data/tasks/release.rake +57 -0
  181. metadata +247 -76
  182. data/.rubocop-todo.yml +0 -24
  183. data/.ruby-gemset +0 -1
  184. data/.ruby-version +0 -1
  185. data/CHANGELOG +0 -12
  186. data/features/validate/body_only.feature +0 -85
  187. data/lib/pacto/contract_list.rb +0 -17
  188. data/lib/pacto/contract_validator.rb +0 -29
  189. data/lib/pacto/core/validation_registry.rb +0 -40
  190. data/lib/pacto/stubs/webmock_helper.rb +0 -69
  191. data/lib/pacto/validation.rb +0 -54
  192. data/lib/pacto/validators/body_validator.rb +0 -49
  193. data/lib/pacto/validators/request_body_validator.rb +0 -26
  194. data/lib/pacto/validators/response_body_validator.rb +0 -26
  195. data/lib/pacto/validators/response_status_validator.rb +0 -24
  196. data/spec/pacto/server.rb +0 -2
  197. data/spec/unit/pacto/contract_list_spec.rb +0 -35
  198. data/spec/unit/pacto/contract_validator_spec.rb +0 -85
  199. data/spec/unit/pacto/core/validation_registry_spec.rb +0 -76
  200. data/spec/unit/pacto/core/validation_spec.rb +0 -60
  201. data/spec/unit/pacto/generator_spec.rb +0 -132
  202. data/spec/unit/pacto/stubs/webmock_helper_spec.rb +0 -20
  203. data/spec/unit/pacto/validators/body_validator_spec.rb +0 -118
  204. data/spec/unit/pacto/validators/response_status_validator_spec.rb +0 -20
@@ -1,24 +0,0 @@
1
- # This configuration was generated by `rubocop --auto-gen-config`.
2
- # The point is for the user to remove these configuration records
3
- # one by one as the offences are removed from the code base.
4
-
5
- Documentation:
6
- Enabled: false
7
-
8
- DotPosition:
9
- Enabled: false
10
-
11
- Encoding:
12
- Enabled: false
13
-
14
- HashSyntax:
15
- Enabled: false
16
-
17
- IfUnlessModifier:
18
- Enabled: false
19
-
20
- LineLength:
21
- Enabled: false
22
-
23
- SpaceInsideHashLiteralBraces:
24
- Enabled: false
@@ -1 +0,0 @@
1
- pacto
@@ -1 +0,0 @@
1
- 2.1.0
data/CHANGELOG DELETED
@@ -1,12 +0,0 @@
1
- 0.3.1
2
-
3
- Enhancements:
4
- * #103 - Display file URI instead of meaningless schema identifier in messages
5
-
6
- Bug Fixes:
7
- * #102 - Fix rake pacto:generate task
8
-
9
-
10
- 0.3.0
11
-
12
- First stable release
@@ -1,85 +0,0 @@
1
- Feature: Validation
2
-
3
- You can validate just the body of the contract. This may be useful if you want to validate a stubbing system that does not stub the fully connection, or if Pacto is currently unable to validate your headers.
4
-
5
- Background:
6
- Given a file named "Gemfile" with:
7
- """ruby
8
- source 'https://rubygems.org'
9
-
10
- gem 'pacto', :path => '../..'
11
- gem 'excon'
12
- """
13
- Given a file named "validate.rb" with:
14
- """ruby
15
- require 'pacto'
16
- require_relative 'my_service'
17
-
18
- contract_list = Pacto.load_contracts('contracts', 'http://example.com')
19
- contract_list.stub_all
20
-
21
- contract = contract_list.contracts.first
22
- service = MyService.new
23
- response = service.hello
24
- successful = contract.validate_consumer nil, response, :body_only => true
25
- puts "Validated successfully!" if successful
26
- """
27
- Given a file named "contracts/template.json" with:
28
- """json
29
- {
30
- "request": {
31
- "method": "GET",
32
- "path": "/hello",
33
- "headers": {
34
- "Accept": "application/json"
35
- },
36
- "params": {}
37
- },
38
-
39
- "response": {
40
- "status": 200,
41
- "headers": { "Content-Type": "application/json" },
42
- "body": {
43
- "type": "object",
44
- "required": true,
45
- "properties": {
46
- "message": { "type": "string", "required": true
47
- }
48
- }
49
- }
50
- }
51
- }
52
- """
53
-
54
- Scenario: Validate the response body only
55
- # This should be in the Before block, but https://github.com/cucumber/cucumber/issues/52
56
- Given I successfully run `bundle install --local`
57
- Given a file named "my_service.rb" with:
58
- """ruby
59
- require 'excon'
60
- class MyService
61
- def response(params={})
62
- body = params[:body] || {}
63
- status = params[:status] || 200
64
- headers = params[:headers] || {}
65
-
66
- response = Excon::Response.new(:body => body, :headers => headers, :status => status)
67
- if params.has_key?(:expects) && ![*params[:expects]].include?(response.status)
68
- raise(Excon::Errors.status_error(params, response))
69
- else response
70
- end
71
- end
72
-
73
- def hello
74
- body = {
75
- 'message' => 'Hi!'
76
- }
77
- response({:body => body})
78
- end
79
- end
80
- """
81
- When I run `bundle exec ruby validate.rb`
82
- Then the output should contain:
83
- """
84
- Validated successfully!
85
- """
@@ -1,17 +0,0 @@
1
- module Pacto
2
- class ContractList
3
- attr_reader :contracts
4
-
5
- def initialize(contracts)
6
- @contracts = contracts
7
- end
8
-
9
- def stub_all(values = {})
10
- contracts.each { |contract| contract.stub_contract!(values) }
11
- end
12
-
13
- def validate_all
14
- contracts.map { |contract| contract.validate_provider }
15
- end
16
- end
17
- end
@@ -1,29 +0,0 @@
1
- module Pacto
2
- class ContractValidator
3
- class << self
4
- def validate(contract, request, response, opts)
5
- env = {
6
- :contract => contract,
7
- :actual_request => request,
8
- :actual_response => response,
9
- :validation_results => []
10
- }
11
- validation_stack(opts).call env
12
- env[:validation_results].compact
13
- end
14
-
15
- private
16
-
17
- def validation_stack(opts)
18
- Middleware::Builder.new do
19
- use Pacto::Validators::RequestBodyValidator
20
- unless opts[:body_only]
21
- use Pacto::Validators::ResponseStatusValidator
22
- use Pacto::Validators::ResponseHeaderValidator
23
- end
24
- use Pacto::Validators::ResponseBodyValidator
25
- end
26
- end
27
- end
28
- end
29
- end
@@ -1,40 +0,0 @@
1
- module Pacto
2
- class ValidationRegistry
3
- include Singleton
4
- include Logger
5
- attr_reader :validations
6
-
7
- def initialize
8
- @validations = []
9
- end
10
-
11
- def reset!
12
- @validations.clear
13
- end
14
-
15
- def validated?(request_pattern)
16
- matched_validations = @validations.select do |validation|
17
- request_pattern.matches? validation.request
18
- end
19
- matched_validations unless matched_validations.empty?
20
- end
21
-
22
- def register_validation(validation)
23
- @validations << validation
24
- logger.info "Detected #{validation.summary}"
25
- validation
26
- end
27
-
28
- def unmatched_validations
29
- @validations.select do |validation|
30
- validation.contract.nil?
31
- end
32
- end
33
-
34
- def failed_validations
35
- @validations.select do |validation|
36
- !validation.successful?
37
- end
38
- end
39
- end
40
- end
@@ -1,69 +0,0 @@
1
- module Pacto
2
- module Stubs
3
- class WebMockHelper
4
- class << self
5
- include Logger
6
-
7
- def validate(request_signature, response)
8
- pacto_response = webmock_to_pacto_response(response)
9
- contract = Pacto.contracts_for(request_signature).first
10
- validation = Validation.new request_signature, pacto_response, contract
11
- Pacto::ValidationRegistry.instance.register_validation validation
12
- end
13
-
14
- def generate(request_signature, response)
15
- logger.debug("Generating Contract for #{request_signature}, #{response}")
16
- begin
17
- contract_file = load_contract_file(request_signature)
18
-
19
- unless File.exists? contract_file
20
- generate_contract(request_signature, response, contract_file)
21
- end
22
- rescue => e
23
- logger.error("Error while generating Contract #{contract_file}: #{e.message}")
24
- logger.error("Backtrace: #{e.backtrace}")
25
- end
26
- end
27
-
28
- private
29
-
30
- def generate_contract(request_signature, response, contract_file)
31
- uri = URI(request_signature.uri)
32
- pacto_request = webmock_to_pacto_request(request_signature)
33
- pacto_response = webmock_to_pacto_response(response)
34
- generator = Pacto::Generator.new
35
- FileUtils.mkdir_p(File.dirname contract_file)
36
- File.write(contract_file, generator.save(uri, pacto_request, pacto_response))
37
- logger.debug("Generating #{contract_file}")
38
-
39
- Pacto.load_contract contract_file, uri.host
40
- end
41
-
42
- def load_contract_file(request_signature)
43
- uri = URI(request_signature.uri)
44
- basename = File.basename(uri.path, '.json') + '.json'
45
- File.join(Pacto.configuration.contracts_path, uri.host, File.dirname(uri.path), basename)
46
- end
47
-
48
- def webmock_to_pacto_request(webmock_request)
49
- uri = webmock_request.uri
50
- Faraday::Request.create webmock_request.method do |req|
51
- req.path = uri.path
52
- req.params = uri.query_values
53
- req.headers = webmock_request.headers
54
- req.body = webmock_request.body
55
- end
56
- end
57
-
58
- def webmock_to_pacto_response(webmock_response)
59
- status, _description = webmock_response.status
60
- Faraday::Response.new(
61
- :status => status,
62
- :response_headers => webmock_response.headers || {},
63
- :body => webmock_response.body
64
- )
65
- end
66
- end
67
- end
68
- end
69
- end
@@ -1,54 +0,0 @@
1
- module Pacto
2
- class Validation
3
- include Logger
4
- attr_reader :request, :response, :contract, :results
5
-
6
- def initialize(request, response, contract)
7
- @request = request
8
- @response = response
9
- @contract = contract
10
- validate unless contract.nil?
11
- end
12
-
13
- def successful?
14
- @results.nil? || @results.empty?
15
- end
16
-
17
- def against_contract?(contract_pattern)
18
- unless @contract.nil?
19
- case contract_pattern
20
- when String
21
- @contract if @contract.file.eql? contract_pattern
22
- when Regexp
23
- @contract if @contract.file =~ contract_pattern
24
- end
25
- end
26
- end
27
-
28
- def to_s
29
- contract_name = @contract.nil? ? 'nil' : contract.name
30
- """
31
- Validation:
32
- \tRequest: #{@request}
33
- \tContract: #{contract_name}
34
- \tResults: \n\t\t#{@results.join "\n\t\t"}
35
- """
36
- end
37
-
38
- def summary
39
- if @contract.nil?
40
- "Missing contract for services provided by #{@request.uri.host}"
41
- else
42
- status = successful? ? 'successful' : 'unsuccessful'
43
- "#{status} validation of #{@contract.name}"
44
- end
45
- end
46
-
47
- private
48
-
49
- def validate
50
- logger.debug("Validating #{@request}, #{@response} against #{@contract}")
51
- @results = contract.validate_consumer(@request, @response)
52
- end
53
- end
54
- end
@@ -1,49 +0,0 @@
1
- module Pacto
2
- module Validators
3
- class BodyValidator
4
- def self.section_name
5
- fail 'section name should be provided by subclass'
6
- end
7
-
8
- def self.subschema(contract)
9
- fail 'override to return the proper subschema the contract'
10
- end
11
-
12
- # FIXME: https://github.com/thoughtworks/pacto/issues/10#issuecomment-31281238
13
- # rubocop:disable MethodLenth
14
- def self.validate(contract, body)
15
- schema = subschema(contract)
16
- if schema
17
- schema['id'] = contract.file unless schema.key? 'id'
18
- if schema['type'] && schema['type'] == 'string'
19
- validate_as_pure_string schema, body.body
20
- else
21
- validate_as_json(schema, body)
22
- end
23
- end || []
24
- end
25
- # rubocop:enable MethodLenth
26
-
27
- private
28
-
29
- def self.validate_as_pure_string(schema, body)
30
- errors = []
31
- if schema['required'] && body.nil?
32
- errors << "The #{section_name} does not contain a body"
33
- end
34
-
35
- pattern = schema['pattern']
36
- if pattern && !(body =~ Regexp.new(pattern))
37
- errors << "The #{section_name} does not match the pattern #{pattern}"
38
- end
39
-
40
- errors
41
- end
42
-
43
- def self.validate_as_json(schema, body)
44
- body = body.body if body.respond_to? :body
45
- JSON::Validator.fully_validate(schema, body, :version => :draft3)
46
- end
47
- end
48
- end
49
- end
@@ -1,26 +0,0 @@
1
- module Pacto
2
- module Validators
3
- class RequestBodyValidator < BodyValidator
4
- def initialize(app)
5
- @app = app
6
- end
7
-
8
- def self.section_name
9
- 'request'
10
- end
11
-
12
- def self.subschema(contract)
13
- contract.request.schema
14
- end
15
-
16
- def call(env)
17
- if env[:validation_results].empty? # skip body validation if we already have other errors
18
- actual_body = env[:actual_request]
19
- errors = self.class.validate(env[:contract], actual_body)
20
- env[:validation_results].concat errors.compact
21
- end
22
- @app.call env
23
- end
24
- end
25
- end
26
- end
@@ -1,26 +0,0 @@
1
- module Pacto
2
- module Validators
3
- class ResponseBodyValidator < BodyValidator
4
- def initialize(app)
5
- @app = app
6
- end
7
-
8
- def self.section_name
9
- 'response'
10
- end
11
-
12
- def self.subschema(contract)
13
- contract.response.schema
14
- end
15
-
16
- def call(env)
17
- if env[:validation_results].empty? # skip body validation if we already have other errors
18
- actual_body = env[:actual_response]
19
- errors = self.class.validate(env[:contract], actual_body)
20
- env[:validation_results].concat errors.compact
21
- end
22
- @app.call env
23
- end
24
- end
25
- end
26
- end