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

Inherits:
Object
  • Object
show all
Defined in:
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.



236
237
238
239
240
241
242
243
# File 'lib/cucumber/formatter/json.rb', line 236

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.



234
235
236
# File 'lib/cucumber/formatter/json.rb', line 234

def background_hash
  @background_hash
end

#feature_hashObject (readonly)

Returns the value of attribute feature_hash.



234
235
236
# File 'lib/cucumber/formatter/json.rb', line 234

def feature_hash
  @feature_hash
end

#test_case_hashObject (readonly)

Returns the value of attribute test_case_hash.



234
235
236
# File 'lib/cucumber/formatter/json.rb', line 234

def test_case_hash
  @test_case_hash
end

Instance Method Details

#background(background) ⇒ Object



263
264
265
266
267
268
269
270
271
272
# File 'lib/cucumber/formatter/json.rb', line 263

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)


245
246
247
# File 'lib/cucumber/formatter/json.rb', line 245

def background?
  @background_hash != nil
end

#feature(feature, uri) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/cucumber/formatter/json.rb', line 249

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



274
275
276
277
278
279
280
281
282
283
284
285
286
# File 'lib/cucumber/formatter/json.rb', line 274

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