lib/quarry/markup/step.rb in quarry-0.5.0 vs lib/quarry/markup/step.rb in quarry-0.5.2

- old
+ new

@@ -3,75 +3,71 @@ class Markup #:nodoc: # = Step # class Step - attr :parent + + attr :spec attr :code attr :lineno - def initialize(parent, code, lineno) - @parent = parent + attr :before + attr :after + + def initialize(spec, code, lineno, ioc={}) + @spec = spec @code = code.rstrip @lineno = lineno + + @before = ioc[:before] + @after = ioc[:after] end - alias_method :spec, :parent + alias_method :parent, :spec #def description # alias_method :description, :text #end - end - # = Macro - # - class Macro < Step - attr :type - def initialize(parent, code, lineno, type) - super(parent, code, lineno) - @type = type + # Run specification step. + # + # TODO: Would spec.before + spec.code be better? + # + def run(runner, spec, context, output) + output.report_step(self) + #context.instance_eval(runner.before, spec.file) if runner.before + context.instance_eval(before.code, spec.file) if before + begin + context.instance_eval(code, spec.file, lineno) + output.report_pass(self) + rescue Assertion => error + output.report_fail(self, error) + rescue Exception => error + output.report_error(self, error) + ensure + context.instance_eval(after.code, spec.file) if after + #context.instance_eval(runner.after, spec.file) if runner.after + end end - end - # = Header - # - class Header - attr :parent - attr :text - attr :lineno - - def initialize(parent, text, lineno) - @parent = parent - @text = text.strip - @lineno = lineno + # + def tab + @tab ||= to_s.index(/\S/) end - alias_method :spec, :parent - alias_method :description, :text - end - - # = Comment - # - class Comment - attr :parent - attr :text - attr :lineno - - def initialize(parent, text, lineno) - @parent = parent - @text = text.strip - @lineno = lineno + # + def to_s + code end - alias_method :spec, :parent - alias_method :description, :text - - # - def type - /^(\w{1,9})[:]/i =~ text - $1.downcase.to_sym if $1 + # As could appear in stand-alone script. + def to_script + script = [] + script << before.code if before + script << code + script << before.code if after + script .join("\n") end - alias_method :macro?, :type end end #class Markup end #module Quarry