Class: Gurke::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/gurke/builder.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



10
11
12
13
14
15
# File 'lib/gurke/builder.rb', line 10

def initialize
  @language = 'en'
  @parser   = Gherkin::Parser::Parser.new(
    self, true, 'root', false, @language,
  )
end

Instance Attribute Details

#featuresObject (readonly)

Returns the value of attribute features.



7
8
9
# File 'lib/gurke/builder.rb', line 7

def features
  @features
end

#keywordsObject



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/gurke/builder.rb', line 17

def keywords
  @keywords ||= begin
    keywords = {}
    Gherkin::I18n::LANGUAGES[@language].each do |k, v|
      v.split('|').map(&:strip).each do |str|
        keywords[str] = k.to_sym if str != '*'
      end
    end

    keywords
  end
end

Instance Method Details

#background(raw) ⇒ Object



56
57
58
59
60
61
# File 'lib/gurke/builder.rb', line 56

def background(raw)
  @context = Background.new @file, raw.line, raw
  @type    = nil

  @feature.backgrounds << @context
end

#eofObject



80
81
82
83
84
85
86
87
# File 'lib/gurke/builder.rb', line 80

def eof(*)
  @features.reject! {|f| f.scenarios.empty? }
  @feature  = nil
  @scenario = nil
  @context  = nil
  @type     = nil
  @file     = nil
end

#feature(raw) ⇒ Object



46
47
48
49
50
51
52
53
54
# File 'lib/gurke/builder.rb', line 46

def feature(raw)
  tags = raw.tags.map {|t| Tag.new @file, t.line, t }

  @feature  = Feature.new(@file, raw.line, tags, raw)
  @scenario = nil
  @type     = nil

  features << @feature
end

#load(files) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/gurke/builder.rb', line 30

def load(files)
  FeatureList.new.tap do |fl|
    @features = fl

    files.each do |file|
      @parser.parse File.read(file), file, 0
    end

    @features = nil
  end
end

#scenario(raw) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/gurke/builder.rb', line 63

def scenario(raw)
  tags  = raw.tags.map {|t| Tag.new @file, t.line, t }
  tags += features.last.tags

  @scenario = Scenario.new @feature, @file, raw.line, tags, raw
  @context  = @scenario
  @type     = nil

  @feature.scenarios << @scenario
end

#step(raw) ⇒ Object



74
75
76
77
78
# File 'lib/gurke/builder.rb', line 74

def step(raw)
  @type = lookup_type raw.keyword.strip

  @context.steps << Step.new(@file, raw.line, @type, raw)
end

#uri(raw) ⇒ Object



42
43
44
# File 'lib/gurke/builder.rb', line 42

def uri(raw)
  @file = raw.to_s
end