Class: CypressRails::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/cypress_rails/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(host:, port:, bin_path: "npx cypress", tests_path:, output: IO.new(1)) ⇒ Runner

Returns a new instance of Runner.



5
6
7
8
9
10
11
# File 'lib/cypress_rails/runner.rb', line 5

def initialize(host:, port:, bin_path: "npx cypress", tests_path:, output: IO.new(1))
  @host = host
  @port = port
  @bin_path = bin_path
  @tests_path = tests_path
  @output = output
end

Instance Method Details

#openObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/cypress_rails/runner.rb', line 28

def open
  pid = Process.spawn(
    {
      "CYPRESS_app_host" => host,
      "CYPRESS_app_port" => port.to_s,
    },
    [bin_path, "open", "-P #{tests_path}"].join(" "),
    out: output,
    err: [:child, :out]
  )
  output.close
  Process.wait(pid)
end

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cypress_rails/runner.rb', line 13

def run
  pid = Process.spawn(
    {
      "CYPRESS_app_host" => host,
      "CYPRESS_app_port" => port.to_s,
    },
    [bin_path, "run", "-P #{tests_path}"].join(" "),
    out: output,
    err: [:child, :out]
  )
  output.close
  _, status = Process.wait2(pid)
  status.exitstatus
end