Sha256: d2b9e031403fa44540b94bac2c30b6520ae7161e793e9a9768625c8cb05324cb

Contents?: true

Size: 1.33 KB

Versions: 30

Compression:

Stored size: 1.33 KB

Contents

require 'socket'
require 'timeout'
require 'sprockets'

module TestHelpers
  class ServerDown < Exception; end

  def get_random_open_port
    # Using a port of "0" relies on the system to pick an open port.
    server = TCPServer.new('127.0.0.1', 0)
    port = server.addr[1]
    server.close
    port
  end

  def verify_server_up(host)
    http = HTTPClient.new
    4.times do
      begin
        http.get(host)
        return true
      rescue Errno::ECONNREFUSED
        sleep 0.5
      end
    end
    raise ServerDown, "Server failed to start: #{host}"
  end

  def find_resource(resources, regex)
    begin
      resources.select { |resource| resource.resource_url.match(regex) }.fetch(0)
    rescue IndexError
      raise "Missing expected image with resource_url that matches: #{regex}"
    end
  end

  def setup_sprockets(capybara_client)
    root = File.expand_path("../../lib/percy/capybara/client/testdata", __FILE__)
    environment = Sprockets::Environment.new(root)
    environment.append_path '.'

    sprockets_options = double('sprockets_options')
    allow(sprockets_options).to receive(:precompile).and_return([/(?:\/|\\|\A)base\.(css|js)$/])
    allow(sprockets_options).to receive(:digest).and_return(false)

    capybara_client.sprockets_environment = environment
    capybara_client.sprockets_options = sprockets_options
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
percy-capybara-2.3.3 spec/support/test_helpers.rb
percy-capybara-2.3.2 spec/support/test_helpers.rb
percy-capybara-2.3.1 spec/support/test_helpers.rb
percy-capybara-2.3.0 spec/support/test_helpers.rb
percy-capybara-2.3.0.pre.beta spec/support/test_helpers.rb
percy-capybara-2.2.1 spec/support/test_helpers.rb
percy-capybara-2.2.0 spec/support/test_helpers.rb
percy-capybara-2.1.1 spec/support/test_helpers.rb
percy-capybara-2.1.0 spec/support/test_helpers.rb
percy-capybara-2.0.1 spec/support/test_helpers.rb
percy-capybara-2.0.0 spec/support/test_helpers.rb
percy-capybara-1.2.0 spec/support/test_helpers.rb
percy-capybara-1.1.0 spec/support/test_helpers.rb
percy-capybara-1.0.0 spec/support/test_helpers.rb
percy-capybara-0.7.0 spec/support/test_helpers.rb
percy-capybara-0.6.1 spec/support/test_helpers.rb
percy-capybara-0.6.0 spec/support/test_helpers.rb
percy-capybara-0.5.0 spec/support/test_helpers.rb
percy-capybara-0.4.12 spec/support/test_helpers.rb
percy-capybara-0.4.11 spec/support/test_helpers.rb