class Cucumber::Formatter::Json::Builder
Attributes
background_hash[R]
feature_hash[R]
test_case_hash[R]
Public Class Methods
new(test_case, ast_lookup)
click to toggle source
# File lib/cucumber/formatter/json.rb, line 239 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
Public Instance Methods
background(background)
click to toggle source
# File lib/cucumber/formatter/json.rb, line 265 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
background?()
click to toggle source
# File lib/cucumber/formatter/json.rb, line 248 def background? @background_hash != nil end
feature(feature, uri)
click to toggle source
# File lib/cucumber/formatter/json.rb, line 252 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
scenario(scenario_source, test_case)
click to toggle source
# File lib/cucumber/formatter/json.rb, line 276 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
Private Instance Methods
calculate_row_number(scenario_source)
click to toggle source
# File lib/cucumber/formatter/json.rb, line 311 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
create_id(name)
click to toggle source
# File lib/cucumber/formatter/json.rb, line 296 def create_id(name) name.downcase.tr(' ', '-') end
create_id_from_scenario_source(scenario_source)
click to toggle source
# File lib/cucumber/formatter/json.rb, line 300 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
value_or_empty_string(value)
click to toggle source
# File lib/cucumber/formatter/json.rb, line 292 def value_or_empty_string(value) value.nil? ? '' : value end