Sha256: 33ec31a2f8fc45d52012f2a5aea5c8a23e3c8542255348a557db52f3ad59b946

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require 'cucumber/core/filter'
require 'cucumber/running_test_case'
require 'cucumber/hooks'

module Cucumber
  module Filters

    class PrepareWorld < Core::Filter.new(:runtime)

      def test_case(test_case)
        CaseFilter.new(runtime, test_case).test_case.describe_to receiver
      end

      class CaseFilter
        def initialize(runtime, original_test_case)
          @runtime, @original_test_case = runtime, original_test_case
        end

        def test_case
          init_scenario = Cucumber::Hooks.around_hook(@original_test_case.source) do |continue|
            @runtime.begin_scenario(scenario)
            continue.call
            @runtime.end_scenario(scenario)
          end
          around_hooks = [init_scenario] + @original_test_case.around_hooks

          empty_hook = proc {} #no op - legacy format adapter expects a before hooks
          default_hook = Cucumber::Hooks.before_hook(@original_test_case.source, Cucumber::Hooks.location(empty_hook), &empty_hook)
          steps = [default_hook] + @original_test_case.test_steps

          @original_test_case.with_around_hooks(around_hooks).with_steps(steps)
        end

        private

        def scenario
          @scenario ||= RunningTestCase.new(test_case)
        end
      end

    end

  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cucumber-2.0.1 lib/cucumber/filters/prepare_world.rb