module GrapeApe::TestHelper
Public Instance Methods
server(api, port, options = {}, &blk)
click to toggle source
Launches an instance of a given API
server. The server will launch on the specified port.
@param api [Class] The API
class to launch @param port [Integer] The port to run the server on @param options [Hash] The options hash to provide to the server @return [Goliath::Server] The executed server
# File lib/grape_ape/test_helper.rb, line 25 def server(api, port, options = {}, &blk) op = OptionParser.new s = GrapeApe::Goliath::Server.new s.logger = setup_logger(options) s.api = api s.app = ::Goliath::Rack::Builder.build(api.class, s.api) s.api.options_parser(op, options) s.options = options s.port = port s.plugins = api.class.plugins @test_server_port = s.port if blk s.start(&blk) s end
with_api(api, options = {}, &blk)
click to toggle source
Wrapper for launching API
and executing given code block. This will start the EventMachine reactor running.
@param api [Class] The GrapeApe::API
class to launch @param options [Hash] The options to pass to the server @param blk [Proc] The code to execute after the server is launched. @note This will not return until stop is called.
# File lib/grape_ape/test_helper.rb, line 14 def with_api(api, options = {}, &blk) server(GrapeApe::Server.new(api: api), options.delete(:port) || 9900, options, &blk) end