Module: GrapeApe::TestHelper

Includes:
Goliath::TestHelper
Defined in:
lib/grape_ape/test_helper.rb

Instance Method Summary collapse

Instance Method Details

#server(api, port, options = {}, &blk) ⇒ Goliath::Server

Launches an instance of a given API server. The server will launch on the specified port.

Parameters:

  • api (Class)

    The API class to launch

  • port (Integer)

    The port to run the server on

  • options (Hash) (defaults to: {})

    The options hash to provide to the server

Returns:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# 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) ⇒ Object

Note:

This will not return until stop is called.

Wrapper for launching API and executing given code block. This will start the EventMachine reactor running.

Parameters:

  • api (Class)

    The GrapeApe::API class to launch

  • options (Hash) (defaults to: {})

    The options to pass to the server

  • blk (Proc)

    The code to execute after the server is launched.



14
15
16
# 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