Class: SauceDocumentation

Inherits:
RSpec::Core::Formatters::DocumentationFormatter
  • Object
show all
Defined in:
lib/sauce_documentation/sauce_documentation.rb

Instance Method Summary collapse

Instance Method Details

#dump_failures(notification) ⇒ Object

Modifying the exception backtrace causes the default formatter to prepend #

If the link is outputted after failure.fully_formatted then the backtrace will always appear before the Sauce job link

By updating the exception message with instance_eval, the job link will show up after the message and before the backtrace without additional formatting.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sauce_documentation/sauce_documentation.rb', line 15

def dump_failures(notification)
  failure_notifications = notification.failure_notifications
  return if failure_notifications.empty?

  failure_notifications.each do |failure|
    exception = failure.exception
    next unless exception

    sauce_test_link = failure.example.[:sauce_test_link]
    next unless sauce_test_link

    # Use nonbreaking space to bypass message.strip and ensure we have
    # a newline after the message and before the stack trace.
    nbsp = "\u00A0"
    message = "#{exception.message}\n#{sauce_test_link}\n#{nbsp}"
    exception.instance_eval "      def message\n        %q(\#{message})\n      end\n\n      def to_s\n        message\n      end\n    RUBY\n  end\n\n  # Use default RSpec logic to format the failures now that we've\n  # attached the Sauce test link to the exceptions\n  super\nend\n"