title: RSpec fails before timed loop completes
body: <p>In our Ruby application web testing application using watir-webdriver, we have added code to allow up to 30 seconds for an element that is present on a page but not yet visible to become visible (due to AJAX, javascript, performance, etc.).  The routine that is being tested is:</p>
  
  <pre><code>start_time = Time.now
  while !visible? do
    @logger.info "!visible is true, looping"
    sleep 1
    if Time.now - start_time &gt; 30
      @logger.debug("error while checking for visible")
      raise ElementHiddenError, element_hidden_message
    end
  end
  </code></pre>
  
  <p>The RSpec that is used to test this is:</p>
  
  <pre><code>...
  it "raises ElementHiddenError if element is hidden" do
    element.should_receive(:visible?).and_return(false)
    expect { proxy.set('something') }.to raise_error(ElementHiddenError)
  end
  ....
  </code></pre>
  
  <p>When I run this RSpec, I receive this error:</p>
  
  <pre><code>1)
  'ElementProxy#set raises ElementHiddenError if element is hidden' FAILED
  expected ElementHiddenError but nothing was raised
  ./spec/element_proxy_spec.rb:144:in `(root)'
  org/jruby/RubyKernel.java:2043:in `instance_eval'
  ./spec/spec_helper.rb:68:in `timeout'
  org/jruby/RubyArray.java:1614:in `each'
  org/jruby/RubyArray.java:1614:in `each'
  org/jruby/RubyKernel.java:1052:in `load'
  </code></pre>
  
  <p>I can get this RSpec to pass by commenting out the loop:</p>
  
  <pre><code>#start_time = Time.now
  while !visible? do
    @logger.info "!visible is true, looping"
    sleep 1
    #if Time.now - start_time &gt; 30
      @logger.debug("error while checking for visible")
      raise ElementHiddenError, element_hidden_message
    #end
  end
  </code></pre>
  
  <p>I am not the original author of this code, but it appears that something is happening with Time or sleep in the RSpec which is affecting this test.  </p>
  
  <p>I would appreciate any ideas about how to debug this issue, as this routine is used in almost all of our command sets.  The delay works in our application but does not pass the RSpec.</p>
  
  <p>Thanks.</p>