Class: VagrantPlugins::ServerSpecHtmlReport::Provisioner

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-serverspechtmlreport/provisioner.rb

Instance Method Summary collapse

Constructor Details

#initialize(machine, config) ⇒ Provisioner

Returns a new instance of Provisioner.



8
9
10
11
# File 'lib/vagrant-serverspechtmlreport/provisioner.rb', line 8

def initialize(machine, config)
  super
  @spec_files = config.spec_files
end

Instance Method Details

#provisionObject



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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/vagrant-serverspechtmlreport/provisioner.rb', line 13

def provision
  if machine.config.vm.communicator == :winrm
    username = machine.config.winrm.username
    winrm_info = VagrantPlugins::CommunicatorWinRM::Helper.winrm_info(@machine)
    set :backend, :winrm
    set :os, :family => 'windows'
    user = machine.config.winrm.username
    pass = machine.config.winrm.password
    endpoint = "http://#{winrm_info[:host]}:#{winrm_info[:port]}/wsman"

    winrm = ::WinRM::WinRMWebService.new(endpoint, :ssl, :user => user, :pass => pass, :basic_auth_only => true)
    winrm.set_timeout machine.config.winrm.timeout
    Specinfra.configuration.winrm = winrm
  else
    set :backend, :ssh

    if ENV['ASK_SUDO_PASSWORD']
      begin
        require 'highline/import'
      rescue LoadError
        fail "highline is not available. Try installing it."
      end
      set :sudo_password, ask("Enter sudo password: ") { |q| q.echo = false }
    else
      set :sudo_password, ENV['SUDO_PASSWORD']
    end

    host = machine.ssh_info[:host]
    options = Net::SSH::Config.for(host)

    options[:proxy]         = setup_provider_proxy if use_jump_provider?
    options[:user]          = machine.ssh_info[:username]
    options[:port]          = machine.ssh_info[:port]
    options[:keys]          = machine.ssh_info[:private_key_path]
    options[:password]      = machine.ssh_info[:password]
    options[:forward_agent] = machine.ssh_info[:private_key_path]

    set :host,        options[:host_name] || host
    set :ssh_options, options
  end

	require 'rspec'
	require 'rspec_html_formatter'
	config = RSpec.configuration

	formatter = RspecHtmlFormatter.new(config.output_stream)

	# create reporter with RspecHtmlFormatter
	reporter =  RSpec::Core::Reporter.new(config)
	config.instance_variable_set(:@reporter, reporter)

	# internal hack
	# api may not be stable, make sure lock down Rspec version
	loader = config.send(:formatter_loader)
	notifications = loader.send(:notifications_for, RspecHtmlFormatter)


	reporter.register_listener(formatter, *notifications)

	RSpec::Core::Runner.run(@spec_files)

	p formatter.output_hash
  #raise Vagrant::Errors::ServerSpecFailed if status != 0
end