Sha256: fd29d1d99bcf3344282ccd1b8353a181e96d76f69dec91da033077ef4aa49da6

Contents?: true

Size: 1.96 KB

Versions: 14

Compression:

Stored size: 1.96 KB

Contents

module Cucumber
  module Ast
    # Represents the root node of a parsed feature.
    class Feature
      attr_accessor :file
      attr_writer :features, :lines

      def initialize(comment, tags, name, feature_elements, background = nil)
        @comment, @tags, @name, @feature_elements, @background = comment, tags, name, feature_elements, background
        feature_elements.each do |feature_element| 
          feature_element.feature = self
          feature_element.background = background if background
        end
        background.feature = self if background
        @lines = []
      end

      def tagged_with?(tag_names, check_elements=true)
        @tags.among?(tag_names) || 
        (check_elements && @feature_elements.detect{|e| e.tagged_with?(tag_names)})
      end
      
      def matches_scenario_names?(scenario_names)
        @feature_elements.detect{|e| e.matches_scenario_names?(scenario_names)}
      end

      def accept(visitor)
        visitor.current_feature_lines = @lines
        visitor.visit_comment(@comment)
        visitor.visit_tags(@tags)
        visitor.visit_feature_name(@name)
        
        @feature_elements.each do |feature_element|
          visitor.visit_feature_element(feature_element) if @features.visit?(feature_element, @lines)
        end
      end

      def scenario_executed(scenario)
        @features.scenario_executed(scenario) if @features
      end

      def step_executed(step)
        @features.step_executed(step) if @features
      end

      def backtrace_line(step_name, line)
        "#{file_line(line)}:in `#{step_name}'"
      end

      def file_line(line)
        "#{@file}:#{line}"
      end

      def to_sexp
        sexp = [:feature, @name]
        comment = @comment.to_sexp
        sexp += [comment] if comment
        tags = @tags.to_sexp
        sexp += tags if tags.any?
        sexp += [@background.to_sexp] if @background
        sexp += @feature_elements.map{|e| e.to_sexp}
        sexp
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
aslakhellesoy-cucumber-0.1.99.12 lib/cucumber/ast/feature.rb
aslakhellesoy-cucumber-0.1.99.13 lib/cucumber/ast/feature.rb
aslakhellesoy-cucumber-0.1.99.14 lib/cucumber/ast/feature.rb
aslakhellesoy-cucumber-0.1.99.15 lib/cucumber/ast/feature.rb
aslakhellesoy-cucumber-0.1.99.17 lib/cucumber/ast/feature.rb
aslakhellesoy-cucumber-0.1.99.18 lib/cucumber/ast/feature.rb
aslakhellesoy-cucumber-0.1.99.19 lib/cucumber/ast/feature.rb
aslakhellesoy-cucumber-0.1.99.20 lib/cucumber/ast/feature.rb
aslakhellesoy-cucumber-0.1.99.21 lib/cucumber/ast/feature.rb
aslakhellesoy-cucumber-0.1.99.22 lib/cucumber/ast/feature.rb
aslakhellesoy-cucumber-0.1.99.23 lib/cucumber/ast/feature.rb
kosmas58-cucumber-0.1.99.21 lib/cucumber/ast/feature.rb
kosmas58-cucumber-0.1.99.23 lib/cucumber/ast/feature.rb
notch8-cucumber-0.1.99.23 lib/cucumber/ast/feature.rb