Class: Polyspec::TestSetupRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/polyspec/test_setup_runner.rb

Direct Known Subclasses

DjangoProjectRunner, GolangProjectRunner

Constant Summary collapse

DEFAULT_WAIT_TRIES =
3
DEFAULT_WAIT_CHECK =
->(port, check_url) {
  begin
    HTTParty.get("http://localhost:#{port}#{check_url}")
  rescue
  end
}

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#build_commandObject

Returns the value of attribute build_command.



5
6
7
# File 'lib/polyspec/test_setup_runner.rb', line 5

def build_command
  @build_command
end

#check_urlObject

Returns the value of attribute check_url.



5
6
7
# File 'lib/polyspec/test_setup_runner.rb', line 5

def check_url
  @check_url
end

#pidObject

Returns the value of attribute pid.



5
6
7
# File 'lib/polyspec/test_setup_runner.rb', line 5

def pid
  @pid
end

#portObject

Returns the value of attribute port.



5
6
7
# File 'lib/polyspec/test_setup_runner.rb', line 5

def port
  @port
end

#start_commandObject

Returns the value of attribute start_command.



5
6
7
# File 'lib/polyspec/test_setup_runner.rb', line 5

def start_command
  @start_command
end

#stop_commandObject

Returns the value of attribute stop_command.



5
6
7
# File 'lib/polyspec/test_setup_runner.rb', line 5

def stop_command
  @stop_command
end

#wait_checkObject

Returns the value of attribute wait_check.



5
6
7
# File 'lib/polyspec/test_setup_runner.rb', line 5

def wait_check
  @wait_check
end

#wait_triesObject

Returns the value of attribute wait_tries.



5
6
7
# File 'lib/polyspec/test_setup_runner.rb', line 5

def wait_tries
  @wait_tries
end

Class Method Details

.from_args(args) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/polyspec/test_setup_runner.rb', line 14

def self.from_args(args)
  runner = new

  runner.build_command = options[:build_command]
  runner.start_command = options[:start_command]
  runner.stop_command = options[:stop_command]
  runner.wait_tries = options[:wait_tries]
  runner.port = options[:port]
  runner.check_url = options[:check_url]
  runner
end

Instance Method Details

#buildObject



26
27
28
# File 'lib/polyspec/test_setup_runner.rb', line 26

def build
  `#{build_command}`
end

#cleanupObject



44
45
46
# File 'lib/polyspec/test_setup_runner.rb', line 44

def cleanup
  # NOOP
end

#startObject



30
31
32
33
34
# File 'lib/polyspec/test_setup_runner.rb', line 30

def start
  self.pid = Process.spawn(start_command, pgroup: true)
  wait_for_app_to_boot
  pid
end

#stopObject



36
37
38
39
40
41
42
# File 'lib/polyspec/test_setup_runner.rb', line 36

def stop
  if stop_command
    `#{stop_command}`
  else
    Process.kill(-9, pid)
  end
end