Sha256: d0457d3683e5ee292b54646ab3e7ee66a90d4b86327b82d27de26f434b6bcaac
Contents?: true
Size: 1.99 KB
Versions: 1
Compression:
Stored size: 1.99 KB
Contents
module Guard class Spork class SporkInstance attr_reader :type, :env, :port, :options, :pid, :process def initialize(type, port, env, options) @type = type @port = port @env = env @options = options end def to_s case type when :rspec "RSpec" when :cucumber "Cucumber" when :test_unit "Test::Unit" when :minitest "MiniTest" else type.to_s end end def start cmd = command ::Guard::UI.debug "guard-spork command execution: #{cmd}" @process = ChildProcess.build *cmd @process.environment.merge!(env) unless env.empty? @process.io.inherit! @process.start @pid = @process.pid end def stop process.stop end def alive? pid && process.alive? end def running? return false unless alive? TCPSocket.new('localhost', port).close true rescue Errno::ECONNREFUSED false end def command parts = [] if use_bundler? parts << "bundle" parts << "exec" end if use_foreman? parts << "foreman" parts << "run" parts << "-e=#{options[:foreman].fetch(:env, '.env')}" if foreman_options? end parts << "spork" if type == :test_unit parts << "testunit" elsif type == :cucumber parts << "cu" elsif type == :minitest parts << "minitest" end parts << "-p" parts << port.to_s parts << "-q" if options[:quiet] parts end def self.spork_pids `ps aux | awk '/spork/&&!/awk/{print $2;}'`.split("\n").map { |pid| pid.to_i } end private def use_bundler? options[:bundler] end def use_foreman? options[:foreman] end def foreman_options? options[:foreman].is_a?(Hash) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
guard-spork-1.4.0 | lib/guard/spork/spork_instance.rb |