Class: Stringup::Runner
- Inherits:
-
Object
- Object
- Stringup::Runner
- Defined in:
- lib/stringup/runner.rb
Instance Attribute Summary collapse
-
#scenario ⇒ Object
readonly
Returns the value of attribute scenario.
-
#script ⇒ Object
readonly
Returns the value of attribute script.
Instance Method Summary collapse
-
#initialize(script, scenario, *args) ⇒ Runner
constructor
A new instance of Runner.
- #output_log ⇒ Object
- #run ⇒ Object
- #run_command ⇒ Object
- #test(event) ⇒ Object
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
#scenario ⇒ Object (readonly)
Returns the value of attribute scenario.
20 21 22 |
# File 'lib/stringup/runner.rb', line 20 def scenario @scenario end |
#script ⇒ Object (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_log ⇒ Object
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 |
#run ⇒ Object
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_command ⇒ Object
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 |