Class: Stringup::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/stringup/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(script, scenario, *args) ⇒ Runner

Returns a new instance of Runner.



21
22
23
24
25
26
# File 'lib/stringup/runner.rb', line 21

def initialize(script, scenario, *args)
  @script = script
  @scenario = scenario
  @args = args
  @log = ''
end

Instance Attribute Details

#scenarioObject (readonly)

Returns the value of attribute scenario.



20
21
22
# File 'lib/stringup/runner.rb', line 20

def scenario
  @scenario
end

#scriptObject (readonly)

Returns the value of attribute script.



20
21
22
# File 'lib/stringup/runner.rb', line 20

def script
  @script
end

Instance Method Details

#output_logObject



37
38
39
40
41
42
43
44
45
# File 'lib/stringup/runner.rb', line 37

def output_log
  if @log.empty?
    puts "NO OUTPUT FROM `#{command}`"
  else
    line = "\nOUTPUT FROM `#{command}`"
    puts line, ('=' * line.size)
    puts @log
  end
end

#runObject



28
29
30
31
32
33
34
35
# File 'lib/stringup/runner.rb', line 28

def run
  Test::Unit.run = false
  suite = Test::Unit::TestSuite.new("#{scenario.description} for `#{command}`")
  suite << test(:before).suite
  suite << test(:after).suite
  Test::Unit::UI::Console::TestRunner.run(suite)
  output_log
end

#run_commandObject



47
48
49
50
51
52
53
54
# File 'lib/stringup/runner.rb', line 47

def run_command
  Open3.popen3(command) do |stdin, stdout, stderr|
    stdin.close
    @log << stdout.read
    @log << stderr.read
  end
  true
end

#test(event) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/stringup/runner.rb', line 56

def test(event)
  klass = Class.new(Test::Unit::TestCase) do
    class << self; attr_accessor :stringup, :name, :event; end
  end
  klass.name = "Stringup::Test::Order#{event == :after ? 1 : 0}::#{event.to_s.capitalize}Puppet"
  klass.stringup = self
  klass.event = event
  klass.context "#{event} `#{command}`" do
    if parent.event == :after
      setup do
        @ran_puppet ||= self.class.stringup.run_command
      end
    end
    parent.stringup.scenario.assertions.each do |assertion|
      should assertion.describe_should_at(event) do
        assertion.__send__(event, self)
      end
    end
  end
  klass
end