Module: SaucelabsAdapter::Utilities
- Included in:
- JsunitSeleniumSupport, SauceTunnel, SeleniumConfig, SshTunnel, Test::Unit::UI::Console::TestRunner
- Defined in:
- lib/saucelabs_adapter/utilities.rb
Instance Method Summary collapse
- #debug(what, print_if_level_ge = 0) ⇒ Object
- #diagnostics_prefix ⇒ Object
- #find_unused_port(hostname, range = (3000..5000)) ⇒ Object
- #raise_with_message(message) ⇒ Object
- #say(what) ⇒ Object
Instance Method Details
#debug(what, print_if_level_ge = 0) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/saucelabs_adapter/utilities.rb', line 12 def debug(what, print_if_level_ge = 0) if ENV['SAUCELABS_ADAPTER_DEBUG'] actual_level = ENV['SAUCELABS_ADAPTER_DEBUG'].to_i STDOUT.puts "#{diagnostics_prefix} #{what}" if print_if_level_ge >= actual_level end end |
#diagnostics_prefix ⇒ Object
4 5 6 |
# File 'lib/saucelabs_adapter/utilities.rb', line 4 def diagnostics_prefix @diagnostics_prefix ||= '[saucelabs-adapter]' end |
#find_unused_port(hostname, range = (3000..5000)) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/saucelabs_adapter/utilities.rb', line 23 def find_unused_port(hostname, range = (3000..5000)) debug 'searching for unused port', 2 range.each do |port| debug "trying #{hostname}:#{port}", 2 begin socket = TCPSocket.new(hostname, port) rescue Errno::ECONNREFUSED debug "it's good, returning #{port}", 2 return port ensure socket.close if socket end end end |
#raise_with_message(message) ⇒ Object
19 20 21 |
# File 'lib/saucelabs_adapter/utilities.rb', line 19 def () raise "#{diagnostics_prefix} #{}" end |
#say(what) ⇒ Object
8 9 10 |
# File 'lib/saucelabs_adapter/utilities.rb', line 8 def say(what) STDOUT.puts "#{diagnostics_prefix} #{what}" end |