Module: ExecutableStories

Defined in:
lib/executable_stories.rb,
lib/executable_stories/rspec.rb,
lib/executable_stories/story.rb,
lib/executable_stories/types.rb,
lib/executable_stories/output.rb,
lib/executable_stories/minitest.rb,
lib/executable_stories/collector.rb,
lib/executable_stories/doc_entry.rb,
lib/executable_stories/json_writer.rb

Defined Under Namespace

Modules: Collector, DocEntry, JsonWriter, MinitestPlugin, Output, RSpecPlugin, RSpecStoryDSL Classes: RSpecFormatter, RawAttachment, RawCIInfo, RawError, RawRun, RawStepEvent, RawTestCase, Story, StoryMeta, StoryStep, Ticket

Class Method Summary collapse

Class Method Details

.attachment_to_h(att) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/executable_stories/types.rb', line 85

def attachment_to_h(att)
  h = {
    "name" => att.name,
    "mediaType" => att.media_type
  }
  h["path"] = att.path if att.path
  h["body"] = att.body if att.body
  h["encoding"] = att.encoding if att.encoding
  h["charset"] = att.charset if att.charset
  h["fileName"] = att.file_name if att.file_name
  h["byteLength"] = att.byte_length if att.byte_length
  h["stepIndex"] = att.step_index unless att.step_index.nil?
  h["stepId"] = att.step_id if att.step_id
  h
end

.ci_info_to_h(ci) ⇒ Object



128
129
130
131
132
133
# File 'lib/executable_stories/types.rb', line 128

def ci_info_to_h(ci)
  h = { "name" => ci.name }
  h["url"] = ci.url if ci.url
  h["buildNumber"] = ci.build_number if ci.build_number
  h
end

.error_to_h(error) ⇒ Object



78
79
80
81
82
83
# File 'lib/executable_stories/types.rb', line 78

def error_to_h(error)
  h = {}
  h["message"] = error.message if error.message
  h["stack"] = error.stack if error.stack
  h
end

.init(scenario, **opts) ⇒ Object



415
416
417
# File 'lib/executable_stories/story.rb', line 415

def init(scenario, **opts)
  Story.new(scenario, **opts)
end

.meta_to_h(meta) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/executable_stories/types.rb', line 57

def meta_to_h(meta)
  h = {
    "scenario" => meta.scenario,
    "steps" => meta.steps.map { |s| s.is_a?(StoryStep) ? step_to_h(s) : s }
  }
  h["tags"] = meta.tags if meta.tags && !meta.tags.empty?
  h["tickets"] = meta.tickets.map { |t| t.is_a?(Ticket) ? ticket_to_h(t) : t } if meta.tickets && !meta.tickets.empty?
  h["meta"] = meta.meta if meta.meta
  h["suitePath"] = meta.suite_path if meta.suite_path
  h["docs"] = meta.docs if meta.docs && !meta.docs.empty?
  h["sourceOrder"] = meta.source_order unless meta.source_order.nil?
  h["otelSpans"] = meta.otel_spans if meta.otel_spans
  h
end

.run_to_h(run) ⇒ Object



135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/executable_stories/types.rb', line 135

def run_to_h(run)
  h = {
    "schemaVersion" => run.schema_version,
    "testCases" => run.test_cases.map { |tc| test_case_to_h(tc) },
    "projectRoot" => run.project_root
  }
  h["startedAtMs"] = run.started_at_ms unless run.started_at_ms.nil?
  h["finishedAtMs"] = run.finished_at_ms unless run.finished_at_ms.nil?
  h["packageVersion"] = run.package_version if run.package_version
  h["gitSha"] = run.git_sha if run.git_sha
  h["ci"] = ci_info_to_h(run.ci) if run.ci
  h["meta"] = run.meta if run.meta
  h
end

.step_event_to_h(event) ⇒ Object



101
102
103
104
105
106
107
108
# File 'lib/executable_stories/types.rb', line 101

def step_event_to_h(event)
  h = {}
  h["index"] = event.index unless event.index.nil?
  h["title"] = event.title if event.title
  h["status"] = event.status if event.status
  h["durationMs"] = event.duration_ms if event.duration_ms
  h
end

.step_to_h(step) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/executable_stories/types.rb', line 44

def step_to_h(step)
  h = {
    "keyword" => step.keyword,
    "text" => step.text
  }
  h["id"] = step.id if step.id
  h["mode"] = step.mode if step.mode
  h["wrapped"] = step.wrapped if step.wrapped
  h["durationMs"] = step.duration_ms if step.duration_ms
  h["docs"] = step.docs.map { |d| d.is_a?(Hash) ? d : d.to_h } if step.docs && !step.docs.empty?
  h
end

.test_case_to_h(tc) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/executable_stories/types.rb', line 110

def test_case_to_h(tc)
  h = { "status" => tc.status }
  h["externalId"] = tc.external_id if tc.external_id
  h["title"] = tc.title if tc.title
  h["titlePath"] = tc.title_path if tc.title_path
  h["story"] = meta_to_h(tc.story) if tc.story
  h["sourceFile"] = tc.source_file if tc.source_file
  h["sourceLine"] = tc.source_line if tc.source_line
  h["durationMs"] = tc.duration_ms if tc.duration_ms
  h["error"] = error_to_h(tc.error) if tc.error
  h["meta"] = tc.meta if tc.meta
  h["retry"] = tc.retry unless tc.retry.nil?
  h["retries"] = tc.retries unless tc.retries.nil?
  h["attachments"] = tc.attachments.map { |a| attachment_to_h(a) } if tc.attachments && !tc.attachments.empty?
  h["stepEvents"] = tc.step_events.map { |e| step_event_to_h(e) } if tc.step_events && !tc.step_events.empty?
  h
end

.ticket_to_h(ticket) ⇒ Object



72
73
74
75
76
# File 'lib/executable_stories/types.rb', line 72

def ticket_to_h(ticket)
  h = { "id" => ticket.id }
  h["url"] = ticket.url if ticket.url
  h
end