Class: CypressRails::Server

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/cypress_rails/server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, command, healthcheck_url, log_path) ⇒ Server

Returns a new instance of Server.



12
13
14
15
16
17
18
# File 'lib/cypress_rails/server.rb', line 12

def initialize(host, command, healthcheck_url, log_path)
  @host = host
  @port = find_free_port
  @command = command
  @healthcheck_url = URI(healthcheck_url || "http://#{host}").tap { |uri| uri.port = port }
  @log_path = log_path
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



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

def command
  @command
end

#healthcheck_urlObject (readonly)

Returns the value of attribute healthcheck_url.



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

def healthcheck_url
  @healthcheck_url
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#log_pathObject (readonly)

Returns the value of attribute log_path.



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

def log_path
  @log_path
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

Instance Method Details

#startObject



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

def start
  spawn_server
  until server_responsive?
    puts "Pinging #{healthcheck_url.to_s}..."
    sleep 1
  end
  yield(host, port) if block_given?
ensure
  stop_server
end