Skip to content

Instantly share code, notes, and snippets.

@hedgehog
Created June 24, 2011 05:05
Show Gist options
  • Select an option

  • Save hedgehog/1044259 to your computer and use it in GitHub Desktop.

Select an option

Save hedgehog/1044259 to your computer and use it in GitHub Desktop.
pause until timeout
describe "with arguments" do
before :all do
@url_stub = "http://not.there.com:88/"
end
context 'the web server is not running' do
it "should wait for the given URL to respond with the expected code" do
pause_for_url_response( 3, @stub_url, '200', 1).should raise_error Timeout::Error
end
end
context 'the web server is now running' do
it "should wait for the given URL to respond with the expected code" do
pause_for_url_response( 3, @stub_url, '200', 1).should_not raise_error Timeout::Error
end
end
end
def pause_for_url_response(seconds,url,code, interval = 60)
begin
Timeout::timeout(seconds) do
response = nil
while response.nil? || response.code != '200' do
response = ::Faraday.get url rescue Faraday::Error::ConnectionFailed
pp response
sleep(interval)
end
end
rescue Timeout::Error => e
raise e
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment