RubyのSeleniumでCapybaraを使用しています(テストフレームワーク内ではありません)。
Ruby コンソールを開いてメソッドを実行すると機能しますが、同じメソッドを再度実行すると、このエラーが発生します。
Errno::ECONNREFUSED: Connection refused - connect(2)
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:762:in `initialize'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:762:in `open'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:762:in `block in connect'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/timeout.rb:54:in `timeout'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/timeout.rb:99:in `timeout'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:762:in `connect'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:755:in `do_start'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:744:in `start'
from /home/ross/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/net/http.rb:1284:in `request'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/http/default.rb:83:in `response_for'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/http/default.rb:39:in `request'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/bridge.rb:598:in `raw_execute'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/bridge.rb:576:in `execute'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/remote/bridge.rb:99:in `get'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/selenium-webdriver-2.26.0/lib/selenium/webdriver/common/navigation.rb:14:in `to'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/capybara-2.0.1/lib/capybara/selenium/driver.rb:34:in `visit'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/capybara-2.0.1/lib/capybara/session.rb:180:in `visit'
from /home/ross/.rvm/gems/ruby-1.9.3-p327/gems/capybara-2.0.1/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>'
コードは次のようなものです。
class ExampleClass
include Capybara::DSL
def do_capybara
Capybara.app_host = "http://example.com"
Capybara.run_server = false
Capybara.current_driver = :selenium
visit '/'
page.driver.browser.close
Capybara.reset_sessions!
end