# File lib/foreman_maintain/scenario.rb, line 168 def self.inspect "Scenario Class #{metadata[:description]}<#{name}>" end
# File lib/foreman_maintain/scenario.rb, line 82 def initialize(context_data = {}) @steps = [] @context = Context.new(context_data) set_context_mapping compose end
# File lib/foreman_maintain/scenario.rb, line 181 def self.new_from_hash(hash) scenarios = find_all_scenarios(:label => hash[:label]) unless scenarios.size == 1 raise "Could not find scenario #{hash[:label]}, found #{scenarios.size} scenarios" end scenario = scenarios.first scenario.load_step_states(hash[:steps]) scenario end
# File lib/foreman_maintain/scenario.rb, line 154 def add_step(step) add_steps([step]) unless step.nil? end
# File lib/foreman_maintain/scenario.rb, line 158 def add_step_with_context(definition, extra_params = {}) if definition.present? add_step(definition.send(:new, context.params_for(definition).merge(extra_params))) end end
# File lib/foreman_maintain/scenario.rb, line 148 def add_steps(steps) steps.each do |step| self.steps << step.ensure_instance end end
# File lib/foreman_maintain/scenario.rb, line 164 def add_steps_with_context(*definitions) definitions.flatten.each { |definition| add_step_with_context(definition) } end
scenarios to be run before this scenario
# File lib/foreman_maintain/scenario.rb, line 141 def before_scenarios scenarios = [] preparation_scenario = PreparationScenario.new(self) scenarios << [preparation_scenario] unless preparation_scenario.steps.empty? scenarios end
Override to compose steps for the scenario
# File lib/foreman_maintain/scenario.rb, line 90 def compose; end
# File lib/foreman_maintain/scenario.rb, line 103 def executed_steps steps.find_all(&:executed?) end
# File lib/foreman_maintain/scenario.rb, line 136 def failed? !passed? end
# File lib/foreman_maintain/scenario.rb, line 119 def filter_whitelisted(steps, options) options.validate_options!(:whitelisted) if options.key?(:whitelisted) steps.select do |step| options[:whitelisted] ? step.whitelisted? : !step.whitelisted? end else steps end end
# File lib/foreman_maintain/scenario.rb, line 172 def inspect "#{self.class.metadata[:description]}<#{self.class.name}>" end
# File lib/foreman_maintain/scenario.rb, line 191 def load_step_states(steps_hash) steps = self.steps.dup steps_hash.each do |step_hash| until steps.empty? step = steps.shift if step.matches_hash?(step_hash) step.update_from_hash(step_hash) break end end end end
# File lib/foreman_maintain/scenario.rb, line 130 def passed? (steps_with_abort(:whitelisted => false) + steps_with_error(:whitelisted => false) + steps_with_warning(:whitelisted => false)).empty? end
# File lib/foreman_maintain/scenario.rb, line 95 def preparation_steps # we first take the preparation steps defined for the scenario + collect # preparation steps for the steps inside the scenario steps.inject(super.dup) do |results, step| results.concat(step.preparation_steps) end.uniq end
Override to map context for the scenario
# File lib/foreman_maintain/scenario.rb, line 93 def set_context_mapping; end
# File lib/foreman_maintain/scenario.rb, line 111 def steps_with_abort(options = {}) filter_whitelisted(executed_steps.find_all(&:aborted?), options) end
# File lib/foreman_maintain/scenario.rb, line 107 def steps_with_error(options = {}) filter_whitelisted(executed_steps.find_all(&:fail?), options) end
# File lib/foreman_maintain/scenario.rb, line 115 def steps_with_warning(options = {}) filter_whitelisted(executed_steps.find_all(&:warning?), options) end
# File lib/foreman_maintain/scenario.rb, line 176 def to_hash { :label => label, :steps => steps.map(&:to_hash) } end