If you’re writing Cucumber tests using Webrat and Mechanize to test a site, and you are behind a proxy server, you can do something like this to tell mechanize about it in your webrat_steps.rb file:
When /^I am on (.+)$/ do |page_name|
webrat.adapter.mechanize.set_proxy('proxy.host.com',8080)
visit path_to(page_name)
end
I’m sure there’s a tidier way to do this, but it’s quick and it works with the following gem versions:
Cucumber 0.3.11
Webrat 0.5.3
Mechanize 0.9.3
Hi, nice blog!
You can also add this to your world so you need only set it once.
class MechanizeWorld < Webrat::MechanizeSession
def mechanize
return @mechanize unless @mechanize.nil?
@mechanize = Mechanize.new
# Get proxy from http_porxy environment var
if ENV['http_proxy'] != nil
proxy = URI.parse(ENV['http_proxy'])
@mechanize.set_proxy(proxy.host, proxy.port)
end
@mechanize
end
end
World do
MechanizeWorld.new
end
matth
9 Jul 10 at 10:47 pm