1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
require 'cucumber/core/ast/describes_itself'
require 'cucumber/core/ast/names'
require 'cucumber/core/ast/location'
require 'gherkin/dialect'
module Cucumber
module Core
module Ast
# Represents the root node of a parsed feature.
class Feature
include Names
include HasLocation
include DescribesItself
attr_reader :language, :location, :background,
:comments, :tags, :keyword, :description,
:feature_elements
def initialize(language, location, comments, tags, keyword, name, description, feature_elements)
@language = language
@location = location
@background = BackgroundFinder.new(feature_elements).result
@comments = comments
@tags = tags
@keyword = keyword
@name = name
@description = description
@feature_elements = feature_elements
end
def children
@feature_elements
end
def short_name
first_line = name.split(/\n/)[0]
if first_line =~ /#{language.feature_keywords}:(.*)/
$1.strip
else
first_line
end
end
def to_sexp
sexp = [:feature, file, name]
comment = @comment.to_sexp
sexp += [comment] if comment
tags = @tags.to_sexp
sexp += tags if tags.any?
sexp += @feature_elements.map{|fe| fe.to_sexp}
sexp
end
private
def description_for_visitors
:feature
end
end
class NullFeature
def method_missing(*args, &block)
self
end
end
class BackgroundFinder
def initialize(feature_elements)
@background = nil
feature_elements[0].describe_to(self) unless feature_elements.empty?
end
def background(background)
@background = background
end
def result
@background ? @background : EmptyBackground.new
end
def method_missing(*)
end
end
require 'delegate'
class LanguageDelegator < SimpleDelegator
attr_reader :iso_code
def initialize(iso_code, obj)
super(obj)
@iso_code = iso_code
end
end
end
end
end
|