Module: Rswag::Specs::ExampleGroupHelpers

Defined in:
lib/rswag/specs/example_group_helpers.rb

Instance Method Summary collapse

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



26
27
28
29
# File 'lib/rswag/specs/example_group_helpers.rb', line 26

def description(value=nil)
  return super() if value.nil?
  [:operation][:description] = value 
end

#header(name, attributes) ⇒ Object



59
60
61
62
# File 'lib/rswag/specs/example_group_helpers.rb', line 59

def header(name, attributes)
  [:response][:headers] ||= {}
  [:response][:headers][name] = attributes
end

#parameter(attributes) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/rswag/specs/example_group_helpers.rb', line 38

def parameter(attributes)
  attributes[:required] = true if attributes[:in].to_sym == :path

  if .has_key?(:operation)
    [:operation][:parameters] ||= []
    [:operation][:parameters] << attributes
  else
    [:path_item][:parameters] ||= []
    [:path_item][:parameters] << attributes
  end
end

#path(template, &block) ⇒ Object



5
6
7
8
# File 'lib/rswag/specs/example_group_helpers.rb', line 5

def path(template, &block)
   = { path_item: { template: template } }
  describe(template, , &block)
end

#response(code, description, &block) ⇒ Object



50
51
52
53
# File 'lib/rswag/specs/example_group_helpers.rb', line 50

def response(code, description, &block)
   = { response: { code: code, description: description } }
  context(description, , &block)
end

#run_test!Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rswag/specs/example_group_helpers.rb', line 64

def run_test!
  # NOTE: rspec 2.x support
  if RSPEC_VERSION < 3
    before do
      submit_request(example.)
    end

    it "returns a #{metadata[:response][:code]} response" do
      (example.)
    end
  else
    before do |example|
      submit_request(example.)
    end

    it "returns a #{metadata[:response][:code]} response" do |example|
      (example.)
    end
  end
end

#schema(value) ⇒ Object



55
56
57
# File 'lib/rswag/specs/example_group_helpers.rb', line 55

def schema(value)
  [:response][:schema] = value
end