Skip to content

Commit c813887

Browse files
committed
Minor: Simplify specs
1 parent 7164928 commit c813887

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

spec/datadog/core/crashtracking/component_spec.rb

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144

145145
let(:agent_base_url) { "http://#{hostname}:#{http_server_port}" }
146146

147-
# exception only gets stack attached when raised
148147
def method_that_raises
149148
raise StandardError, 'Test unhandled exception with backtrace'
150149
end
@@ -160,31 +159,16 @@ def method_that_raises
160159

161160
crashtracker.report_unhandled_exception(exception)
162161

163-
# Wait for both crash ping and crash report to be sent
164162
try_wait_until { messages.length == 2 }
165163

166-
parsed_messages = messages.map { |msg| JSON.parse(msg.body.to_s, symbolize_names: true) }
164+
parsed_messages = messages.map { |msg| JSON.parse(msg.body.to_s, symbolize_names: true).fetch(:payload).fetch(:logs).first }
167165

168-
# Don't assume order on network requests
169-
# We send crash ping first, but it is sent in separate requests
170-
# We are not guaranteed the order of the messages received in the array
171-
#
172-
# Find crash ping message (should have is_crash_ping:true tag)
173-
crash_ping_message = parsed_messages.find do |msg|
174-
payload = msg[:payload][:logs].first
175-
payload[:tags]&.include?('is_crash_ping:true')
176-
end
177-
expect(crash_ping_message).to_not be_nil
178-
179-
# Find crash report message (should have is_crash:true)
180-
crash_report_message = parsed_messages.find do |msg|
181-
payload = msg[:payload][:logs].first
182-
payload[:is_crash] == true
183-
end
166+
expect(parsed_messages).to include(
167+
a_hash_including(is_crash: false, tags: a_string_including('is_crash_ping')),
168+
a_hash_including(is_crash: true),
169+
)
184170

185-
# Verify crash report content
186-
crash_payload = crash_report_message[:payload][:logs].first
187-
crash_report = JSON.parse(crash_payload[:message], symbolize_names: true)
171+
crash_report = JSON.parse(parsed_messages.find { |msg| msg[:is_crash] == true }.fetch(:message), symbolize_names: true)
188172

189173
# Verify metadata (ddog_crasht_CrashInfoBuilder_with_metadata)
190174
expect(crash_report[:metadata]).to include(

0 commit comments

Comments
 (0)