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

Returns a new instance of Builder



229
230
231
232
233
# File 'lib/cucumber/formatter/json.rb', line 229

def initialize(test_case)
  @background_hash = nil
  test_case.describe_source_to(self)
  test_case.feature.background.describe_to(self)
end

Instance Attribute Details

#background_hashObject (readonly)

Returns the value of attribute background_hash



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

def background_hash
  @background_hash
end

#feature_hashObject (readonly)

Returns the value of attribute feature_hash



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

def feature_hash
  @feature_hash
end

#test_case_hashObject (readonly)

Returns the value of attribute test_case_hash



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

def test_case_hash
  @test_case_hash
end

Instance Method Details

#background(background) ⇒ Object



260
261
262
263
264
265
266
267
268
269
# File 'lib/cucumber/formatter/json.rb', line 260

def background(background)
  @background_hash = {
    keyword: background.keyword,
    name: background.to_s,
    description: background.description,
    line: background.location.line,
    type: 'background'
  }
  @background_hash[:comments] = Formatter.create_comments_array(background.comments) unless background.comments.empty?
end

#background?Boolean

Returns:

  • (Boolean)


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

def background?
  @background_hash != nil
end

#examples_table(examples_table) ⇒ Object



304
305
306
307
308
309
310
311
# File 'lib/cucumber/formatter/json.rb', line 304

def examples_table(examples_table)
  # the json file have traditionally used the header row as row 1,
  # wheras cucumber-ruby-core used the first example row as row 1.
  @example_id = create_id(examples_table) + ";#{@row.number + 1}"

  @examples_table_tags = create_tags_array(examples_table.tags) unless examples_table.tags.empty?
  @examples_table_comments = Formatter.create_comments_array(examples_table.comments) unless examples_table.comments.empty?
end

#examples_table_row(row) ⇒ Object



313
314
315
316
# File 'lib/cucumber/formatter/json.rb', line 313

def examples_table_row(row)
  @row = row
  @row_comments = Formatter.create_comments_array(row.comments) unless row.comments.empty?
end

#feature(feature) ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
# File 'lib/cucumber/formatter/json.rb', line 239

def feature(feature)
  @feature_hash = {
    uri: feature.file,
    id: create_id(feature),
    keyword: feature.keyword,
    name: feature.to_s,
    description: feature.description,
    line: feature.location.line
  }
  unless feature.tags.empty?
    @feature_hash[:tags] = create_tags_array(feature.tags)
    @test_case_hash[:tags] = if @test_case_hash[:tags]
                               @feature_hash[:tags] + @test_case_hash[:tags]
                             else
                               @feature_hash[:tags]
                             end
  end
  @feature_hash[:comments] = Formatter.create_comments_array(feature.comments) unless feature.comments.empty?
  @test_case_hash[:id].insert(0, @feature_hash[:id] + ';')
end

#scenario(scenario) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/cucumber/formatter/json.rb', line 271

def scenario(scenario)
  @test_case_hash = {
    id: create_id(scenario),
    keyword: scenario.keyword,
    name: scenario.to_s,
    description: scenario.description,
    line: scenario.location.line,
    type: 'scenario'
  }
  @test_case_hash[:tags] = create_tags_array(scenario.tags) unless scenario.tags.empty?
  @test_case_hash[:comments] = Formatter.create_comments_array(scenario.comments) unless scenario.comments.empty?
end

#scenario_outline(scenario) ⇒ Object



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/cucumber/formatter/json.rb', line 284

def scenario_outline(scenario)
  @test_case_hash = {
    id: create_id(scenario) + ';' + @example_id,
    keyword: scenario.keyword,
    name: scenario.to_s,
    description: scenario.description,
    line: @row.location.line,
    type: 'scenario'
  }
  tags = []
  tags += create_tags_array(scenario.tags) unless scenario.tags.empty?
  tags += @examples_table_tags if @examples_table_tags
  @test_case_hash[:tags] = tags unless tags.empty?
  comments = []
  comments += Formatter.create_comments_array(scenario.comments) unless scenario.comments.empty?
  comments += @examples_table_comments if @examples_table_comments
  comments += @row_comments if @row_comments
  @test_case_hash[:comments] = comments unless comments.empty?
end