Sha256: 948099d07dc049600446f5b9391b77a5beb785a75d89f05c5b200b38b98e7acb

Contents?: true

Size: 1.82 KB

Versions: 14

Compression:

Stored size: 1.82 KB

Contents

require 'enumerator'
require 'gherkin/tag_expression'

module Lucid
  module AST
    module HasSteps #:nodoc:
      attr_reader :gherkin_statement, :raw_steps, :title, :description
      def gherkin_statement(statement=nil)
        @gherkin_statement ||= statement
      end

      def attach_steps(steps)
        steps.each do |step| 
          step.feature_element = self
        end
      end

      def first_line_length
        name_line_lengths[0]
      end

      def text_length
        name_line_lengths.max
      end

      def name_line_lengths
        if name.strip.empty?
          [AST::Step::INDENT + @keyword.unpack('U*').length + ': '.length]
        else
          name.split("\n").enum_for(:each_with_index).map do |line, line_number|
            if line_number == 0
              AST::Step::INDENT + @keyword.unpack('U*').length + ': '.length + line.unpack('U*').length
            else
              AST::Step::INDENT + AST::Step::INDENT + line.unpack('U*').length
            end
          end
        end
      end

      def matches_scenario_names?(scenario_name_regexps)
        scenario_name_regexps.detect{|n| n =~ name}
      end

      def backtrace_line(step_name = "#{@keyword}: #{name}", line = self.line)
        "#{location.on_line(line)}:in `#{step_name}'"
      end

      def source_indent(text_length)
        max_line_length - text_length
      end

      def max_line_length
        steps.max_line_length(self)
      end

      def accept_hook?(hook)
        Gherkin::TagExpression.new(hook.tag_expressions).evaluate(source_tags)
      end

      def source_tag_names
        source_tags.map { |tag| tag.name }
      end

      def source_tags
        @tags.tags.to_a + feature_tags.tags.to_a
      end

      def language
        @language || raise("Language is required for a #{self.class}")
      end

    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
lucid-0.5.1 lib/lucid/ast/has_steps.rb
lucid-0.4.1 lib/lucid/ast/has_steps.rb
lucid-0.4.0 lib/lucid/ast/has_steps.rb
lucid-0.3.3 lib/lucid/ast/has_steps.rb
lucid-0.3.0 lib/lucid/ast/has_steps.rb
lucid-0.2.1 lib/lucid/ast/has_steps.rb
lucid-0.2.0 lib/lucid/ast/has_steps.rb
lucid-0.1.1 lib/lucid/ast/has_steps.rb
lucid-0.1.0 lib/lucid/ast/has_steps.rb
lucid-0.0.9 lib/lucid/ast/has_steps.rb
lucid-0.0.8 lib/lucid/ast/has_steps.rb
lucid-0.0.7 lib/lucid/ast/has_steps.rb
lucid-0.0.6 lib/lucid/ast/has_steps.rb
lucid-0.0.5 lib/lucid/ast/has_steps.rb