Class: Gherkin::JSONParser

Inherits:
Object
  • Object
show all
Includes:
Base64
Defined in:
lib/gherkin/json_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(reporter, formatter) ⇒ JSONParser



13
14
15
# File 'lib/gherkin/json_parser.rb', line 13

def initialize(reporter, formatter)
  @reporter, @formatter = reporter, formatter
end

Instance Method Details

#parse(o) ⇒ Object

Parse a gherkin object o, which can either be a JSON String, or a Hash (from a parsed JSON String).



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
# File 'lib/gherkin/json_parser.rb', line 19

def parse(o)
  o = MultiJson.load(o) if String === o

  o.each do |f|
    @formatter.uri(f['uri'])
    Formatter::Model::Feature.new(comments(f), tags(f), keyword(f), name(f), description(f), line(f), id(f)).replay(@formatter)
    (f["elements"] || []).each do |feature_element|
      feature_element(feature_element).replay(@formatter)

      (feature_element["before"] || []).each do |hook|
        before(hook)
      end

      (feature_element["steps"] || []).each do |step|
        step(step).replay(@formatter)
        match(step)
        result(step)
        embeddings(step)
        output(step)
      end

      (feature_element["after"] || []).each do |hook|
        after(hook)
      end

      (feature_element["examples"] || []).each do |eo|
        Formatter::Model::Examples.new(comments(eo), tags(eo), keyword(eo), name(eo), description(eo), line(eo), id(eo), examples_rows(eo['rows'])).replay(@formatter)
      end
    end
  end

  @formatter.eof
end