Sha256: dfccbdefdecec960f7b2aca7c1aab8d3ec25fdced5e8a2ad8097d76b8de77221

Contents?: true

Size: 1.06 KB

Versions: 9

Compression:

Stored size: 1.06 KB

Contents

require "open3"

module VagrantHelpers
  extend self

  class VagrantSSHCommandError < RuntimeError; end

  at_exit do
    if ENV["KEEP_RUNNING"]
      puts "Vagrant vm will be left up because KEEP_RUNNING is set."
      puts "Rerun without KEEP_RUNNING set to cleanup the vm."
    else
      vagrant_cli_command("destroy -f")
    end
  end

  def vagrant_cli_command(command)
    puts "[vagrant] #{command}"
    stdout, stderr, status = Dir.chdir(VAGRANT_ROOT) do
      Open3.capture3("#{VAGRANT_BIN} #{command}")
    end

    (stdout + stderr).each_line { |line| puts "[vagrant] #{line}" }

    [stdout, stderr, status]
  end

  def run_vagrant_command(command)
    stdout, stderr, status = vagrant_cli_command("ssh -c #{command.inspect}")
    return [stdout, stderr] if status.success?
    raise VagrantSSHCommandError, status
  end

  def puts(message)
    # Attach log messages to the current cucumber feature (`log`),
    # or simply puts to the console (`super`) if we are outside of cucumber.
    respond_to?(:log) ? log(message) : super(message)
  end
end

World(VagrantHelpers)

Version data entries

9 entries across 9 versions & 2 rubygems

Version Path
capistrano-3.18.1 features/support/vagrant_helpers.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/capistrano-3.18.0/features/support/vagrant_helpers.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/capistrano-3.18.0/features/support/vagrant_helpers.rb
capistrano-3.18.0 features/support/vagrant_helpers.rb
capistrano-3.17.3 features/support/vagrant_helpers.rb
capistrano-3.17.2 features/support/vagrant_helpers.rb
capistrano-3.17.1 features/support/vagrant_helpers.rb
capistrano-3.17.0 features/support/vagrant_helpers.rb
capistrano-3.16.0 features/support/vagrant_helpers.rb