Ruby Function to Check If We Are Currently Online
First, install it:
gem install online
Then, you can use the online?
global function:
require 'online'
if online?
# do some LIVE testing
end
You can also check a particular URL:
if online?(uri: 'https://api.github.com')
# GitHub API is accessible
end
The online?()
function doesn't make an HTTP request on each call, but
instead caches the previous result for five minutes. You can change this
interval to three seconds, for example:
if online?(ttl: 3)
# We are online, let's run integration tests!
end
That's it.
How to contribute
Read these guidelines. Make sure your build is green before you contribute your pull request. You will need to have Ruby 3.0+ and Bundler installed. Then:
bundle update
bundle exec rake
If it's clean and you don't see any error messages, submit your pull request.