cucumber end of file reached (EOFError)
<p>Running cucumber tests give me following error</p>

<pre><code>  end of file reached (EOFError)
  /usr/lib64/ruby/2.0.0/net/protocol.rb:153:in `read_nonblock'
  /usr/lib64/ruby/2.0.0/net/protocol.rb:153:in `rbuf_fill'
  /usr/lib64/ruby/2.0.0/net/protocol.rb:134:in `readuntil'
  /usr/lib64/ruby/2.0.0/net/protocol.rb:144:in `readline'
  /usr/lib64/ruby/2.0.0/net/http/response.rb:39:in `read_status_line'
  /usr/lib64/ruby/2.0.0/net/http/response.rb:28:in `read_new'
  /usr/lib64/ruby/2.0.0/net/http.rb:1406:in `block in transport_request'
  /usr/lib64/ruby/2.0.0/net/http.rb:1403:in `catch'
  /usr/lib64/ruby/2.0.0/net/http.rb:1403:in `transport_request'
  /usr/lib64/ruby/2.0.0/net/http.rb:1376:in `request'
  /usr/lib64/ruby/2.0.0/net/http.rb:1369:in `block in request'
  /usr/lib64/ruby/2.0.0/net/http.rb:852:in `start'
  /usr/lib64/ruby/2.0.0/net/http.rb:1367:in `request'
  ./features/step_definitions/my_steps.rb:110:in `block (2 levels) in &lt;top (required)&gt;'
  ./features/step_definitions/my_steps.rb:58:in `each'
  ./features/step_definitions/my_steps.rb:58:in `/^action$/'
  features/myFeature.feature:18:in `Then I should XY'
  Connection refused - connect(2) (Errno::ECONNREFUSED)
  /usr/lib64/ruby/2.0.0/net/http.rb:878:in `initialize'
  /usr/lib64/ruby/2.0.0/net/http.rb:878:in `open'
  /usr/lib64/ruby/2.0.0/net/http.rb:878:in `block in connect'
  /usr/lib64/ruby/2.0.0/timeout.rb:66:in `timeout'
  /usr/lib64/ruby/2.0.0/net/http.rb:877:in `connect'
  /usr/lib64/ruby/2.0.0/net/http.rb:862:in `do_start'
  /usr/lib64/ruby/2.0.0/net/http.rb:851:in `start'
  /usr/lib64/ruby/2.0.0/net/http.rb:1367:in `request'
  ./features/support/env.rb:45:in `After' 
</code></pre>

<p>My gemlist from bundle:</p>

<pre><code>* activemodel (4.2.6)
* activerecord (4.2.6)
* activesupport (4.2.6)
* addressable (2.4.0)
* arel (6.0.3)
* builder (3.2.2)
* bundler (1.6.5)
* capybara (2.6.2)
* childprocess (0.5.9)
* cucumber (2.3.3)
* cucumber-core (1.4.0)
* cucumber-wire (0.0.1)
* data_magic (0.22)
* diff-lcs (1.2.5)
* faker (1.6.3)
* ffi (1.9.10)
* gherkin (3.2.0)
* headless (2.2.3)
* i18n (0.7.0)
* json (1.8.3)
* mime-types (3.0)
* mime-types-data (3.2016.0221)
* mini_portile2 (2.0.0)
* minitest (5.8.4)
* multi_json (1.11.2)
* multi_test (0.1.2)
* mysql2 (0.4.3)
* nokogiri (1.6.7.2)
* page-object (1.1.1)
* page_navigation (0.9)
* rack (1.6.4)
* rack-test (0.6.3)
* rspec (3.4.0)
* rspec-core (3.4.4)
* rspec-expectations (3.4.0)
* rspec-mocks (3.4.1)
* rspec-support (3.4.1)
* rubyzip (1.2.0)
* selenium-webdriver (2.53.0)
* snapurl (0.0.3)
* syntax (1.2.0)
* thread_safe (0.3.5)
* tzinfo (1.2.2)
* watir-webdriver (0.9.1)
* websocket (1.2.2)
* xpath (2.0.0)
* yml_reader (0.7)
* zip-zip (0.3)
</code></pre>

<p>OS: openSuSE 13.1
Browser: Firefox 45.0</p>

<p>The error occurs inside a each loop (after 1 till 2 minutes), regardless if I watch the Firefox or let it run headless.</p>

<p>Step Code (from pastebin link in comments) </p>

<pre><code>Then /^I should XY$/ do
  today = Date.today
  heute = today.to_s.sub(/(\w+)-(\w+)-(\w+)/, '\\3.\\2.\\1')
  letzter_tag = Date.today.end_of_month
  differenz = letzter_tag - today
  ueber_naechster_monats_beginn = Date.today.at_beginning_of_month.next_month.next_month
  deutscher_ueber_naechster_monats_beginn = ueber_naechster_monats_beginn.to_s.sub(/(\w+)-(\w+)-(\w+)/, '\\3.\\2.\\1')
  puts 'Heute ist das Datum: '+today.to_s
  puts 'Der letzte Tag des aktuellen Monats ist: '+letzter_tag.to_s
  puts 'Bis zum letzten Tag des aktuellen Monats sind es noch: '+differenz.to_s+' Tage'
  if differenz &lt; 9 || differenz &lt; 0
    puts "Der Monatswechsel liegt an, das neue Datum für den Monatsbeginn ist: "+ueber_naechster_monats_beginn.to_s
  else
    puts "Kein Monatswechsel liegt an."
  end
  tabellen_zeilen = @browser.table(:id =&gt; 'tabellenanfang').tbody.rows
  puts tabellen_zeilen.count.to_s+' Tabellenzeilen gefunden'
  link_list_2_mit_monats_wechsel = Array.new
  link_list_2_ohne_monats_wechsel = Array.new
  link_list_2 = Array.new
  link_list_1 = Array.new
  tabellen_zeilen.each do |tabellen_zeile|
    if !tabellen_zeile.cell(:index =&gt; 2).div.text.include?("nicht veröffentlicht")
      link_list_2 &lt;&lt; tabellen_zeile.cell(:index =&gt; 0).div.a.text
      puts 'veröffentlicht: '+tabellen_zeile.cell(:index =&gt; 0).div.a.text
      beginn_datum = Date.parse(tabellen_zeile.cell(:index =&gt; 3).div.text)
      puts '  Beginn Datum ist: '+beginn_datum.to_s
      aktuelle_differenz = beginn_datum - today
      puts ' '
      # 
      if aktuelle_differenz &lt; 10 || aktuelle_differenz &lt; 0
        link_list_2_mit_monats_wechsel &lt;&lt; tabellen_zeile.cell(:index =&gt; 0).div.a.text
        puts "  "
      else
        link_list_2_ohne_monats_wechsel &lt;&lt; tabellen_zeile.cell(:index =&gt; 0).div.a.text
        puts "  "
      end
    else
      link_list_1 &lt;&lt; tabellen_zeile.cell(:index =&gt; 0).div.a.text
      puts ' '
    end
  end
  puts ' '
  link_list_2.each { |link_text|
    puts '____________________________________________________________________________________________'
    puts ''
    puts link_text
    puts ''
    puts '____________________________________________________________________________________________'
    link = @browser.link(:text =&gt; link_text)
    begin
      link.click
    rescue Watir::Exception::UnknownObjectException =&gt; i #catch the Exception
      @browser.refresh
      link.wait_until_present(600)
      link.click
      puts "Objekt konnte nicht geklickt werden: #{i}"
    end
    puts '    Link geöffnet'
    begin
        @browser.input(:id =&gt; 'tab1').wait_until_present(600)
        @browser.input(:id =&gt; 'tab1').click
    rescue Watir::Exception::UnknownObjectException, TimeoutError =&gt; j #catch the Exception
      @browser.refresh
      @browser.input(:id =&gt; 'tab1').wait_until_present(600)
      @browser.input(:id =&gt; 'tab1').click
      puts "Objekt konnte nicht geklickt werden: #{j}"
    end
    puts ' '
    @browser.element(:id =&gt; 'begin_field').wait_until_present(600)
    @browser.element(:id =&gt; 'begin_field').exists?.should == true
    @browser.text_field(:id =&gt; 'begin_field').set heute
    @browser.element(:id =&gt; 'speichern_unten').wait_until_present(100)
    @browser.input(:id =&gt; 'speichern_unten').click
    begin
      @browser.input(:id =&gt; 'tab2').click
    rescue Watir::Exception::UnknownObjectException =&gt; e #catch the Exception
      @browser.refresh
      @browser.input(:id =&gt; 'tab2').wait_until_present(100)
      @browser.input(:id =&gt; 'tab2').click
      puts "Objekt konnte nicht geklickt werden: #{e}"
    end
    puts ' '
    begin
      @browser.element(:id =&gt; 'begin_date').wait_until_present(100)
      @browser.element(:id =&gt; 'begin_date').exists?.should == true
      @browser.text_field(:id =&gt; 'begin_date').set heute
    rescue Watir::Exception::UnknownObjectException, TimeoutError =&gt; l #catch the Exception
      @browser.refresh
      @browser.element(:id =&gt; 'begin_date').wait_until_present(100)
      @browser.element(:id =&gt; 'begin_date').exists?.should == true
      @browser.text_field(:id =&gt; 'begin_date').set heute
    end    
    begin
      @browser.element(:id =&gt; 'speichern_unten').wait_until_present(600)
      @browser.input(:id =&gt; 'speichern_unten').click
    rescue Watir::Exception::UnknownObjectException, TimeoutError =&gt; h #catch the Exception
      puts "Objekt konnte nicht geklickt werden: #{h}"
      @browser.refresh
      @browser.element(:id =&gt; 'speichern_unten').wait_until_present(600)
      @browser.input(:id =&gt; 'speichern_unten').click
    end    
    begin
      @browser.element(:id =&gt; 'tab1').wait_until_present(600)
      @browser.input(:id =&gt; 'tab1').click
    rescue Watir::Exception::UnknownObjectException, TimeoutError =&gt; g #catch the Exception
      puts "Objekt konnte nicht geklickt werden: #{g}"
      @browser.refresh
      @browser.element(:id =&gt; 'tab1').wait_until_present(600)
      @browser.input(:id =&gt; 'tab1').click
    end
    puts ' '
    begin
      @browser.element(:id =&gt; 'begin_field').wait_until_present(600)
    rescue Watir::Wait::TimeoutError =&gt; k
      puts "Objekt konnte nicht geklickt werden: #{k}"
      @browser.refresh
      @browser.element(:id =&gt; 'begin_field').wait_until_present(600)
    end
    @browser.element(:id =&gt; 'begin_field').exists?.should == true
    @browser.element(:id =&gt; 'begin_field').html.include?(heute).should == true
    @browser.element(:id =&gt; 'tab2').wait_until_present(600)
    @browser.input(:id =&gt; 'tab2').click
    begin
      @browser.element(:id =&gt; 'begin_date').wait_until_present(100)
    rescue Watir::Wait::TimeoutError =&gt; f
      puts "Objekt konnte nicht geklickt werden: #{f}"
      @browser.refresh
      @browser.element(:id =&gt; 'begin_date').wait_until_present(100)
    end
    @browser.element(:id =&gt; 'begin_date').exists?.should == true
    @browser.element(:id =&gt; 'begin_date').html.include?(heute).should == true 
    puts '    neuer Veröffentlichungszeitraum auf '+heute+' gesetzt'
    @browser.link(:text =&gt; 'buttonText').click
    puts '____________________________________________________________________________________________'
    puts ''
  }
  puts ' '
  puts "----------------------------------------------------------------------------------------------"
  puts ' '
  puts ' '
  puts ' '
  puts ' '
  link_list_2_mit_monats_wechsel.each { |monats_wechsel_link_text|
    puts '____________________________________________________________________________________________'
    puts ''
    puts monats_wechsel_link_text
    puts ''
    puts '____________________________________________________________________________________________'
    link = @browser.link(:text =&gt; monats_wechsel_link_text)
    link.click    
    puts '    Link geöffnet'
    @browser.input(:id =&gt; 'tab3').click   
    puts '    Reiter 1 Stelleninfo geöffnet'
    @browser.element(:id =&gt; 'dateField').wait_until_present(600)
    @browser.element(:id =&gt; 'dateField').exists?.should == true
    puts ' '
    @browser.text_field(:id =&gt; 'dateField').set deutscher_ueber_naechster_monats_beginn
    @browser.input(:id =&gt; 'speichern_unten').click
    sleep 1
    @browser.input(:id =&gt; 'tab1').click
    sleep 1
    @browser.input(:id =&gt; 'tab3').click   
    puts '    Reiter 1 Stelleninfo zur Kontrolle geöffnet'
    sleep 1
    @browser.element(:id =&gt; 'dateField').wait_until_present(600)
    @browser.element(:id =&gt; 'dateField').exists?.should == true
    @browser.element(:id =&gt; 'dateField').html.include?(deutscher_ueber_naechster_monats_beginn).should == true
    puts ' '
    @browser.link(:text =&gt; 'buttonText').click
    puts '____________________________________________________________________________________________'
    puts ' '
  }
  puts ' '
end
</code></pre>

<p>env.rb  (from pastebin link in comments)</p>

<pre><code>#!/bin/env ruby
# encoding: utf-8
# -*- coding: utf-8 -*- 
require 'rubygems'
require 'capybara'
# active_support wird fuer die Funktion end_of_month benoetigt
require 'active_support'
require 'active_support/core_ext'
require 'minitest'
require 'minitest/autorun'
require 'rspec/expectations'
require 'capybara/rspec'
require 'capybara/cucumber'
#require 'ruby_gntp'
require 'net/http'
#require 'escape_utils'
require 'watir-webdriver'
require 'page-object/page_factory'
World(PageObject::PageFactory)
require 'headless'
client = Selenium::WebDriver::Remote::Http::Default.new
client.timeout = 600 # seconds – default is 60
Capybara.run_server = true #Whether start server when testing
Capybara.default_selector = :css #default selector , you can change to :css
Capybara.default_max_wait_time = 180 #When we testing AJAX, we can set a default wait time
Capybara.ignore_hidden_elements = false #Ignore hidden elements when testing, make helpful when you hide or show elements using javascript

Before do
  @headless = Headless.new()
  @headless.start
  $DEBUG = true

  #profile = Selenium::WebDriver::Firefox::Profile.new
  @browser  = Watir::Browser.new :firefox, :http_client =&gt; client
  #@browser = Watir::Browser.new
  @browser.window.resize_to(2250, 1024)
end


After do
   @headless.destroy
   #@browser.close
end
</code></pre>

<p>What could I try?</p>