Sha256: dbf17a0b1964a1c8c794c0ee5cc72baa7c9ab40119d80528c94b5d1ffef214d8

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

module Sauce
  class Connect
    attr_reader :status, :error

    def initialize(options={})
      @ready = false
      @status = "uninitialized"
      @error = nil
      host = options[:host] || '127.0.0.1'
      port = options[:port] || '3000'
      options.delete(:host)
      options.delete(:port)
      config = Sauce::Config.new(options)
      args = ['-u', config.username, '-k', config.access_key, '-s', host, '-p', port, '-d', config.domain, '-t', '80']
      @pipe = IO.popen(([Sauce::Connect.find_sauce_connect] + args).join(' '))
      at_exit do
        Process.kill("INT", @pipe.pid)
        while @ready
          sleep 1
        end
      end
      Thread.new {
        while( (line = @pipe.gets) )
          if line =~ /Tunnel host is (.*) (\.\.|at)/
            @status = $1
          end
          if line =~/You may start your tests/
            @ready = true
          end
          if line =~ /- (Problem.*)$/
            @error = $1
          end
          puts line
        end
        @ready = false
      }
    end

    def wait_until_ready
      while(!@ready)
        sleep 0.4
      end
    end

    def disconnect
      if @ready
        Process.kill("INT", @pipe.pid)
        while @ready
          sleep 1
        end
      end
    end

    def self.find_sauce_connect
      File.join(File.dirname(File.dirname(File.expand_path(File.dirname(__FILE__)))), "support", "sauce_connect")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sauce-0.10.0 lib/sauce/connect.rb