Module: OpenapiFirst::Test::Callable
- Defined in:
- lib/openapi_first/test/callable.rb
Overview
Return a Module with a call method that wrapps silent request/response validation to monitor a Rack app This is used by Openapi::Test.observe
Class Method Summary collapse
-
.[](definition) ⇒ Object
Returns a Module with a ‘call(env)` method that wraps super inside silent request/response validation You can use `Application.prepend(OpenapiFirst::Test::Callable)` to monitor your app during testing.
Class Method Details
.[](definition) ⇒ Object
Returns a Module with a ‘call(env)` method that wraps super inside silent request/response validation You can use `Application.prepend(OpenapiFirst::Test::Callable)` to monitor your app during testing.
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/openapi_first/test/callable.rb', line 10 def self.[](definition) Module.new.tap do |mod| mod.define_method(:call) do |env| request = Rack::Request.new(env) definition.validate_request(request, raise_error: false) response = super(env) status, headers, body = response definition.validate_response(request, Rack::Response[status, headers, body], raise_error: false) response end end end |