Class: Datadog::CI::Contrib::Cucumber::Formatter
- Inherits:
-
Object
- Object
- Datadog::CI::Contrib::Cucumber::Formatter
- Defined in:
- lib/datadog/ci/contrib/cucumber/formatter.rb
Overview
Defines collection of instrumented Cucumber events
Instance Method Summary collapse
- #bind_events(config) ⇒ Object
-
#initialize(config) ⇒ Formatter
constructor
A new instance of Formatter.
- #on_test_case_finished(event) ⇒ Object
- #on_test_case_started(event) ⇒ Object
- #on_test_run_finished(event) ⇒ Object
- #on_test_run_started(event) ⇒ Object
- #on_test_step_finished(event) ⇒ Object
- #on_test_step_started(event) ⇒ Object
Constructor Details
#initialize(config) ⇒ Formatter
Returns a new instance of Formatter.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/datadog/ci/contrib/cucumber/formatter.rb', line 18 def initialize(config) @ast_lookup = ::Cucumber::Formatter::AstLookup.new(config) if defined?(::Cucumber::Formatter::AstLookup) @config = config @current_test_suite = nil @failed_test_suites_count = 0 bind_events(config) end |
Instance Method Details
#bind_events(config) ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/datadog/ci/contrib/cucumber/formatter.rb', line 29 def bind_events(config) config.on_event :test_run_started, &method(:on_test_run_started) config.on_event :test_run_finished, &method(:on_test_run_finished) config.on_event :test_case_started, &method(:on_test_case_started) config.on_event :test_case_finished, &method(:on_test_case_finished) config.on_event :test_step_started, &method(:on_test_step_started) config.on_event :test_step_finished, &method(:on_test_step_finished) end |
#on_test_case_finished(event) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/datadog/ci/contrib/cucumber/formatter.rb', line 92 def on_test_case_finished(event) test_span = test_visibility_component.active_test return if test_span.nil? finish_span(test_span, event.result) end |
#on_test_case_started(event) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/datadog/ci/contrib/cucumber/formatter.rb', line 59 def on_test_case_started(event) test_suite_name = test_suite_name(event.test_case) # @type var tags: Hash[String, String] = { CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK, CI::Ext::Test::TAG_FRAMEWORK_VERSION => datadog_integration.version.to_s, CI::Ext::Test::TAG_SOURCE_FILE => Git::LocalRepository.relative_to_root(event.test_case.location.file), CI::Ext::Test::TAG_SOURCE_START => event.test_case.location.line.to_s } if (parameters = extract_parameters_hash(event.test_case)) [CI::Ext::Test::TAG_PARAMETERS] = Utils::TestRun.test_parameters(arguments: parameters) end unless same_test_suite_as_current?(test_suite_name) start_test_suite( test_suite_name, tags: (event.test_case) ) end test_span = test_visibility_component.trace_test( event.test_case.name, test_suite_name, tags: , service: datadog_configuration[:service_name] ) if event.test_case.("@#{CI::Ext::Test::ITR_UNSKIPPABLE_OPTION}") test_span&.itr_unskippable! end end |
#on_test_run_finished(event) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/datadog/ci/contrib/cucumber/formatter.rb', line 49 def on_test_run_finished(event) finish_current_test_suite if event.respond_to?(:success) finish_session(event.success) else finish_session(@failed_test_suites_count.zero?) end end |
#on_test_run_started(event) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/datadog/ci/contrib/cucumber/formatter.rb', line 38 def on_test_run_started(event) test_visibility_component.start_test_session( tags: { CI::Ext::Test::TAG_FRAMEWORK => Ext::FRAMEWORK, CI::Ext::Test::TAG_FRAMEWORK_VERSION => datadog_integration.version.to_s }, service: datadog_configuration[:service_name] ) test_visibility_component.start_test_module(Ext::FRAMEWORK) end |
#on_test_step_finished(event) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/datadog/ci/contrib/cucumber/formatter.rb', line 103 def on_test_step_finished(event) current_step_span = test_visibility_component.active_span return if current_step_span.nil? finish_span(current_step_span, event.result) end |
#on_test_step_started(event) ⇒ Object
99 100 101 |
# File 'lib/datadog/ci/contrib/cucumber/formatter.rb', line 99 def on_test_step_started(event) test_visibility_component.trace(event.test_step.to_s, type: Ext::STEP_SPAN_TYPE) end |