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.



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

def initialize
  # @options  = options
  # @files    = files.map do |file|
  #   split = file.split(':')
  #   [split[0], split[1..-1].map{|l| Integer(l) }]
  # end
  @language = 'en'
  @parser   = Gherkin::Parser::Parser.new(
    self, true, 'root', false, @language)
end

Instance Attribute Details

#featuresObject (readonly)

Returns the value of attribute features.



5
6
7
# File 'lib/gurke/builder.rb', line 5

def features
  @features
end

#keywordsObject (readonly)

Returns the value of attribute keywords.



5
6
7
# File 'lib/gurke/builder.rb', line 5

def keywords
  @keywords
end

Instance Method Details

#background(raw) ⇒ Object



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

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

  @feature.backgrounds << @context
end

#eofObject



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

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

#feature(raw) ⇒ Object



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

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



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

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



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

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 #unless filtered?(@scenario)
end

#step(raw) ⇒ Object



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

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

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

#uri(raw) ⇒ Object



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

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