Module: Kensho
- Defined in:
- lib/kensho/cucumber/state.rb,
lib/kensho/_schema.rb,
lib/kensho/cucumber.rb,
lib/kensho/cucumber/helpers.rb,
lib/kensho/cucumber/version.rb,
lib/kensho/cucumber/formatter.rb
Overview
Cucumber 7+ formatter that emits Kensho v1 results.
Cucumber-Ruby’s formatter API gives us a ‘Cucumber::Configuration` and a `config.on_event(:event_name)` event bus. We subscribe to:
:test_run_started — open the output dir
:test_case_started — start accumulating per-scenario data
:test_step_finished — append a step result
:test_case_finished — write cases/<id>.json
:test_run_finished — write run.json
Each scenario becomes a Kensho case; each Gherkin step becomes a Kensho step. Data tables on a step are emitted as ‘step.parameters[]`. The scenario’s ‘attach` calls (Cucumber’s built-in attachment API) are routed into ‘case.attachments[]`.
Tags drive metadata:
@severity:critical → case.severity
@critical / @blocker / ... → case.severity (shorthand)
@kensho.label.team=growth → case.labels.team = 'growth'
@kensho.link.jira=PROJ-123 → case.links += { kind: 'jira', label: 'PROJ-123', url: 'PROJ-123' }
@kensho.url.jira=https://… → case.links (full url form)
any other @tag → case.tags
Defined Under Namespace
Class Method Summary collapse
- .current_case_id ⇒ Object
-
.description(text) ⇒ Object
Set case.description.
-
.epic(name) ⇒ Object
behavior.epic + labels.epic.
-
.feature(name) ⇒ Object
behavior.feature + labels.feature.
-
.flaky ⇒ Object
Mark the running scenario flaky.
-
.jira_link(id_or_url, label = nil) ⇒ Object
A Jira/issue link.
-
.known_issue(id_or_url, label = nil) ⇒ Object
A known issue: mutes the scenario and records an ‘issue’ link.
- .label(key, value) ⇒ Object
-
.link(url, name = nil, kind: nil, label: nil) ⇒ Object
Add a hyperlink.
-
.muted ⇒ Object
Mark the running scenario muted (known failure not counted by the gate).
-
.owner(value) ⇒ Object
Set case.owner.
-
.parameter(name, value) ⇒ Object
Add a parameter (name/value).
-
.reference_link(url, label = nil) ⇒ Object
A reference/documentation link.
-
.severity(value) ⇒ Object
Set case.severity.
-
.story(name) ⇒ Object
behavior.scenario + labels.story.
-
.tag(name) ⇒ Object
Add a tag.
Class Method Details
.current_case_id ⇒ Object
136 137 138 139 |
# File 'lib/kensho/cucumber/helpers.rb', line 136 def current_case_id scratch = Kensho::Cucumber::State.current scratch && scratch[:case_obj] ? scratch[:case_obj]['id'] : nil end |
.description(text) ⇒ Object
Set case.description.
78 79 80 81 82 83 84 |
# File 'lib/kensho/cucumber/helpers.rb', line 78 def description(text) scratch = Kensho::Cucumber::State.current return if scratch.nil? || text.nil? scratch[:rt_description] = text.to_s nil end |
.epic(name) ⇒ Object
behavior.epic + labels.epic
44 45 46 |
# File 'lib/kensho/cucumber/helpers.rb', line 44 def epic(name) apply_behavior_runtime('epic', 'epic', name) end |
.feature(name) ⇒ Object
behavior.feature + labels.feature
49 50 51 |
# File 'lib/kensho/cucumber/helpers.rb', line 49 def feature(name) apply_behavior_runtime('feature', 'feature', name) end |
.flaky ⇒ Object
Mark the running scenario flaky.
109 110 111 112 113 114 115 |
# File 'lib/kensho/cucumber/helpers.rb', line 109 def flaky scratch = Kensho::Cucumber::State.current return if scratch.nil? scratch[:flaky] = true nil end |
.jira_link(id_or_url, label = nil) ⇒ Object
A Jira/issue link. ‘id_or_url` may be a bare ticket id or a full URL.
34 35 36 |
# File 'lib/kensho/cucumber/helpers.rb', line 34 def jira_link(id_or_url, label = nil) add_link(id_or_url, kind: 'issue', label: label || id_or_url) end |
.known_issue(id_or_url, label = nil) ⇒ Object
A known issue: mutes the scenario and records an ‘issue’ link.
127 128 129 130 131 132 133 134 |
# File 'lib/kensho/cucumber/helpers.rb', line 127 def known_issue(id_or_url, label = nil) scratch = Kensho::Cucumber::State.current return if scratch.nil? scratch[:muted] = true jira_link(id_or_url, label) nil end |
.label(key, value) ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/kensho/cucumber/helpers.rb', line 20 def label(key, value) scratch = Kensho::Cucumber::State.current return if scratch.nil? || key.nil? || key.to_s.empty? (scratch[:rt_labels] ||= {})[key.to_s] = value.to_s nil end |
.link(url, name = nil, kind: nil, label: nil) ⇒ Object
Add a hyperlink. Positional ‘name` is the human label. Kind ’link’.
29 30 31 |
# File 'lib/kensho/cucumber/helpers.rb', line 29 def link(url, name = nil, kind: nil, label: nil) add_link(url, kind: kind || 'link', label: name || label) end |
.muted ⇒ Object
Mark the running scenario muted (known failure not counted by the gate).
118 119 120 121 122 123 124 |
# File 'lib/kensho/cucumber/helpers.rb', line 118 def muted scratch = Kensho::Cucumber::State.current return if scratch.nil? scratch[:muted] = true nil end |
.owner(value) ⇒ Object
Set case.owner.
69 70 71 72 73 74 75 |
# File 'lib/kensho/cucumber/helpers.rb', line 69 def owner(value) scratch = Kensho::Cucumber::State.current return if scratch.nil? || value.nil? scratch[:rt_owner] = value.to_s nil end |
.parameter(name, value) ⇒ Object
Add a parameter (name/value). No kind.
100 101 102 103 104 105 106 |
# File 'lib/kensho/cucumber/helpers.rb', line 100 def parameter(name, value) scratch = Kensho::Cucumber::State.current return if scratch.nil? || name.nil? || name.to_s.empty? (scratch[:rt_parameters] ||= []) << { 'name' => name.to_s, 'value' => value.to_s } nil end |
.reference_link(url, label = nil) ⇒ Object
A reference/documentation link. Kind ‘reference’.
39 40 41 |
# File 'lib/kensho/cucumber/helpers.rb', line 39 def reference_link(url, label = nil) add_link(url, kind: 'reference', label: label) end |
.severity(value) ⇒ Object
Set case.severity. Only the five canonical names are accepted.
59 60 61 62 63 64 65 66 |
# File 'lib/kensho/cucumber/helpers.rb', line 59 def severity(value) scratch = Kensho::Cucumber::State.current return if scratch.nil? || value.nil? v = value.to_s scratch[:rt_severity] = v if Kensho::Schema::SEVERITY.include?(v) nil end |
.story(name) ⇒ Object
behavior.scenario + labels.story
54 55 56 |
# File 'lib/kensho/cucumber/helpers.rb', line 54 def story(name) apply_behavior_runtime('scenario', 'story', name) end |
.tag(name) ⇒ Object
Add a tag. Strips a leading ‘@’ and de-dupes.
87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/kensho/cucumber/helpers.rb', line 87 def tag(name) scratch = Kensho::Cucumber::State.current return if scratch.nil? || name.nil? t = name.to_s.sub(/\A@/, '') return if t.empty? = (scratch[:rt_tags] ||= []) << t unless .include?(t) nil end |