lib/honeydew/device.rb in honeydew-0.15.0 vs lib/honeydew/device.rb in honeydew-0.16.0
- old
+ new
@@ -1,14 +1,16 @@
require 'net/http'
require 'honeydew/device_matchers'
require 'honeydew/device_actions'
+require 'honeydew/device_log_formatter'
module Honeydew
class Device
include Honeydew::DeviceActions
include Honeydew::DeviceMatchers
+ include Honeydew::DeviceLogFormatter
ServerTimeoutError = Class.new(Timeout::Error)
ActionFailedError = Class.new(Timeout::Error)
FinderTimeout = Class.new(Timeout::Error)
@@ -38,11 +40,11 @@
def perform_assertion action, arguments = {}, options = {}
ensure_device_ready
arguments[:timeout] = Honeydew.config.timeout.to_s
- log "performing assertion #{action} with arguments #{arguments}"
+ debug "performing assertion #{action} with arguments #{arguments}"
Timeout.timeout Honeydew.config.timeout.to_i, FinderTimeout do
begin
send_command action, arguments
rescue ActionFailedError
sleep 0.3
@@ -54,11 +56,11 @@
end
def perform_action action, arguments = {}, options = {}
ensure_device_ready
arguments[:timeout] = Honeydew.config.timeout.to_s
- log "performing action #{action} with arguments #{arguments}"
+ debug "performing action #{action} with arguments #{arguments}"
send_command action, arguments
end
def send_command action, arguments
uri = device_endpoint('/command')
@@ -79,15 +81,10 @@
else
raise "honeydew-server failed to process command, response: #{response.value}"
end
end
- def log message
- return unless Honeydew.config.debug
- STDERR.puts "Device #{serial}: #{message}"
- end
-
def ensure_device_ready
@device_ready ||= begin
wait_for_honeydew_server
true
end
@@ -96,14 +93,14 @@
def timeout_server_operation &block
Timeout.timeout(Honeydew.config.server_timeout.to_i, ServerTimeoutError, &block)
end
def wait_for_honeydew_server
- log 'waiting for honeydew-server to respond'
+ info 'waiting for honeydew-server to respond'
timeout_server_operation do
sleep 0.1 until honeydew_server_alive?
end
- log 'honeydew-server is alive and awaiting commands'
+ info 'honeydew-server is alive and awaiting commands'
rescue ServerTimeoutError
raise 'timed out waiting for honeydew-server to respond'
end