Module: OpenapiRspec::ModuleHelpers

Defined in:
lib/openapi_rspec/module_helpers.rb

Instance Method Summary collapse

Instance Method Details

#delete(*args, &block) ⇒ Object



42
43
44
# File 'lib/openapi_rspec/module_helpers.rb', line 42

def delete(*args, &block)
  process(:delete, *args, &block)
end

#get(*args, &block) ⇒ Object



30
31
32
# File 'lib/openapi_rspec/module_helpers.rb', line 30

def get(*args, &block)
  process(:get, *args, &block)
end

#head(*args, &block) ⇒ Object



46
47
48
# File 'lib/openapi_rspec/module_helpers.rb', line 46

def head(*args, &block)
  process(:head, *args, &block)
end

#headers(&block) ⇒ Object



22
23
24
# File 'lib/openapi_rspec/module_helpers.rb', line 22

def headers(&block)
  let(:openapi_rspec_headers, &block)
end

#media_type(&block) ⇒ Object



18
19
20
# File 'lib/openapi_rspec/module_helpers.rb', line 18

def media_type(&block)
  let(:openapi_rspec_media_type, &block)
end

#params(&block) ⇒ Object



14
15
16
# File 'lib/openapi_rspec/module_helpers.rb', line 14

def params(&block)
  let(:openapi_rspec_params, &block)
end

#patch(*args, &block) ⇒ Object



50
51
52
# File 'lib/openapi_rspec/module_helpers.rb', line 50

def patch(*args, &block)
  process(:patch, *args, &block)
end

#post(*args, &block) ⇒ Object



34
35
36
# File 'lib/openapi_rspec/module_helpers.rb', line 34

def post(*args, &block)
  process(:post, *args, &block)
end

#process(method, uri) ⇒ Object



54
55
56
57
58
59
60
61
62
63
# File 'lib/openapi_rspec/module_helpers.rb', line 54

def process(method, uri)
  [:openapi_rspec] = {uri: uri, method: method}
  let(:openapi_rspec_media_type) { "application/json" }
  let(:openapi_rspec_params) { {} }
  let(:openapi_rspec_headers) { {} }
  let(:openapi_rspec_query) { {} }
  context "#{method.to_s.upcase} #{uri}" do
    yield if block_given?
  end
end

#put(*args, &block) ⇒ Object



38
39
40
# File 'lib/openapi_rspec/module_helpers.rb', line 38

def put(*args, &block)
  process(:put, *args, &block)
end

#query(&block) ⇒ Object



26
27
28
# File 'lib/openapi_rspec/module_helpers.rb', line 26

def query(&block)
  let(:openapi_rspec_query, &block)
end

#validate_code(code, &block) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/openapi_rspec/module_helpers.rb', line 5

def validate_code(code, &block)
  specify do |example|
     = example.[:openapi_rspec]
    validator = RequestValidator.new(**request_params(), code: code)
    expect(subject).to validator
    instance_exec validator, &block if block
  end
end