Sha256: 72066a1a9bd1fd040359a5bf15022496517136df5d68f968138e5b624c03b678

Contents?: true

Size: 1.98 KB

Versions: 2

Compression:

Stored size: 1.98 KB

Contents

require 'cucumber/core_ext/proc'

module Cucumber
  class Pending < StandardError
  end

  class Executor
    attr_reader :failed
    
    def line=(line)
      @line = line
    end

    def initialize(formatter, step_mother)
      @formatter = formatter
      @world_proc = lambda{ Object.new }
      @before_procs = []
      @after_procs = []
      @step_mother = step_mother
    end
    
    def register_world_proc(&proc)
      @world_proc = proc
    end

    def register_before_proc(&proc)
      proc.extend(CoreExt::CallIn)
      @before_procs << proc
    end

    def register_after_proc(&proc)
      proc.extend(CoreExt::CallIn)
      @after_procs << proc
    end

    def visit_features(features)
      raise "Line number can only be specified when there is 1 feature. There were #{features.length}." if @line && features.length != 1
      @step_mother.visit_features(features)
      @formatter.visit_features(features) if @formatter.respond_to?(:visit_features)
      features.accept(self)
      @formatter.dump
    end

    def visit_feature(feature)
      feature.accept(self)
    end

    def visit_header(header)
      @formatter.header_executing(header) if @formatter.respond_to?(:header_executing)
    end

    def visit_scenario(scenario)
      if @line.nil? || scenario.at_line?(@line)
        @error = nil
        @world = @world_proc.call
        @formatter.scenario_executing(scenario) if @formatter.respond_to?(:scenario_executing)
        @before_procs.each{|p| p.call_in(@world, *[])}
        scenario.accept(self)
        @after_procs.each{|p| p.call_in(@world, *[])}
        @formatter.scenario_executed(scenario) if @formatter.respond_to?(:scenario_executed)
      end
    end

    def visit_step(step)
      if @error.nil?
        begin
          step.execute_in(@world)
        rescue Pending => ignore
        rescue => e
          @failed = true
          @error = e
        end
        @formatter.step_executed(step)
      else
        @formatter.step_skipped(step)
      end
    end    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aslakhellesoy-cucumber-0.1.3 lib/cucumber/executor.rb
aslakhellesoy-cucumber-0.1.4 lib/cucumber/executor.rb