templates/parent/spec/spec_helper.rb in opskeleton-0.7.0 vs templates/parent/spec/spec_helper.rb in opskeleton-0.7.1
- old
+ new
@@ -3,31 +3,46 @@
require 'net/ssh'
include SpecInfra::Helper::Ssh
include SpecInfra::Helper::DetectOS
+def run(cmd)
+ unless(system(cmd, out: $stdout, err: :out))
+ puts 'Failed to setup vagrant machine'
+ System.exit 1
+ end
+end
+
RSpec.configure do |c|
- c.before :all do
+ c.before :suite do
c.host = ENV['TARGET_HOST']
c.ssh.close if c.ssh
options = Net::SSH::Config.for(c.host)
- user = 'vagrant'
- vagrant_up = `vagrant up #{c.host}`
- config = `vagrant ssh-config #{c.host}`
- sshhost = sshuser = ''
- if config != ''
- config.each_line do |line|
- if match = /HostName (.*)/.match(line)
- sshhost = match[1]
- elsif match = /User (.*)/.match(line)
- sshuser = match[1]
- elsif match = /IdentityFile (.*)/.match(line)
- options[:keys] = [match[1].gsub(/"/,'')]
- elsif match = /Port (.*)/.match(line)
- options[:port] = match[1]
+ if(!ENV['LOCAL'])
+ run("vagrant up #{c.host}")
+ config = `vagrant ssh-config #{c.host}`
+ sshhost = sshuser = ''
+ if config != ''
+ config.each_line do |line|
+ if match = /HostName (.*)/.match(line)
+ sshhost = match[1]
+ elsif match = /User (.*)/.match(line)
+ sshuser = match[1]
+ elsif match = /IdentityFile (.*)/.match(line)
+ options[:keys] = [match[1].gsub(/"/,'')]
+ elsif match = /Port (.*)/.match(line)
+ options[:port] = match[1]
+ end
end
end
+ else
+ sshhost = 'localhost'
+ sshuser = 'vagrant'
end
-
c.ssh = Net::SSH.start(sshhost, sshuser, options)
+ end
+
+ c.after :suite do
+ c.host = ENV['TARGET_HOST']
+ run("vagrant destroy #{c.host} -f")
end
end