Class: ClucumberSubprocess
- Inherits:
-
Object
- Object
- ClucumberSubprocess
- Defined in:
- lib/clucumber.rb
Defined Under Namespace
Classes: LaunchFailed
Instance Attribute Summary collapse
-
#output ⇒ Object
readonly
Returns the value of attribute output.
Class Method Summary collapse
Instance Method Summary collapse
- #alive? ⇒ Boolean
-
#initialize(dir, options = {}) ⇒ ClucumberSubprocess
constructor
A new instance of ClucumberSubprocess.
- #kill ⇒ Object
- #listen(additional_forms = "") ⇒ Object
- #record_output ⇒ Object
- #run ⇒ Object
- #start_clucumber_server(additional_forms) ⇒ Object
Constructor Details
#initialize(dir, options = {}) ⇒ ClucumberSubprocess
Returns a new instance of ClucumberSubprocess.
18 19 20 21 22 23 |
# File 'lib/clucumber.rb', line 18 def initialize(dir, ={}) @dir = dir @lisp = [:lisp] || ENV['LISP'] || 'sbcl --disable-debugger' @port = [:port] || raise("Need a port to run clucumber on.") @output = "" end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
7 8 9 |
# File 'lib/clucumber.rb', line 7 def output @output end |
Class Method Details
.launch(dir, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/clucumber.rb', line 9 def self.launch(dir, ={}) proc = ClucumberSubprocess.new(dir, ) at_exit do proc.kill end proc.run proc end |
Instance Method Details
#alive? ⇒ Boolean
90 91 92 93 94 |
# File 'lib/clucumber.rb', line 90 def alive? if !@pid.nil? (Process.kill("CONT", @pid) && true) rescue false end end |
#kill ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/clucumber.rb', line 78 def kill if @pid FileUtils.rm_f wire_file @reader.terminate! Process.kill("TERM", @pid) Process.waitpid(@pid) @pid = nil end rescue PTY::ChildExited @pid = nil end |
#listen(additional_forms = "") ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/clucumber.rb', line 51 def listen(additional_forms="") start_clucumber_server(additional_forms) unless wire_file_exists? until socket = TCPSocket.new("localhost", @port) rescue nil raise LaunchFailed, "Couldn't start clucumber:\n#{@output}" unless alive? sleep 0.01 end socket.close unless wire_file_exists? File.open(wire_file, "w") do |out| YAML.dump({'host' => "localhost", 'port' => @port}, out) end end end |
#record_output ⇒ Object
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/clucumber.rb', line 67 def record_output begin while line = @out.readline @output << line end rescue PTY::ChildExited STDOUT.puts "child exited, stopping." nil end end |
#run ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/clucumber.rb', line 25 def run set_port_from_wire_file and return if wire_file_exists? Dir.chdir(@dir) do @out, @in, @pid = PTY.spawn(@lisp) end @reader = Thread.start { record_output } cluke_dir = File.("clucumber/", File.dirname(__FILE__)) Dir[cluke_dir + '/**/*.fasl'].each do |fasl| FileUtils.rm(fasl) end @in.puts("(load #p\"\#{File.expand_path(\"clucumber/clucumber-bootstrap.lisp\", File.dirname(__FILE__))}\")\n") end |
#start_clucumber_server(additional_forms) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/clucumber.rb', line 43 def start_clucumber_server(additional_forms) @in.puts "\#{additional_forms}\n(asdf:oos 'asdf:load-op :clucumber)\n(clucumber-external:start #p\"./\" \"localhost\" \#{@port})\n" end |