lib/serverspec/setup.rb in serverspec-0.2.14 vs lib/serverspec/setup.rb in serverspec-0.2.15

- old
+ new

@@ -22,29 +22,10 @@ @hostname = gets.chomp else @hostname = 'localhost' end - prompt = <<-EOF - -Select OS type of target host: - - 1) Auto Detect - 2) Red Hat - 3) Debian - 4) Gentoo - 5) Solaris - -Select number: -EOF - - print prompt.chop - num = gets.to_i - 1 - puts - - @os_type = [ 'DetectOS', 'RedHat', 'Debian', 'Gentoo', 'Solaris' ][num] - [ 'spec', "spec/#{@hostname}" ].each { |dir| safe_mkdir(dir) } safe_create_spec safe_create_spec_helper safe_create_rakefile end @@ -98,49 +79,53 @@ content = <<-EOF require 'serverspec' require 'pathname' ### include requirements ### +### include backend helper ### +include Serverspec::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 - ### include backend helper ### - ### include os helper ### ### include backend conf ### end EOF if not @backend_type.nil? - content.gsub!(/### include backend helper ###/, "c.include(Serverspec::Helper::#{@backend_type})") + content.gsub!(/### include backend helper ###/, "include Serverspec::Helper::#{@backend_type}") case @backend_type when 'Ssh' content.gsub!(/### include requirements ###/, "require 'net/ssh'") - content.gsub!(/### include backend conf ###/, "c.before do - host = File.basename(Pathname.new(example.metadata[:location]).dirname) + content.gsub!(/### include backend conf ###/, "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 c.ssh = Net::SSH.start(c.host, user, options) c.os = backend(Serverspec::Commands::Base).check_os end end") when 'Exec' - content.gsub!(/### include backend conf ###/, "c.before do + content.gsub!(/### include backend conf ###/, "c.before :all do c.os = backend(Serverspec::Commands::Base).check_os end") when 'Puppet' content.gsub!(/### include requirements ###/, "require 'puppet'\nrequire 'serverspec/backend/puppet' ") end - end - if not @os_type.nil? - content.gsub!(/### include os helper ###/, "c.include(Serverspec::Helper::#{@os_type})") end if File.exists? 'spec/spec_helper.rb' old_content = File.read('spec/spec_helper.rb') if old_content != content