Class: Webrat::Selenium::ApplicationServer

Inherits:
Object
  • Object
show all
Includes:
SilenceStream
Defined in:
lib/webrat/selenium/application_server.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SilenceStream

#silence_stream

Class Method Details

.bootObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/webrat/selenium/application_server.rb', line 8

def self.boot
  case Webrat.configuration.application_framework
  when :sinatra
    require "webrat/selenium/sinatra_application_server"
    SinatraApplicationServer.new.boot
  when :merb
    require "webrat/selenium/merb_application_server"
    MerbApplicationServer.new.boot
  when :rails
    require "webrat/selenium/rails_application_server"
    RailsApplicationServer.new.boot
  else
    raise WebratError.new(<<-STR)
Unknown Webrat application_framework: #{Webrat.configuration.application_framework.inspect}

Please ensure you have a Webrat configuration block that specifies an application_framework
in your test_helper.rb, spec_helper.rb, or env.rb (for Cucumber).

For example:

  Webrat.configure do |config|
    # ...
    config.application_framework = :rails
  end
STR
  end
end

Instance Method Details

#bootObject



36
37
38
39
40
# File 'lib/webrat/selenium/application_server.rb', line 36

def boot
  start
  wait
  stop_at_exit
end

#prepare_pid_file(file_path, pid_file_name) ⇒ Object



65
66
67
68
# File 'lib/webrat/selenium/application_server.rb', line 65

def prepare_pid_file(file_path, pid_file_name)
  FileUtils.mkdir_p File.expand_path(file_path)
  File.expand_path("#{file_path}/#{pid_file_name}")
end

#stop_at_exitObject



42
43
44
45
46
# File 'lib/webrat/selenium/application_server.rb', line 42

def stop_at_exit
  at_exit do
    stop
  end
end

#waitObject



48
49
50
51
52
# File 'lib/webrat/selenium/application_server.rb', line 48

def wait
  $stderr.print "==> Waiting for #{Webrat.configuration.application_framework} application server on port #{Webrat.configuration.application_port}... "
  wait_for_socket
  $stderr.print "Ready!\n"
end

#wait_for_socketObject



54
55
56
57
58
59
60
61
62
63
# File 'lib/webrat/selenium/application_server.rb', line 54

def wait_for_socket
  silence_stream(STDOUT) do
    TCPSocket.wait_for_service_with_timeout \
      :host     => Webrat.configuration.application_address,
      :port     => Webrat.configuration.application_port.to_i,
      :timeout  => 30 # seconds
  end
rescue SocketError
  fail
end