lib/rspec_api_docs/after.rb in rspec-api-docs-0.1.0 vs lib/rspec_api_docs/after.rb in rspec-api-docs-0.2.0

- old
+ new

@@ -1,10 +1,27 @@ +require 'rspec_api_docs/after/type_checker' + module RspecApiDocs - After = -> (example) do - metadata = example.metadata[METADATA_NAMESPACE] + UndocumentedParameter = Class.new(BaseError) - if metadata + class After + Hook = -> (example) do + metadata = example.metadata[METADATA_NAMESPACE] + return unless metadata + metadata[:requests] ||= [] metadata[:requests] << [last_request, last_response] + + return unless RspecApiDocs.configuration.validate_params + + metadata[:requests].each do |request, response| + request.params.each do |key, value| + if metadata[:parameters] && metadata[:parameters].has_key?(key.to_sym) + After::TypeChecker.call(type: metadata[:parameters][key.to_sym][:type], value: value) + else + raise UndocumentedParameter, "undocumented parameter included in request #{key.inspect}" + end + end + end end end end