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
- #connectable? ⇒ 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.
19 20 21 22 23 24 |
# File 'lib/clucumber.rb', line 19 def initialize(dir, ={}) @dir = dir @lisp = [:lisp] || ENV['LISP'] || 'sbcl --disable-debugger' @port = [:port] @output = "" end |
Instance Attribute Details
#output ⇒ Object (readonly)
Returns the value of attribute output.
8 9 10 |
# File 'lib/clucumber.rb', line 8 def output @output end |
Class Method Details
.launch(dir, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/clucumber.rb', line 10 def self.launch(dir, ={}) proc = ClucumberSubprocess.new(dir, ) at_exit do proc.kill end proc.run proc end |
Instance Method Details
#alive? ⇒ Boolean
93 94 95 96 97 |
# File 'lib/clucumber.rb', line 93 def alive? if !@pid.nil? (Process.kill("CONT", @pid) && true) rescue false end end |
#connectable? ⇒ Boolean
62 63 64 65 66 67 68 69 |
# File 'lib/clucumber.rb', line 62 def connectable? if socket = TCPSocket.new("127.0.0.1", @port) rescue nil socket.close true else false end end |
#kill ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/clucumber.rb', line 82 def kill if @pid @reader.terminate! Process.kill("TERM", @pid) Process.waitpid(@pid) @pid = nil end rescue PTY::ChildExited @pid = nil end |
#listen(additional_forms = "") ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/clucumber.rb', line 53 def listen(additional_forms="") start_clucumber_server(additional_forms) unless connectable? until connectable? raise LaunchFailed, "Couldn't start clucumber:\n#{@output}" unless alive? sleep 0.5 end sleep 1 end |
#record_output ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/clucumber.rb', line 71 def record_output begin while line = @out.readline @output << line end rescue PTY::ChildExited STDOUT.puts "child exited, stopping." nil end end |
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/clucumber.rb', line 26 def run set_port 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(<<-LISP) (load #p"#{File.("clucumber/clucumber-bootstrap.lisp", File.dirname(__FILE__))}") LISP end |
#start_clucumber_server(additional_forms) ⇒ Object
44 45 46 47 48 49 50 51 |
# File 'lib/clucumber.rb', line 44 def start_clucumber_server(additional_forms) @in.puts <<-LISP #{additional_forms} (asdf:oos 'asdf:load-op :clucumber) (clucumber-external:start #p"./" "localhost" #{@port}) LISP sleep 1 end |