lib/lopata/scenario.rb in lopata-0.1.25 vs lib/lopata/scenario.rb in lopata-0.1.26
- old
+ new
@@ -43,128 +43,128 @@
private
# @private
def method_missing(method, *args, &block)
- if execution.let_methods.include?(method)
- execution.let_methods[method].call_in_scenario(self, *args)
+
+ if (let_method = execution.find_let_method(method))
+ let_method.call_in_scenario(self, *args)
elsif metadata.keys.include?(method)
metadata[method]
else
super
end
end
# @private
def respond_to_missing?(method, *)
- execution.let_methods.include?(method) or metadata.keys.include?(method) or super
+ execution.find_let_method(method) or metadata.keys.include?(method) or super
end
# @private
# Scenario execution and live-cycle information
class Execution
- attr_reader :scenario, :status, :steps, :title, :current_step
+ attr_reader :scenario, :current_step, :top
- def initialize(title, options_title, metadata = {})
- @title = [title, options_title].compact.reject(&:empty?).join(' ')
- @metadata = metadata
- @let_methods = {}
- @status = :not_runned
- @steps = []
+ def initialize(title, metadata = {})
@scenario = Lopata::Scenario.new(self)
+ @top = Lopata::GroupExecution.new(Lopata::TopStep.new(title, metadata: metadata), nil, steps: [])
+ @current_step = @top
end
# Provide a human-readable representation of this class
def inspect
"#<#{self.class.name} #{title.inspect}>"
end
alias to_s inspect
+ def steps
+ top.steps
+ end
+
def run
- @status = :running
- sort_steps
world.notify_observers(:scenario_started, self)
- steps.each(&method(:run_step))
- @status = steps.any?(&:failed?) ? :failed : :passed
+ run_step(top)
world.notify_observers(:scenario_finished, self)
cleanup
end
def run_step(step)
- return if step.skipped? || step.ignored?
- groups = step.groups
- if groups.length > 0 && groups != @current_groups
- @current_groups = groups
- condition = groups.last.condition
- if condition&.dynamic? && !condition.match_dynamic?(scenario)
- step.ignored!
- ignore_groups(groups)
- return
+ @current_step = step
+ return :skipped if step.skipped?
+ return :ignored if step.ignored?
+ if step.condition&.dynamic && !step.condition.match_dynamic?(scenario)
+ step.ignored!
+ return :ignored
+ end
+ if step.group?
+ skip_rest = false
+ step.steps.each do
+ if _1.teardown?
+ run_step(_1)
+ elsif skip_rest
+ _1.skip!
+ else
+ run_step(_1)
+ skip_rest = true if _1.failed? && _1.skip_rest_on_failure?
+ end
end
+ step.status!
+ else
+ step.run(scenario)
+ step.status
end
- @current_step = step
- step.run(scenario)
- skip_rest if step.failed? && step.skip_rest_on_failure?
- @current_step = nil
end
def world
Lopata.world
end
def failed?
status == :failed
end
- def sort_steps
- @steps = steps.reject(&:teardown_group?) + steps.select(&:teardown_group?)
+ def metadata
+ current_step.metadata
end
- def skip_rest
- steps.select { |s| s.status == :not_runned && !s.teardown? }.each(&:skip!)
+ def let_methods
+ current_step.let_methods
end
- def ignore_groups(groups)
- steps.select { _1.status == :not_runned && _1.groups.take(groups.length) == groups }.each(&:ignored!)
+ def find_let_method(name)
+ current_step.find_let_method(name)
end
- def metadata
- if current_step
- @metadata.merge(current_step.metadata)
- else
- @metadata
- end
+ def title
+ top.title
end
- def let_methods
- if current_step
- @let_methods.merge(current_step.let_methods)
- else
- @let_methods
- end
+ def status
+ top.status
end
def let_base
- if current_step && !current_step.groups.empty?
- current_step.groups.last.let_methods
+ if current_step.group?
+ current_step
else
- @let_methods
+ current_step.parent
end
end
def let(method_name, &block)
- let_base[method_name] = LetMethod.new(&block)
+ let_base.add_let_method(method_name, LetMethod.new(&block))
end
def let!(method_name, &block)
- let_base[method_name] = LetBangMethod.new(&block)
+ let_base.add_let_method(method_name, LetBangMethod.new(&block))
end
def cleanup
@title = nil
- @metadata = nil
- @steps = nil
@scenario = nil
+ @top = nil
+ @current_step = nil
end
end
# @private
# let! methods incapsulate cached value and calculation block