Sha256: 609ba5f05cf4e8f1d083108139e111ac6702c7b9e77edb8173bb42e9ea22a41b

Contents?: true

Size: 1.37 KB

Versions: 11

Compression:

Stored size: 1.37 KB

Contents

require 'cucumber/core/filter'
require 'cucumber/core/ast/location'
require 'cucumber/running_test_case'

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
          empty_hook_location = Cucumber::Core::Ast::Location.from_source_location(*empty_hook.source_location)
          default_hook = Cucumber::Hooks.before_hook(@original_test_case.source, empty_hook_location, &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

11 entries across 11 versions & 2 rubygems

Version Path
cucumber-2.99.0 lib/cucumber/filters/prepare_world.rb
mobiusloop-0.1.5 lib/cucumber/filters/prepare_world.rb
cucumber-2.4.0 lib/cucumber/filters/prepare_world.rb
mobiusloop-0.1.3 lib/cucumber/filters/prepare_world.rb
mobiusloop-0.1.2 lib/cucumber/filters/prepare_world.rb
cucumber-2.3.3 lib/cucumber/filters/prepare_world.rb
cucumber-2.3.2 lib/cucumber/filters/prepare_world.rb
cucumber-2.3.1 lib/cucumber/filters/prepare_world.rb
cucumber-2.3.0 lib/cucumber/filters/prepare_world.rb
cucumber-2.2.0 lib/cucumber/filters/prepare_world.rb
cucumber-2.1.0 lib/cucumber/filters/prepare_world.rb