Class: Cucumber::Formatter::Json::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/json.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(test_case, ast_lookup) ⇒ Builder

Returns a new instance of Builder.



240
241
242
243
244
245
246
247
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/json.rb', line 240

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

Instance Attribute Details

#background_hashObject (readonly)

Returns the value of attribute background_hash.



238
239
240
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/json.rb', line 238

def background_hash
  @background_hash
end

#feature_hashObject (readonly)

Returns the value of attribute feature_hash.



238
239
240
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/json.rb', line 238

def feature_hash
  @feature_hash
end

#test_case_hashObject (readonly)

Returns the value of attribute test_case_hash.



238
239
240
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/json.rb', line 238

def test_case_hash
  @test_case_hash
end

Instance Method Details

#background(background) ⇒ Object



267
268
269
270
271
272
273
274
275
276
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/json.rb', line 267

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?Boolean

Returns:

  • (Boolean)


249
250
251
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/json.rb', line 249

def background?
  @background_hash != nil
end

#feature(feature, uri) ⇒ Object



253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/json.rb', line 253

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) ⇒ Object



278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/json.rb', line 278

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