lib/serverspec/setup.rb in serverspec-2.0.0.beta6 vs lib/serverspec/setup.rb in serverspec-2.0.0.beta7
- old
+ new
@@ -101,34 +101,39 @@
describe package('apache2'), :if => os[:family] == 'Ubuntu' do
it { should be_installed }
end
describe service('httpd'), :if => os[:family] == 'RedHat' do
- it { should be_enabled }
- it { should be_running }
+ it { should be_enabled }
+ it { should be_running }
end
describe service('apache2'), :if => os[:family] == 'Ubuntu' do
- it { should be_enabled }
- it { should be_running }
+ it { should be_enabled }
+ it { should be_running }
end
+describe service('org.apache.httpd'), :if => os[:family] == 'Darwin' do
+ it { should be_enabled }
+ it { should be_running }
+end
+
describe port(80) do
it { should be_listening }
end
EOF
- if File.exists? "spec/#{@hostname}/httpd_spec.rb"
- old_content = File.read("spec/#{@hostname}/httpd_spec.rb")
+ if File.exists? "spec/#{@hostname}/sample_spec.rb"
+ old_content = File.read("spec/#{@hostname}/sample_spec.rb")
if old_content != content
- $stderr.puts "!! spec/#{@hostname}/httpd_spec.rb already exists and differs from template"
+ $stderr.puts "!! spec/#{@hostname}/sample_spec.rb already exists and differs from template"
end
else
- File.open("spec/#{@hostname}/httpd_spec.rb", 'w') do |f|
+ File.open("spec/#{@hostname}/sample_spec.rb", 'w') do |f|
f.puts content
end
- puts " + spec/#{@hostname}/httpd_spec.rb"
+ puts " + spec/#{@hostname}/sample_spec.rb"
end
end
def self.safe_mkdir(dir)
if File.exists? dir
@@ -231,15 +236,18 @@
exit 1
end
end
def self.spec_helper_template
- template = <<-EOF
+ template = <<-'EOF'
require 'serverspec'
<% if @backend_type == 'Ssh' -%>
require 'net/ssh'
<% end -%>
+<%- if @vagrant -%>
+require 'tempfile'
+<% end -%>
<% if @backend_type == 'WinRM' -%>
require 'winrm'
<% end -%>
include Specinfra::Helper::<%= @backend_type %>
@@ -260,34 +268,25 @@
else
set :sudo_password, ENV['SUDO_PASSWORD']
end
<%- if @backend_type == 'Ssh' -%>
-host = ENV['TARGET_HOST']
-options = Net::SSH::Config.for(host)
+host = ENV['TARGET_HOST']
<%- if @vagrant -%>
-`vagrant up \#{ENV['TARGET_HOST']}`
+`vagrant up #{host}`
-config = `vagrant ssh-config \#{ENV['TARGET_HOST']}`
-if config != ''
- config.each_line do |line|
- if match = /HostName (.*)/.match(line)
- host = match[1]
- elsif match = /User (.*)/.match(line)
- options[: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
+config = Tempfile.new('', Dir.tmpdir)
+`vagrant ssh-config #{host} > #{config.path}`
+options = Net::SSH::Config.for(host, [config.path])
+<%- else -%>
+options = Net::SSH::Config.for(host)
<%- end -%>
+
options[:user] ||= Etc.getlogin
-set :host, host
+set :host, options[:host_name] || host
set :ssh_options, options
<%- end -%>
<%- end -%>
<% if @backend_type == 'WinRM'-%>