Sha256: 13acf9ef9025b1e6a3a689238ed7d6ff036c64da36d00dad67a356a9517f696e

Contents?: true

Size: 1.37 KB

Versions: 2

Compression:

Stored size: 1.37 KB

Contents

class SauceDocumentation < RSpec::Core::Formatters::DocumentationFormatter
  RSpec::Core::Formatters.register self, :dump_failures

  #
  # 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.
  #

  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.metadata[: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 <<-RUBY
        def message
          %q(#{message})
        end

        def to_s
          message
        end
      RUBY
    end

    # Use default RSpec logic to format the failures now that we've
    # attached the Sauce test link to the exceptions
    super
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
sauce_documentation-0.0.4 lib/sauce_documentation/sauce_documentation.rb
sauce_documentation-0.0.3 lib/sauce_documentation/sauce_documentation.rb