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.



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

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.



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

def command
  @command
end

#healthcheck_urlObject (readonly)

Returns the value of attribute healthcheck_url.



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

def healthcheck_url
  @healthcheck_url
end

#hostObject (readonly)

Returns the value of attribute host.



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

def host
  @host
end

#log_pathObject (readonly)

Returns the value of attribute log_path.



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

def log_path
  @log_path
end

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

Instance Method Details

#startObject



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

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