forked from vamsee/puppet-solr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec_helper.rb
59 lines (50 loc) · 1.7 KB
/
spec_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
require 'rspec-puppet'
fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
RSpec.configure do |c|
c.module_path = File.join(fixture_path, 'modules')
c.manifest_dir = File.join(fixture_path, 'manifests')
if c.files_to_run.detect { |f| f.match(/system/) }
require 'serverspec'
require 'pathname'
require 'net/ssh'
include Serverspec::Helper::Ssh
include Serverspec::Helper::DetectOS
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)
c.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
end
end
c.ssh = Net::SSH.start(c.host, user, options)
end
end
end
end