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



40
41
42
# File 'lib/e2e/server.rb', line 40

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

#startObject



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

def start
  @thread = Thread.new do
    webrick_handler.run(
      @app,
      Host: @host,
      Port: @port,
      AccessLog: [],
      Logger: WEBrick::Log.new(nil, 0) # Silence logs
    ) do |server|
      @webrick = server
    end
  end
  wait_for_boot
end

#stopObject



33
34
35
36
37
38
# File 'lib/e2e/server.rb', line 33

def stop
  @webrick&.shutdown
  @thread&.join(5)
  @thread = nil
  @webrick = nil
end