class ForemanMaintain::Scenario
Attributes
context[R]
steps[R]
Public Class Methods
inspect()
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 192 def self.inspect "Scenario Class #{metadata[:description]}<#{name}>" end
new(context_data = {})
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 89 def initialize(context_data = {}) @steps = [] @context = Context.new(context_data) set_context_mapping compose end
new_from_hash(hash)
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 205 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
Public Instance Methods
add_step(step)
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 178 def add_step(step) add_steps(step) unless step.nil? end
add_step_with_context(definition, extra_params = {})
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 182 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
add_steps(*steps)
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 172 def add_steps(*steps) steps.flatten.each do |step| self.steps << step.ensure_instance end end
add_steps_with_context(*definitions)
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 188 def add_steps_with_context(*definitions) definitions.flatten.each { |definition| add_step_with_context(definition) } end
before_scenarios()
click to toggle source
scenarios to be run before this scenario
# File lib/foreman_maintain/scenario.rb, line 165 def before_scenarios scenarios = [] preparation_scenario = PreparationScenario.new(self) scenarios << [preparation_scenario] unless preparation_scenario.steps.empty? scenarios end
compose()
click to toggle source
Override to compose steps for the scenario
# File lib/foreman_maintain/scenario.rb, line 97 def compose end
executed_steps()
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 112 def executed_steps steps.find_all(&:executed?) end
failed?()
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 160 def failed? !passed? end
filter_whitelisted(steps, options)
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 136 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
info_warning?()
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 156 def info_warning? !steps_with_info_warning(:whitelisted => false).empty? end
inspect()
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 196 def inspect "#{self.class.metadata[:description]}<#{self.class.name}>" end
load_step_states(steps_hash)
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 215 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
passed?()
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 147 def passed? (steps_with_abort(:whitelisted => false) + steps_with_error(:whitelisted => false)).empty? end
preparation_steps()
click to toggle source
Calls superclass method
# File lib/foreman_maintain/scenario.rb, line 104 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
set_context_mapping()
click to toggle source
Override to map context for the scenario
# File lib/foreman_maintain/scenario.rb, line 101 def set_context_mapping end
steps_with_abort(options = {})
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 120 def steps_with_abort(options = {}) filter_whitelisted(executed_steps.find_all(&:aborted?), options) end
steps_with_error(options = {})
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 116 def steps_with_error(options = {}) filter_whitelisted(executed_steps.find_all(&:fail?), options) end
steps_with_info_warning(options = {})
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 128 def steps_with_info_warning(options = {}) filter_whitelisted(executed_steps.find_all(&:info_warning?), options) end
steps_with_skipped(options = {})
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 132 def steps_with_skipped(options = {}) filter_whitelisted(executed_steps.find_all(&:skipped?), options) end
steps_with_warning(options = {})
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 124 def steps_with_warning(options = {}) filter_whitelisted(executed_steps.find_all(&:warning?), options) end
to_hash()
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 200 def to_hash { :label => label, :steps => steps.map(&:to_hash) } end
warning?()
click to toggle source
# File lib/foreman_maintain/scenario.rb, line 152 def warning? !steps_with_warning(:whitelisted => false).empty? end