Module: QAT::Formatter::Loggable::Mdc

Includes:
ScenarioInfo
Included in:
QAT::Formatter::Loggable
Defined in:
lib/qat/formatter/loggable/mdc.rb

Overview

Helper module to manage loggable mdc information

Since:

  • 2.0.2

Instance Method Summary collapse

Instance Method Details

#mdc_add_status_failed!Object

Since:

  • 2.0.2



68
69
70
# File 'lib/qat/formatter/loggable/mdc.rb', line 68

def mdc_add_status_failed!
  Log4r::MDC.put 'status', 'failed'
end

#mdc_add_step!(step_name) ⇒ Object

Set the MDC key ‘step’ with the given value.

Parameters:

  • step_name (String)

    Name of the current step

Since:

  • 0.1.0



58
59
60
# File 'lib/qat/formatter/loggable/mdc.rb', line 58

def mdc_add_step!(step_name)
  Log4r::MDC.put 'step', step_name
end

#mdc_after_feature!Object

Remove the MDC key ‘feature’.

Since:

  • 0.1.0



21
22
23
# File 'lib/qat/formatter/loggable/mdc.rb', line 21

def mdc_after_feature!
  Log4r::MDC.remove 'feature'
end

#mdc_before_feature!(feature_name) ⇒ Object

Set the MDC key ‘feature’ with the given value.

Parameters:

  • feature_name (String)

    Name of the current feature

Since:

  • 0.1.0



15
16
17
# File 'lib/qat/formatter/loggable/mdc.rb', line 15

def mdc_before_feature!(feature_name)
  Log4r::MDC.put 'feature', feature_name
end

#mdc_before_scenario!(scenario_name, tags, outline_number = nil, outline_example = nil) ⇒ Object

Set the MDC key ‘scenario’ with the given value. Optionally scenario outline data can also be provided

Parameters:

  • scenario_name (String)

    Name of the current feature

  • tags (Array<String>)

    List of tags

  • outline_number (Integer) (defaults to: nil)

    Number of the current scenario outline

  • outline_example (Array<String>) (defaults to: nil)

    Values of the current outline’s example row

Since:

  • 0.1.0



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/qat/formatter/loggable/mdc.rb', line 32

def mdc_before_scenario!(scenario_name, tags, outline_number = nil, outline_example = nil)
  mdc_reset_scenario!
  Log4r::MDC.put 'scenario', scenario_name

  test_id = test_id(tags, outline_number)
  Log4r::MDC.put 'test_id', test_id
  loggable_tags = tags.reject { |tag| tag.match(/^\@test\#/) }
  Log4r::MDC.put 'tags', loggable_tags

  Log4r::MDC.put 'outline_number', outline_number if outline_number
  Log4r::MDC.put 'outline_example', outline_example if outline_example
end

#mdc_remove_step!Object

Remove the MDC key ‘step’.

Since:

  • 0.1.0



64
65
66
# File 'lib/qat/formatter/loggable/mdc.rb', line 64

def mdc_remove_step!
  Log4r::MDC.remove 'step'
end

#mdc_reset_scenario!Object

Remove the MDC key ‘scenario’. Other options set in #mdc_before_scenario! will also be unset.

Since:

  • 0.1.0



47
48
49
50
51
52
53
# File 'lib/qat/formatter/loggable/mdc.rb', line 47

def mdc_reset_scenario!
  mdc_remove_step!
  Log4r::MDC.remove 'scenario'
  Log4r::MDC.remove 'tags'
  Log4r::MDC.remove 'outline_number'
  Log4r::MDC.remove 'outline_example'
end