Permalink
Browse files

add last stdout and stderr to adberror messages

  • Loading branch information...
1 parent 2c87eb7 commit f69c36490601bb120613045de0acab458bac9f90 @joelbyler joelbyler committed Oct 29, 2012
Showing with 39 additions and 6 deletions.
  1. +17 −4 lib/ADB.rb
  2. +1 −1 lib/ADB/version.rb
  3. +21 −1 spec/lib/ADB_spec.rb
View
21 lib/ADB.rb
@@ -21,7 +21,7 @@ module ADB
#
def start_server(timeout=30)
execute_adb_with(timeout, 'start-server')
- raise ADBError, "Server didn't start" unless stdout_contains "daemon started successfully"
+ raise ADBError, "Server didn't start#{stdout_stderr_message}" unless stdout_contains "daemon started successfully"
end
#
@@ -44,7 +44,7 @@ def stop_server(timeout=30)
#
def connect(hostname='localhost', port='5555', timeout=30)
execute_adb_with(timeout, "connect #{hostname}:#{port}")
- raise ADBError, "Could not connect to device at #{hostname}:#{port}" unless stdout_contains "connected to #{hostname}"
+ raise ADBError, "Could not connect to device at #{hostname}:#{port}#{stdout_stderr_message}" unless stdout_contains "connected to #{hostname}"
end
#
@@ -95,7 +95,7 @@ def wait_for_device(target={}, timeout=30)
#
def install(installable, options=nil, target={}, timeout=30)
execute_adb_with_exactly(timeout, *"#{which_one(target)} wait-for-device install #{options}".split, installable)
- raise ADBError, "Could not install #{installable}" unless stdout_contains "Success"
+ raise ADBError, "Could not install #{installable}#{stdout_stderr_message}" unless stdout_contains "Success"
end
#
@@ -109,7 +109,7 @@ def install(installable, options=nil, target={}, timeout=30)
#
def uninstall(package, target={}, timeout=30)
execute_adb_with(timeout, "#{which_one(target)} uninstall #{package}")
- raise ADBError, "Could not uninstall #{package}" unless stdout_contains "Success"
+ raise ADBError, "Could not uninstall #{package}#{stdout_stderr_message}" unless stdout_contains "Success"
end
#
@@ -204,6 +204,19 @@ def root(target={}, timeout=30)
private
+ def stdout_stderr_message
+ if not last_stdout.empty?
+ if not last_stderr.empty?
+ return " Cause: #{last_stdout}, and Error: #{last_stderr}"
+ else
+ return " Cause: #{last_stdout}"
+ end
+ elsif not last_stderr.empty?
+ return " Error: #{last_stderr}"
+ end
+ ''
+ end
+
def execute_adb_with(timeout, arguments)
args = arguments.split
execute_adb_with_exactly timeout, *args
View
2 lib/ADB/version.rb
@@ -1,3 +1,3 @@
module ADB
- VERSION = "0.5.4"
+ VERSION = "0.5.6"
end
View
22 spec/lib/ADB_spec.rb
@@ -209,10 +209,30 @@
end
it "should raise an error when the uninstall fails" do
- ADB.should_receive(:last_stdout).and_return('some error')
+ ADB.should_receive(:last_stdout).any_number_of_times.and_return('some error')
should_call_adb_with('uninstall', 'com.example')
expect { ADB.uninstall('com.example') }.to raise_error(ADBError)
end
+
+ it "should raise an error when the uninstall fails" do
+ ADB.should_receive(:last_stdout).any_number_of_times.and_return('some stdout message')
+ should_call_adb_with('uninstall', 'com.example')
+ expect { ADB.uninstall('com.example') }.to raise_error(ADBError, "Could not uninstall com.example Cause: some stdout message")
+ end
+
+ it "should raise an error when the uninstall fails" do
+ ADB.should_receive(:last_stderr).any_number_of_times.and_return('some stderr message')
+ should_call_adb_with('uninstall', 'com.example')
+ expect { ADB.uninstall('com.example') }.to raise_error(ADBError, "Could not uninstall com.example Error: some stderr message")
+ end
+
+ it "should raise an error when the uninstall fails" do
+ ADB.should_receive(:last_stdout).any_number_of_times.and_return('some stdout message')
+ ADB.should_receive(:last_stderr).any_number_of_times.and_return('some stderr message')
+ should_call_adb_with('uninstall', 'com.example')
+ expect { ADB.uninstall('com.example') }.to raise_error(ADBError, "Could not uninstall com.example Cause: some stdout message, and Error: some stderr message")
+ end
+
end

0 comments on commit f69c364

Please sign in to comment.