Class: Gherkin::Formatter::JSONFormatter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ JSONFormatter

Creates a new instance that writes the resulting JSON to io. If io is nil, the JSON will not be written, but instead a Ruby object can be retrieved with #gherkin_object



17
18
19
# File 'lib/gherkin/formatter/json_formatter.rb', line 17

def initialize(io)
  @io = io
end

Instance Attribute Details

#gherkin_objectObject (readonly)

Returns the value of attribute gherkin_object.



12
13
14
# File 'lib/gherkin/formatter/json_formatter.rb', line 12

def gherkin_object
  @gherkin_object
end

Instance Method Details

#background(background) ⇒ Object



33
34
35
# File 'lib/gherkin/formatter/json_formatter.rb', line 33

def background(background)
  feature_elements << background.to_hash
end

#embedding(mime_type, data) ⇒ Object



61
62
63
# File 'lib/gherkin/formatter/json_formatter.rb', line 61

def embedding(mime_type, data)
  embeddings << {'mime_type' => mime_type, 'data' => encode64s(data)}
end

#eofObject



65
66
67
# File 'lib/gherkin/formatter/json_formatter.rb', line 65

def eof
  @io.write(@gherkin_object.to_json) if @io
end

#examples(examples) ⇒ Object



45
46
47
# File 'lib/gherkin/formatter/json_formatter.rb', line 45

def examples(examples)
  all_examples << examples.to_hash
end

#feature(feature) ⇒ Object



26
27
28
# File 'lib/gherkin/formatter/json_formatter.rb', line 26

def feature(feature)
  @gherkin_object = feature.to_hash
end

#match(match) ⇒ Object



53
54
55
# File 'lib/gherkin/formatter/json_formatter.rb', line 53

def match(match)
  last_step['match'] = match.to_hash
end

#result(result) ⇒ Object



57
58
59
# File 'lib/gherkin/formatter/json_formatter.rb', line 57

def result(result)
  last_step['result'] = result.to_hash
end

#scenario(scenario) ⇒ Object



37
38
39
# File 'lib/gherkin/formatter/json_formatter.rb', line 37

def scenario(scenario)
  feature_elements << scenario.to_hash
end

#scenario_outline(scenario_outline) ⇒ Object



41
42
43
# File 'lib/gherkin/formatter/json_formatter.rb', line 41

def scenario_outline(scenario_outline)
  feature_elements << scenario_outline.to_hash
end

#step(step) ⇒ Object



49
50
51
# File 'lib/gherkin/formatter/json_formatter.rb', line 49

def step(step)
  current_steps << step.to_hash
end

#steps(steps) ⇒ Object



30
31
# File 'lib/gherkin/formatter/json_formatter.rb', line 30

def steps(steps)
end

#uri(uri) ⇒ Object



21
22
23
24
# File 'lib/gherkin/formatter/json_formatter.rb', line 21

def uri(uri)
  # We're ignoring the uri - we don't want it as part of the JSON
  # (The pretty formatter uses it just for visual niceness - comments)
end