Module: Swagalicious::ExampleGroupHelpers
- Defined in:
- lib/swagalicious/example_group_helpers.rb
Instance Method Summary collapse
-
#description(value = nil) ⇒ Object
NOTE: ‘description’ requires special treatment because ExampleGroup already defines a method with that name.
-
#examples(example = nil) ⇒ Object
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.
- #header(name, attributes) ⇒ Object
- #parameter(attributes) ⇒ Object
- #path(template, metadata = {}, &block) ⇒ Object
- #response(code, description, metadata = {}, &block) ⇒ Object
- #schema(value) ⇒ Object
- #validate_schema!(mocked: false, mock_name: nil) ⇒ Object
Instance Method Details
#description(value = nil) ⇒ Object
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
24 25 26 27 |
# File 'lib/swagalicious/example_group_helpers.rb', line 24 def description(value=nil) return super() if value.nil? [:operation][:description] = value end |
#examples(example = nil) ⇒ Object
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
69 70 71 72 |
# File 'lib/swagalicious/example_group_helpers.rb', line 69 def examples(example = nil) return super() if example.nil? [:response][:examples] = example end |
#header(name, attributes) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/swagalicious/example_group_helpers.rb', line 59 def header(name, attributes) header_name = attributes.delete(:variable) || name [:response][:headers] ||= {} [:response][:headers][header_name] = attributes end |
#parameter(attributes) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/swagalicious/example_group_helpers.rb', line 36 def parameter(attributes) if attributes[:in] && attributes[:in].to_sym == :path attributes[:required] = true end if .has_key?(:operation) [:operation][:parameters] ||= [] [:operation][:parameters] << attributes else [:path_item][:parameters] ||= [] [:path_item][:parameters] << attributes end end |
#path(template, metadata = {}, &block) ⇒ Object
3 4 5 6 |
# File 'lib/swagalicious/example_group_helpers.rb', line 3 def path(template, ={}, &block) [:path_item] = { template: template } describe(template, , &block) end |
#response(code, description, metadata = {}, &block) ⇒ Object
50 51 52 53 |
# File 'lib/swagalicious/example_group_helpers.rb', line 50 def response(code, description, ={}, &block) [:response] = { code: code, description: description } context(description, , &block) end |
#schema(value) ⇒ Object
55 56 57 |
# File 'lib/swagalicious/example_group_helpers.rb', line 55 def schema(value) [:response][:schema] = value end |
#validate_schema!(mocked: false, mock_name: nil) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/swagalicious/example_group_helpers.rb', line 74 def validate_schema!(mocked: false, mock_name: nil) it "returns a #{[:response][:code]} response" do |example| yield if block_given? submit_request(example., mocked: mocked, mock_name: mock_name) end end |