Module: Capybara::Webmock

Defined in:
lib/capybara/webmock.rb,
lib/capybara/webmock/version.rb

Defined Under Namespace

Classes: Proxy

Constant Summary collapse

VERSION =
"0.4.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.port_numberObject

Returns the value of attribute port_number.



10
11
12
# File 'lib/capybara/webmock.rb', line 10

def port_number
  @port_number
end

Class Method Details

.chrome_switchesObject



37
38
39
# File 'lib/capybara/webmock.rb', line 37

def chrome_switches
  ["--proxy-server=127.0.0.1:#{port_number}"]
end

.firefox_profileObject



26
27
28
29
30
31
32
33
34
35
# File 'lib/capybara/webmock.rb', line 26

def firefox_profile
  proxy_host = '127.0.0.1'
  profile = ::Selenium::WebDriver::Firefox::Profile.new
  profile["network.proxy.type"] = 1
  profile["network.proxy.http"] = proxy_host
  profile["network.proxy.http_port"] = port_number
  profile["network.proxy.ssl"] = proxy_host
  profile["network.proxy.ssl_port"] = port_number
  profile
end

.phantomjs_optionsObject



41
42
43
# File 'lib/capybara/webmock.rb', line 41

def phantomjs_options
  ["--proxy=127.0.0.1:#{port_number}"]
end

.startObject



12
13
14
15
16
17
# File 'lib/capybara/webmock.rb', line 12

def start
  log_file   = File.join('log', 'test.log')
  gem_path   = File.dirname(__FILE__)
  proxy_file = File.join(gem_path, 'webmock', 'config.ru')
  IO.popen("PROXY_PORT_NUMBER=#{port_number} rackup #{proxy_file} >> #{log_file} 2>&1")
end

.stopObject



19
20
21
22
23
24
# File 'lib/capybara/webmock.rb', line 19

def stop
  if File.exist?(Capybara::Webmock::Proxy::PID_FILE)
    rack_pid = File.read(Capybara::Webmock::Proxy::PID_FILE).to_i
    Process.kill('HUP', rack_pid)
  end
end