class Patir::CommandSequenceStatus
CommandSequenceStatus
represents the status of a CommandSequence
, including the status of all the steps for this sequence.
In order to extract the status from steps, classes should quack to the rythm of Command
. CommandSequenceStatus
does this, so you can nest Stati
The status of an action sequence is :not_executed, :running, :success, :warning or :error and represents the overall status
:not_executed is set when all steps are :not_executed :running is set while the sequence is running.
Upon completion or interruption one of :success, :error or :warning will be set.
:success is set when all steps are succesfull. :warning is set when at least one step generates warnings and there are no failures. :error is set when after execution at least one step has the :error status
Attributes
Public Class Methods
You can pass an array of Commands to initialize CommandSequenceStatus
# File lib/patir/command.rb, line 341 def initialize sequence_name,steps=nil @sequence_name=sequence_name @sequence_runner="" @sequence_id=nil @step_states||=Hash.new #not run yet @status=:not_executed #translate the array of steps as we need it in number=>state form steps.each{|step| self.step=step } if steps @start_time=Time.now end
Public Instance Methods
A sequence is considered completed when:
a step has errors and the :fail_on_error strategy is used
a step has warnings and the :fail_on_warning strategy is used
in all other cases if none of the steps has a :not_executed or :running status
# File lib/patir/command.rb, line 369 def completed? #this saves us iterating once+1 when no execution took place return false if !self.executed? @step_states.each do |state| return true if state[1][:status]==:error && state[1][:strategy]==:fail_on_error return true if state[1][:status]==:warning && state[1][:strategy]==:fail_on_warning end @step_states.each{|state| return false if state[1][:status]==:not_executed || state[1][:status]==:running } return true end
# File lib/patir/command.rb, line 447 def error return "" end
# File lib/patir/command.rb, line 434 def exec_time return @stop_time-@start_time if @stop_time return 0 end
# File lib/patir/command.rb, line 450 def executed? return true unless @status==:not_executed return false end
# File lib/patir/command.rb, line 438 def name return @sequence_name end
# File lib/patir/command.rb, line 441 def number return @sequence_id end
# File lib/patir/command.rb, line 444 def output return self.summary end
# File lib/patir/command.rb, line 352 def running? return true if :running==@status return false end
Adds a step to the state. The step state is inferred from the Command
instance __step__
# File lib/patir/command.rb, line 385 def step=step @step_states[step.number]={:name=>step.name, :status=>step.status, :output=>step.output, :duration=>step.exec_time, :error=>step.error, :strategy=>step.strategy } #this way we don't have to compare all the step states we always get the worst last stable state #:not_executed<:success<:warning<:success unless @status==:running @previous_status=@status case step.status when :running @status=:running when :warning @status=:warning unless @status==:error @status=:error if @previous_status==:error when :error @status=:error when :success @status=:success unless @status==:error || @status==:warning @status=:warning if @previous_status==:warning @status=:error if @previous_status==:error when :not_executed @status=@previous_status end end#unless running end
A nil means there is no step with that number
# File lib/patir/command.rb, line 380 def step_state number s=@step_states[number] if @step_states[number] return s end
true is returned when all steps were succesfull.
# File lib/patir/command.rb, line 357 def success? return true if :success==@status return false end
produces a brief text summary for this status
# File lib/patir/command.rb, line 415 def summary sum="" sum<<"#{@sequence_id}:" if @sequence_id sum<<"#{@sequence_name}. " unless @sequence_name.empty? sum<<"Status - #{@status}" if !@step_states.empty? && @status!=:not_executed sum<<". States #{@step_states.size}\nStep status summary:" sorter=Hash.new @step_states.each do |number,state| #sort them by number sorter[number]="\n\t#{number}:'#{state[:name]}' - #{state[:status]}" end 1.upto(sorter.size) {|i| sum<<sorter[i] if sorter[i]} end return sum end
# File lib/patir/command.rb, line 431 def to_s "'#{sequence_id}':'#{@sequence_name}' on '#{@sequence_runner}' started at #{@start_time}.#{@step_states.size} steps" end