Sha256: e75782b571ee2f01592042941f18f96a80b347f692d5fde5f00a949c06221085

Contents?: true

Size: 1.09 KB

Versions: 2

Compression:

Stored size: 1.09 KB

Contents

require_relative "html"
require_relative "browser_logs"
require_relative "notifier"

module WithClues
  module Method
    @@clue_classes = {
      require_page: [
        WithClues::BrowserLogs,
        WithClues::Html,
      ],
      custom: []
    }
    # Wrap any assertion with this method to get more
    # useful context and diagnostics when a test is
    # unexpectedly failing
    def with_clues(context=nil, &block)
      notifier = WithClues::Notifier.new($stdout)
      block.()
      notifier.notify "A passing test has been wrapped with `with_clues`. You should remove the call to `with_clues`"
    rescue Exception => ex
      notifier.notify context
      @@clue_classes[:custom].each do |klass|
        klass.new.dump(notifier, context: context)
      end
      if !defined?(page)
        raise ex
      end
      notifier.notify "Test failed: #{ex.message}"
      @@clue_classes[:require_page].each do |klass|
        klass.new.dump(notifier, context: context, page: page)
      end
      raise ex
    end

    def self.use_custom_clue(klass)
      @@clue_classes[:custom] << klass
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
with_clues-1.1.0 lib/with_clues/method.rb
with_clues-1.0.0 lib/with_clues/method.rb