Class: OpenapiRuby::Adapters::RSpec::OperationProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/openapi_ruby/adapters/rspec.rb

Instance Method Summary collapse

Constructor Details

#initialize(example_group, operation_context, path_context) ⇒ OperationProxy

Returns a new instance of OperationProxy.



70
71
72
73
74
# File 'lib/openapi_ruby/adapters/rspec.rb', line 70

def initialize(example_group, operation_context, path_context)
  @example_group = example_group
  @operation = operation_context
  @path_context = path_context
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name) ⇒ Object (private)



103
104
105
106
107
108
109
# File 'lib/openapi_ruby/adapters/rspec.rb', line 103

def method_missing(name, ...)
  if @example_group.respond_to?(name)
    @example_group.send(name, ...)
  else
    super
  end
end

Instance Method Details

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



87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/openapi_ruby/adapters/rspec.rb', line 87

def response(status_code, description, &block)
  response_ctx = @operation.response(status_code, description)
  operation = @operation

  @example_group.context "response #{status_code} #{description}" do
    [:openapi_operation] = operation
    [:openapi_response] = response_ctx

    # Evaluate response-level DSL
    resp_proxy = ResponseProxy.new(self, response_ctx)
    resp_proxy.instance_eval(&block) if block
  end
end