Sha256: e5a92e334e82297b4a4ba9c98dda763a384558b7e3ac25400c8334c2d4777060

Contents?: true

Size: 1.51 KB

Versions: 2

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true
require 'cucumber/core/test/result'
require 'cucumber/core/test/action'

module Cucumber
  module Core
    module Test
      class Step
        attr_reader :source

        def initialize(source, action = Test::UndefinedAction.new(source.last.location))
          raise ArgumentError if source.any?(&:nil?)
          @source, @action = source, action
        end

        def describe_to(visitor, *args)
          visitor.test_step(self, *args)
        end

        def describe_source_to(visitor, *args)
          source.reverse.each do |node|
            node.describe_to(visitor, *args)
          end
          self
        end

        def skip(*args)
          @action.skip(*args)
        end

        def execute(*args)
          @action.execute(*args)
        end

        def with_action(location = nil, &block)
          self.class.new(source, Test::Action.new(location, &block))
        end

        def name
          source.last.name
        end

        def location
          source.last.location
        end

        def action_location
          @action.location
        end

        def inspect
          "#<#{self.class}: #{location}>"
        end

      end

      class IsStepVisitor
        def initialize(test_step)
          @is_step = false
          test_step.describe_to(self)
        end

        def step?
          @is_step
        end

        def test_step(*)
          @is_step = true
        end

        def method_missing(*)
          self
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cucumber-core-3.0.0.pre.2 lib/cucumber/core/test/step.rb
cucumber-core-2.0.0 lib/cucumber/core/test/step.rb