Sha256: 5fc14357657d3b4721939f9b2f90810bbde2386413d728f344c53c4bceb24445

Contents?: true

Size: 1.27 KB

Versions: 49

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

49 entries across 49 versions & 1 rubygems

Version Path
testcentricity_web-2.3.15 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.14.1 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.14 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.12 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.11 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.10 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.9 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.8 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.7 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.6.2 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.6.1 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.6 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.5 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.4 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.3 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.2 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.1 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.3.0 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.2.1 lib/testcentricity_web/exception_queue_helper.rb
testcentricity_web-2.2.0 lib/testcentricity_web/exception_queue_helper.rb