module Rswag3::Specs::ExampleGroupHelpers
Public Instance Methods
content(value)
click to toggle source
# File lib/rswag3/specs/example_group_helpers.rb, line 65 def content(value) metadata[:response][:content] = value end
description(value=nil)
click to toggle source
NOTE: 'description' requires special treatment because ExampleGroup already defines a method with that name. Provide an override that supports the existing functionality while also setting the appropriate metadata if applicable
Calls superclass method
# File lib/rswag3/specs/example_group_helpers.rb, line 26 def description(value=nil) return super() if value.nil? metadata[:operation][:description] = value end
examples(example = nil)
click to toggle source
NOTE: Similar to 'description', 'examples' need to handle the case when being invoked with no params to avoid overriding 'examples' method of rspec-core ExampleGroup
Calls superclass method
# File lib/rswag3/specs/example_group_helpers.rb, line 77 def examples(example = nil) return super() if example.nil? metadata[:response][:examples] = example end
header(name, attributes)
click to toggle source
# File lib/rswag3/specs/example_group_helpers.rb, line 69 def header(name, attributes) metadata[:response][:headers] ||= {} metadata[:response][:headers][name] = attributes end
parameter(attributes)
click to toggle source
# File lib/rswag3/specs/example_group_helpers.rb, line 42 def parameter(attributes) if attributes[:in] && attributes[:in].to_sym == :path attributes[:required] = true end if metadata.has_key?(:operation) metadata[:operation][:parameters] ||= [] metadata[:operation][:parameters] << attributes else metadata[:path_item][:parameters] ||= [] metadata[:path_item][:parameters] << attributes end end
path(template, metadata={}, &block)
click to toggle source
# File lib/rswag3/specs/example_group_helpers.rb, line 5 def path(template, metadata={}, &block) metadata[:path_item] = { template: template } describe(template, metadata, &block) end
requestBody(value)
click to toggle source
# File lib/rswag3/specs/example_group_helpers.rb, line 38 def requestBody(value) metadata[:operation][:requestBody] = value end
response(code, description, metadata={}, &block)
click to toggle source
# File lib/rswag3/specs/example_group_helpers.rb, line 56 def response(code, description, metadata={}, &block) metadata[:response] = { code: code, description: description } context(description, metadata, &block) end
run_test!(&block)
click to toggle source
# File lib/rswag3/specs/example_group_helpers.rb, line 82 def run_test!(&block) # NOTE: rspec 2.x support if RSPEC_VERSION < 3 before do submit_request(example.metadata) end it "returns a #{metadata[:response][:code]} response" do assert_response_matches_metadata(metadata) block.call(response) if block_given? end else before do |example| submit_request(example.metadata) end it "returns a #{metadata[:response][:code]} response" do |example| assert_response_matches_metadata(example.metadata, &block) example.instance_exec(response, &block) if block_given? end end end
schema(value)
click to toggle source
# File lib/rswag3/specs/example_group_helpers.rb, line 61 def schema(value) metadata[:response][:schema] = value end