Sha256: be92068060d90bc72f9d2a761a5acf8401e81ec25a7b5a00c597c711df0c9db4

Contents?: true

Size: 1.27 KB

Versions: 13

Compression:

Stored size: 1.27 KB

Contents

module TestCentricity
  class ExceptionQueue
    include Capybara::DSL

    @error_queue

    def self.enqueue_assert_equal(expected, actual, error_message)
      unless expected == actual
        enqueue("#{error_message} to be\n  #{expected}\nbut found\n  #{actual}")
        enqueue_screenshot
      end
    end

    def self.enqueue_assert_not_equal(expected, actual, error_message)
      unless expected != actual
        enqueue("#{error_message} to not be equal to #{expected}")
        enqueue_screenshot
      end
    end

    def self.enqueue_exception(error_message)
      enqueue(error_message)
    end

    def self.post_exceptions
      raise @error_queue unless @error_queue.nil?
    ensure
      @error_queue = nil
    end

    private

    def self.enqueue(message)
      @error_queue = "#{@error_queue}#{message}\n\n"
    end

    def self.enqueue_screenshot
      timestamp = Time.now.strftime('%Y%m%d%H%M%S')
      filename = "Screenshot-#{timestamp}"
      path = File.join Dir.pwd, 'reports/screenshots/', filename
      Capybara.save_screenshot "#{path}.png"
      puts "Screenshot saved at #{path}.png"
      screen_shot = { :path => path, :filename => filename }
      Environ.save_screen_shot(screen_shot)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
testcentricity_web-2.0.5 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.0.4 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.0.3 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.0.2 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.0.1 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.0.0 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-1.0.23 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-1.0.22 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-1.0.21 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-1.0.20 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-1.0.19 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-1.0.18 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-1.0.17 lib/testcentricity_web/exception_queue_helper.rb