spec/support/helpers.rb in engineyard-0.3.1 vs spec/support/helpers.rb in engineyard-0.3.2

- old
+ new

@@ -16,16 +16,15 @@ NonzeroExitStatus = Class.new(UnexpectedExit) ZeroExitStatus = Class.new(UnexpectedExit) def ey(cmd = nil, options = {}, &block) require "open3" - hide_err = options.delete(:hide_err) - path_prepends = options.delete(:prepend_to_path) + hide_err = options.has_key?(:hide_err) ? options[:hide_err] : options[:expect_failure] + path_prepends = options[:prepend_to_path] - ey_env = { - 'DEBUG' => options[:debug].to_s - } + ey_env = {} + ey_env['DEBUG'] = options[:debug].to_s if options[:debug] if path_prepends tempdir = File.join(Dir.tmpdir, "ey_test_cmds_#{Time.now.tv_sec}#{Time.now.tv_usec}_#{$$}") Dir.mkdir(tempdir) path_prepends.each do |name, contents| @@ -52,13 +51,25 @@ elsif exit_status.success? && options[:expect_failure] raise ZeroExitStatus.new(@out, @err) end end - @ssh_commands = @out.split(/\n/).find_all do |line| + @raw_ssh_commands = @out.split(/\n/).find_all do |line| line =~ /^ssh/ - end.map do |line| - line.sub(/^.*?\"/, '').sub(/\"$/, '') + end + + @ssh_commands = @raw_ssh_commands.map do |cmd| + # Strip off everything up to and including user@host, leaving + # just the command that the remote system would run + ssh_prefix_removed = cmd.gsub(/^.*?\w+@\S*\s*/, '') + + # Its arguments have been double-escaped: one layer is to get + # them through our local shell and into ssh, and the other + # layer is to get them through the remote system's shell. + # + # Strip off one layer by running it through the shell. + just_the_remote_command = ssh_prefix_removed.gsub(/>\s*\/dev\/null.*$/, '') + `echo #{just_the_remote_command}`.strip end puts @err unless @err.empty? || hide_err @out end