class Cucumber::Formatter::Json::Builder
def background(background)
def background(background) @background_hash = { keyword: background.keyword, name: background.name, description: value_or_empty_string(background.description), line: background.location.line, type: 'background', steps: [] } end
def background?
def background? @background_hash != nil end
def calculate_row_number(scenario_source)
def calculate_row_number(scenario_source) scenario_source.examples.table_body.each_with_index do |row, index| return index + 2 if row == scenario_source.row end end
def create_id(name)
def create_id(name) name.downcase.tr(' ', '-') end
def create_id_from_scenario_source(scenario_source)
def create_id_from_scenario_source(scenario_source) if scenario_source.type == :Scenario create_id(scenario_source.scenario.name) else scenario_outline_name = scenario_source.scenario_outline.name examples_name = scenario_source.examples.name row_number = calculate_row_number(scenario_source) "#{create_id(scenario_outline_name)};#{create_id(examples_name)};#{row_number}" end end
def create_tags_array_from_hash_array(tags)
def create_tags_array_from_hash_array(tags) tags_array = [] tags.each { |tag| tags_array << { name: tag.name, line: tag.location.line } } tags_array end
def create_tags_array_from_tags_array(tags)
def create_tags_array_from_tags_array(tags) tags_array = [] tags.each { |tag| tags_array << { name: tag.name, line: tag.location.line } } tags_array end
def feature(feature, uri)
def feature(feature, uri) @feature_hash = { id: create_id(feature.name), uri: uri, keyword: feature.keyword, name: feature.name, description: value_or_empty_string(feature.description), line: feature.location.line } return if feature.tags.empty? @feature_hash[:tags] = create_tags_array_from_hash_array(feature.tags) end
def initialize(test_case, ast_lookup)
def initialize(test_case, ast_lookup) @background_hash = nil uri = test_case.location.file feature = ast_lookup.gherkin_document(uri).feature feature(feature, uri) background(feature.children.first.background) unless feature.children.first.background.nil? scenario(ast_lookup.scenario_source(test_case), test_case) end
def scenario(scenario_source, test_case)
def scenario(scenario_source, test_case) scenario = scenario_source.type == :Scenario ? scenario_source.scenario : scenario_source.scenario_outline @test_case_hash = { id: "#{@feature_hash[:id]};#{create_id_from_scenario_source(scenario_source)}", keyword: scenario.keyword, name: test_case.name, description: value_or_empty_string(scenario.description), line: test_case.location.lines.max, type: 'scenario', steps: [] } @test_case_hash[:tags] = create_tags_array_from_tags_array(test_case.tags) unless test_case.tags.empty? end
def value_or_empty_string(value)
def value_or_empty_string(value) value.nil? ? '' : value end