Class: E2E::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/e2e/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, port: nil) ⇒ Server

Returns a new instance of Server.



12
13
14
15
16
# File 'lib/e2e/server.rb', line 12

def initialize(app, port: nil)
  @app = app
  @host = "127.0.0.1"
  @port = port || find_available_port
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



10
11
12
# File 'lib/e2e/server.rb', line 10

def app
  @app
end

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/e2e/server.rb', line 10

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



10
11
12
# File 'lib/e2e/server.rb', line 10

def port
  @port
end

Instance Method Details

#base_urlObject



32
33
34
# File 'lib/e2e/server.rb', line 32

def base_url
  "http://#{@host}:#{@port}"
end

#startObject



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/e2e/server.rb', line 18

def start
  @thread = Thread.new do
    # Use Rackup handler for Rack 3 compatibility
    Rackup::Handler::WEBrick.run(
      @app,
      Host: @host,
      Port: @port,
      AccessLog: [],
      Logger: WEBrick::Log.new(nil, 0) # Silence logs
    )
  end
  wait_for_boot
end