Sha256: 4c47cc1fe84ddd8f67376b7d85656ead68baf3f22efb0d64c115d73c7465b1da

Contents?: true

Size: 1.97 KB

Versions: 2

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true
require 'cucumber/core/ast/describes_itself'
require 'cucumber/core/ast/location'

module Cucumber
  module Core
    module Ast
      class Step
        include HasLocation
        include DescribesItself

        attr_reader :keyword, :text, :language, :comments, :exception, :multiline_arg

        def initialize(language, location, comments, keyword, text, multiline_arg)
          @language, @location, @comments, @keyword, @text, @multiline_arg = language, location, comments, keyword, text, multiline_arg
        end

        def to_s
          text
        end

        def backtrace_line
          "#{location}:in `#{keyword}#{text}'"
        end

        def actual_keyword(previous_step_keyword = nil)
          if [language.and_keywords, language.but_keywords].flatten.uniq.include? keyword
            if previous_step_keyword.nil?
              language.given_keywords.reject{|kw| kw == '* '}[0]
            else
              previous_step_keyword
            end
          else
            keyword
          end
        end

        def inspect
          keyword_and_text = [keyword, text].join(": ")
          %{#<#{self.class} "#{keyword_and_text}" (#{location})>}
        end

        private

        def children
          [@multiline_arg]
        end

        def description_for_visitors
          :step
        end
      end

      class ExpandedOutlineStep < Step

        def initialize(outline_step, language, location, comments, keyword, text, multiline_arg)
          @outline_step, @language, @location, @comments, @keyword, @text, @multiline_arg = outline_step, language, location, comments, keyword, text, multiline_arg
        end

        def all_locations
          @outline_step.all_locations
        end

        alias :step_backtrace_line :backtrace_line

        def backtrace_line
          "#{step_backtrace_line}\n" +
          "#{@outline_step.location}:in `#{@outline_step.keyword}#{@outline_step.text}'"
        end

      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cucumber-core-3.1.0 lib/cucumber/core/ast/step.rb
cucumber-core-3.0.0 lib/cucumber/core/ast/step.rb