Sha256: cc7ac6034beb1945bf7ad159896d7d478cc60f737bee17ff2852b6f36eba23b2
Contents?: true
Size: 1.2 KB
Versions: 18
Compression:
Stored size: 1.2 KB
Contents
module Apidiesel module Handlers module MockResponse class RequestHandler def run(request, api_config) action = request.action return request unless action.respond_to?(:mock_response) && action.mock_response file_name = action.mock_response[:file] parser = action.mock_response[:parser] file = File.read(file_name) request.response_body = if parser parser.call(file) elsif file_name.ends_with?('.json') JSON.parse(file) elsif file_name.ends_with?('.xml') Hash.from_xml(file) else file end request end end module ActionExtension extend ActiveSupport::Concern class_methods do def mock_response!(file:, &block) @mock_response = { file: file, parser: block } end def mock_response @mock_response end end def mock_response self.class.mock_response end end end end end Apidiesel::Action.send(:include, Apidiesel::Handlers::MockResponse::ActionExtension)
Version data entries
18 entries across 18 versions & 1 rubygems