Skip to content

Commit

Permalink
Merge 6cfb05b into b40e3a6
Browse files Browse the repository at this point in the history
  • Loading branch information
pomier committed Jan 30, 2019
2 parents b40e3a6 + 6cfb05b commit 7915886
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/exception_notifier/slack_notifier.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ def deep_reject(hash, block)

def attchs(exception, clean_message, options)
text, data = information_from_options(exception.class, options)
fields = fields(clean_message, exception.backtrace, data)
backtrace = clean_backtrace(exception) if exception.backtrace
fields = fields(clean_message, backtrace, data)

[color: @color, text: text, fields: fields, mrkdwn_in: %w[text fields]]
end
Expand Down
7 changes: 6 additions & 1 deletion test/exception_notifier/slack_notifier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ def setup
@exception = fake_exception
@exception.stubs(:backtrace).returns(fake_backtrace)
@exception.stubs(:message).returns('exception message')
ExceptionNotifier::SlackNotifier.any_instance.stubs(:clean_backtrace).returns(fake_cleaned_backtrace)
Socket.stubs(:gethostname).returns('example.com')
end

Expand Down Expand Up @@ -192,6 +193,10 @@ def fake_backtrace
]
end

def fake_cleaned_backtrace
fake_backtrace[2..-1]
end

def fake_notification(exception = @exception, notification_options = {}, data_string = nil, expected_backtrace_lines = 10, additional_fields = [])
exception_name = "*#{exception.class.to_s =~ /^[aeiou]/i ? 'An' : 'A'}* `#{exception.class}`"
if notification_options[:env].nil?
Expand All @@ -211,7 +216,7 @@ def fake_notification(exception = @exception, notification_options = {}, data_st
fields = [{ title: 'Exception', value: exception.message }]
fields.push(title: 'Hostname', value: 'example.com')
if exception.backtrace
formatted_backtrace = "```#{exception.backtrace.first(expected_backtrace_lines).join("\n")}```"
formatted_backtrace = "```#{fake_cleaned_backtrace.first(expected_backtrace_lines).join("\n")}```"
fields.push(title: 'Backtrace', value: formatted_backtrace)
end
fields.push(title: 'Data', value: "```#{data_string}```") if data_string
Expand Down

0 comments on commit 7915886

Please sign in to comment.