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.


230
231
232
233
234
235
236
237
# File 'lib/cucumber/formatter/json.rb', line 230

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


228
229
230
# File 'lib/cucumber/formatter/json.rb', line 228

def background_hash
  @background_hash
end

#feature_hashObject (readonly)

Returns the value of attribute feature_hash


228
229
230
# File 'lib/cucumber/formatter/json.rb', line 228

def feature_hash
  @feature_hash
end

#test_case_hashObject (readonly)

Returns the value of attribute test_case_hash


228
229
230
# File 'lib/cucumber/formatter/json.rb', line 228

def test_case_hash
  @test_case_hash
end

Instance Method Details

#background(background) ⇒ Object


256
257
258
259
260
261
262
263
264
# File 'lib/cucumber/formatter/json.rb', line 256

def background(background)
  @background_hash = {
    keyword: background[:keyword],
    name: background[:name],
    description: value_or_empty_string(background[:description]),
    line: background[:location][:line],
    type: 'background'
  }
end

#background?Boolean

Returns:

  • (Boolean)

239
240
241
# File 'lib/cucumber/formatter/json.rb', line 239

def background?
  @background_hash != nil
end

#feature(feature, uri) ⇒ Object


243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/cucumber/formatter/json.rb', line 243

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


266
267
268
269
270
271
272
273
274
275
276
277
# File 'lib/cucumber/formatter/json.rb', line 266

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: scenario[:name],
    description: value_or_empty_string(scenario[:description]),
    line: test_case.location.lines.max,
    type: 'scenario'
  }
  @test_case_hash[:tags] = create_tags_array_from_tags_array(test_case.tags) unless test_case.tags.empty?
end