Module: Sauce::Utilities

Included in:
RailsServer
Defined in:
lib/sauce/utilities.rb

Defined Under Namespace

Classes: RailsServer

Instance Method Summary collapse

Instance Method Details

#silence_stream(stream) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/sauce/utilities.rb', line 8

def silence_stream(stream)
  old_stream = stream.dup
  stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
  stream.sync = true
  yield
ensure
  stream.reopen(old_stream)
end

#wait_for_server_on_port(port) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/sauce/utilities.rb', line 17

def wait_for_server_on_port(port)
  while true
    begin
      Timeout::timeout(2) do
          socket = TCPSocket.new('127.0.0.1', port)
          socket.close unless socket.nil?
          return
      end
    rescue Errno::ECONNREFUSED, 
      Errno::EBADF,           # Windows
      Timeout::Error
    end
    sleep 2
  end
end

#with_selenium_rcObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/sauce/utilities.rb', line 33

def with_selenium_rc
  ENV['LOCAL_SELENIUM'] = "true"
  STDERR.puts "Starting Selenium RC server on port 4444..."

  jar_file = File.expand_path(File.dirname(__FILE__) + "/../../support/selenium-server.jar")
  command = ["java", "-jar", jar_file, "-port", "4444"]
  server = ChildProcess.build(*command)
  server.start
  wait_for_server_on_port(4444)
  STDERR.puts "Selenium RC running!"
  begin
    yield
  ensure
    Net::HTTP.get("127.0.0.1", "/selenium-server/driver/?cmd=shutDownSeleniumServer", 4444)
  end
end