This class doesn’t really generate JSON - instead it populates an Array that can easily be turned into JSON.
# File lib/gherkin/formatter/json_formatter.rb, line 15 def initialize(io) raise "Must be writeable" unless io.respond_to?(:write) @io = io @feature_hashes = [] @current_step_or_hook = nil end
# File lib/gherkin/formatter/json_formatter.rb, line 69 def after(match, result) add_hook(match, result, "after") end
# File lib/gherkin/formatter/json_formatter.rb, line 36 def background(background) feature_elements << background.to_hash end
# File lib/gherkin/formatter/json_formatter.rb, line 65 def before(match, result) add_hook(match, result, "before") end
# File lib/gherkin/formatter/json_formatter.rb, line 22 def done @io.write(@feature_hashes.to_json) end
# File lib/gherkin/formatter/json_formatter.rb, line 73 def embedding(mime_type, data) embeddings << {'mime_type' => mime_type, 'data' => encode64s(data)} end
# File lib/gherkin/formatter/json_formatter.rb, line 81 def eof end
# File lib/gherkin/formatter/json_formatter.rb, line 48 def examples(examples) all_examples << examples.to_hash end
# File lib/gherkin/formatter/json_formatter.rb, line 30 def feature(feature) @feature_hash = feature.to_hash @feature_hash['uri'] = @uri @feature_hashes << @feature_hash end
# File lib/gherkin/formatter/json_formatter.rb, line 57 def match(match) @current_step_or_hook['match'] = match.to_hash end
# File lib/gherkin/formatter/json_formatter.rb, line 61 def result(result) @current_step_or_hook['result'] = result.to_hash end
# File lib/gherkin/formatter/json_formatter.rb, line 40 def scenario(scenario) feature_elements << scenario.to_hash end
# File lib/gherkin/formatter/json_formatter.rb, line 44 def scenario_outline(scenario_outline) feature_elements << scenario_outline.to_hash end
# File lib/gherkin/formatter/json_formatter.rb, line 52 def step(step) @current_step_or_hook = step.to_hash steps << @current_step_or_hook end
# File lib/gherkin/formatter/json_formatter.rb, line 26 def uri(uri) @uri = uri end
# File lib/gherkin/formatter/json_formatter.rb, line 77 def write(text) output << text end