Class: Gherkin::Formatter::JSONFormatter

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

Instance Method Summary collapse

Methods included from Rubify

#rubify

Constructor Details

#initialize(io) ⇒ JSONFormatter

Returns a new instance of JSONFormatter.



10
11
12
# File 'lib/gherkin/formatter/json_formatter.rb', line 10

def initialize(io)
  @io = io
end

Instance Method Details

#background(statement) ⇒ Object



19
20
21
22
# File 'lib/gherkin/formatter/json_formatter.rb', line 19

def background(statement)
  @json_hash['background'] = statement_hash(nil, statement) 
  @in_background = true
end

#eofObject



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

def eof
  @io.write(@json_hash.to_json)
end

#examples(statement, examples_rows) ⇒ Object



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

def examples(statement, examples_rows)
  @table_container = add_examples(statement)
  @table_container['table'] = to_hash_array(examples_rows)
end

#feature(statement, uri) ⇒ Object



14
15
16
17
# File 'lib/gherkin/formatter/json_formatter.rb', line 14

def feature(statement, uri)
  @json_hash = statement_hash(nil, statement)
  @json_hash['uri'] = uri
end

#scenario(statement) ⇒ Object



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

def scenario(statement)
  @in_background = false
  add_step_container('scenario', statement)
end

#scenario_outline(statement) ⇒ Object



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

def scenario_outline(statement)
  @in_background = false
  add_step_container('scenario_outline', statement)
end

#step(statement, multiline_arg, result) ⇒ Object



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

def step(statement, multiline_arg, result)
  @table_container = statement_hash(nil, statement).merge(step_arg_to_hash(multiline_arg))
  last_element['steps'] ||= []
  last_element['steps'] << @table_container
end