templates/parent/spec/spec_helper.rb in opskeleton-0.6.3 vs templates/parent/spec/spec_helper.rb in opskeleton-0.6.4
- old
+ new
@@ -4,43 +4,30 @@
include SpecInfra::Helper::Ssh
include SpecInfra::Helper::DetectOS
RSpec.configure do |c|
- if ENV['ASK_SUDO_PASSWORD']
- require 'highline/import'
- c.sudo_password = ask("Enter sudo password: ") { |q| q.echo = false }
- else
- c.sudo_password = ENV['SUDO_PASSWORD']
- end
c.before :all do
- block = self.class.metadata[:example_group_block]
- if RUBY_VERSION.start_with?('1.8')
- file = block.to_s.match(/.*@(.*):[0-9]+>/)[1]
- else
- file = block.source_location.first
- end
- host = File.basename(Pathname.new(file).dirname)
- if c.host != host
- c.ssh.close if c.ssh
- c.host = host
- options = Net::SSH::Config.for(c.host)
- user = options[:user] || Etc.getlogin
- vagrant_up = `vagrant up default`
- config = `vagrant ssh-config default`
- if config != ''
- config.each_line do |line|
- if match = /HostName (.*)/.match(line)
- host = match[1]
- elsif match = /User (.*)/.match(line)
- user = match[1]
- elsif match = /IdentityFile (.*)/.match(line)
- options[:keys] = [match[1].gsub(/"/,'')]
- elsif match = /Port (.*)/.match(line)
- options[:port] = match[1]
- end
+ 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]
end
end
- c.ssh = Net::SSH.start(host, user, options)
end
+
+ c.ssh = Net::SSH.start(sshhost, sshuser, options)
end
end