ADB 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rvmrc +1 -0
- data/ADB.gemspec +23 -0
- data/ChangeLog +10 -0
- data/Gemfile +10 -0
- data/Guardfile +18 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +25 -0
- data/cucumber.yml +1 -0
- data/features/ADB.feature +24 -0
- data/features/step_definitions/adb_steps.rb +34 -0
- data/features/support/ApiDemos.apk +0 -0
- data/features/support/env.rb +21 -0
- data/lib/ADB.rb +156 -0
- data/lib/ADB/errors.rb +8 -0
- data/lib/ADB/version.rb +3 -0
- data/spec/lib/ADB_spec.rb +160 -0
- data/spec/spec_helper.rb +29 -0
- metadata +125 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm 1.9.3-p194@ADB --create
|
data/ADB.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/ADB/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jeffrey S. Morgan"]
|
6
|
+
gem.email = ["jeff.morgan@leandog.com"]
|
7
|
+
gem.description = %q{Simple wrapper over Android Debug Bridge command-line tool}
|
8
|
+
gem.summary = %q{Simple wrapper over Android Debug Bridge command-line tool}
|
9
|
+
gem.homepage = "http://github.com/cheezy/ADB"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "ADB"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = ADB::VERSION
|
17
|
+
|
18
|
+
gem.add_dependency 'childprocess', '>= 0.3.5'
|
19
|
+
|
20
|
+
gem.add_development_dependency 'rspec', '>= 2.11.0'
|
21
|
+
gem.add_development_dependency 'cucumber', '>= 1.2.0'
|
22
|
+
|
23
|
+
end
|
data/ChangeLog
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
=== 0.1 / 2012-8-10
|
2
|
+
Initial release of the gem. It has support for the following commands
|
3
|
+
* start-server => start_server
|
4
|
+
* kill-server => stop_server
|
5
|
+
* connect => connect
|
6
|
+
* disconnect => disconnect
|
7
|
+
* devices => devices
|
8
|
+
* wait-for-device => wait_for_device
|
9
|
+
* install => install
|
10
|
+
* uninstall => uninstall
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2, :cli => '--color --format Fuubar' do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
end
|
9
|
+
|
10
|
+
guard 'cucumber', :notification => true, :all_after_pass => false, :cli => '--profile default' do
|
11
|
+
watch(%r{^features/.+\.feature$})
|
12
|
+
watch(%r{^features/support/.+$}) { 'features' }
|
13
|
+
watch(%r{^features/step_definitions/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'features' }
|
14
|
+
watch(%r{^lib/.+\.rb$}) { "features" }
|
15
|
+
watch(%r{^cucumber.yml$}) { "features" }
|
16
|
+
end
|
17
|
+
|
18
|
+
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jeffrey S. Morgan
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# ADB
|
2
|
+
|
3
|
+
A simple wrapper around the Android Debug Bridge
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ADB'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ADB
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
require 'rspec/core/rake_task'
|
4
|
+
require 'cucumber'
|
5
|
+
require 'cucumber/rake/task'
|
6
|
+
|
7
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
8
|
+
spec.ruby_opts = "-I lib:spec"
|
9
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
10
|
+
end
|
11
|
+
task :spec
|
12
|
+
|
13
|
+
Cucumber::Rake::Task.new(:features, "Run all features") do |t|
|
14
|
+
t.profile = 'default'
|
15
|
+
end
|
16
|
+
|
17
|
+
desc 'Run all specs and features'
|
18
|
+
task :test => ['spec', 'features']
|
19
|
+
|
20
|
+
task :lib do
|
21
|
+
$LOAD_PATH.unshift(File.expand_path("lib", File.dirname(__FILE__)))
|
22
|
+
end
|
23
|
+
|
24
|
+
task :default => :spec
|
25
|
+
|
data/cucumber.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
default: --no-source --color --format pretty
|
@@ -0,0 +1,24 @@
|
|
1
|
+
Feature: Using the ADB module
|
2
|
+
|
3
|
+
Scenario: Starting the adb server
|
4
|
+
When the adb server is started
|
5
|
+
Then the adb server should be running
|
6
|
+
|
7
|
+
Scenario: Connecting to a device
|
8
|
+
Given the adb server is started
|
9
|
+
Then I should be able to connect to a local device
|
10
|
+
|
11
|
+
Scenario: Getting list of devices
|
12
|
+
Given the adb server is started
|
13
|
+
And I am connected to the local device
|
14
|
+
Then I should see the device "localhost:5555"
|
15
|
+
|
16
|
+
Scenario: Installing applications on the device
|
17
|
+
Given the adb server is started
|
18
|
+
And I am connected to the local device
|
19
|
+
Then I should be able to install the sample application
|
20
|
+
|
21
|
+
Scenario: Uninstalling the application
|
22
|
+
Given the adb server is started
|
23
|
+
And I am connected to the local device
|
24
|
+
Then I should be able to uninstall the sample application
|
@@ -0,0 +1,34 @@
|
|
1
|
+
When /^the adb server is started$/ do
|
2
|
+
start_server
|
3
|
+
end
|
4
|
+
|
5
|
+
Then /^the adb server should be running$/ do
|
6
|
+
last_stdout.should include "daemon started successfully"
|
7
|
+
end
|
8
|
+
|
9
|
+
Then /^I should be able to connect to a local device$/ do
|
10
|
+
connect('localhost')
|
11
|
+
last_stdout.should include "connected to localhost"
|
12
|
+
disconnect('localhost')
|
13
|
+
end
|
14
|
+
|
15
|
+
Given /^I am connected to the local device$/ do
|
16
|
+
connect
|
17
|
+
end
|
18
|
+
|
19
|
+
Then /^I should see the device "(.*?)"$/ do |device|
|
20
|
+
devices.should include device
|
21
|
+
end
|
22
|
+
|
23
|
+
Then /^I should be able to install the sample application$/ do
|
24
|
+
sn = devices[0]
|
25
|
+
wait_for_device({:serial => sn}, 60)
|
26
|
+
install 'features/support/ApiDemos.apk', {:serial => sn}, 60
|
27
|
+
last_stdout.should include 'Success'
|
28
|
+
end
|
29
|
+
|
30
|
+
Then /^I should be able to uninstall the sample application$/ do
|
31
|
+
sn = devices[0]
|
32
|
+
uninstall 'com.example.android.apis', {:serial => sn}
|
33
|
+
last_stdout.should include 'Success'
|
34
|
+
end
|
Binary file
|
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '../../', 'lib'))
|
2
|
+
|
3
|
+
require 'rspec/expectations'
|
4
|
+
require 'childprocess'
|
5
|
+
require 'ADB'
|
6
|
+
|
7
|
+
World(ADB)
|
8
|
+
|
9
|
+
emulator = ChildProcess.build('emulator', '-avd', 'Android_4.0.3')
|
10
|
+
emulator.start
|
11
|
+
|
12
|
+
at_exit do
|
13
|
+
emulator.stop
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
After do
|
18
|
+
stop_server
|
19
|
+
sleep 1
|
20
|
+
end
|
21
|
+
|
data/lib/ADB.rb
ADDED
@@ -0,0 +1,156 @@
|
|
1
|
+
require 'ADB/version'
|
2
|
+
require 'ADB/errors'
|
3
|
+
require 'childprocess'
|
4
|
+
require 'tempfile'
|
5
|
+
|
6
|
+
#
|
7
|
+
# Mixin that provides access to the commands of the adb executable
|
8
|
+
# which is a part of the android toolset.
|
9
|
+
#
|
10
|
+
module ADB
|
11
|
+
|
12
|
+
attr_reader :last_stdout, :last_stderr
|
13
|
+
|
14
|
+
#
|
15
|
+
# start the server process
|
16
|
+
#
|
17
|
+
# @param timeout value for the command to complete. Defaults to 30
|
18
|
+
# seconds.
|
19
|
+
#
|
20
|
+
def start_server(timeout=30)
|
21
|
+
execute_adb_with(timeout, 'start-server')
|
22
|
+
raise ADBError, "Server didn't start" unless stdout_contains "daemon started successfully"
|
23
|
+
end
|
24
|
+
|
25
|
+
#
|
26
|
+
# stop the server process
|
27
|
+
#
|
28
|
+
# @param timeout value for the command to complete. Defaults to 30
|
29
|
+
# seconds.
|
30
|
+
#
|
31
|
+
def stop_server(timeout=30)
|
32
|
+
execute_adb_with(timeout, 'kill-server')
|
33
|
+
end
|
34
|
+
|
35
|
+
#
|
36
|
+
# connect to a running device via TCP/IP
|
37
|
+
#
|
38
|
+
# @param hostname defaults to 'localhost'
|
39
|
+
# @param port defaults to '5555'
|
40
|
+
# @param timeout value for the command to complete. Defaults to 30
|
41
|
+
# seconds.
|
42
|
+
#
|
43
|
+
def connect(hostname='localhost', port='5555', timeout=30)
|
44
|
+
execute_adb_with(timeout, "connect #{hostname}:#{port}")
|
45
|
+
raise ADBError, "Could not connect to device at #{hostname}:#{port}" unless stdout_contains "connected to #{hostname}"
|
46
|
+
end
|
47
|
+
|
48
|
+
#
|
49
|
+
# disconnect from a device
|
50
|
+
#
|
51
|
+
# @param hostname defaults to 'localhost'
|
52
|
+
# @param port defaults to '5555'
|
53
|
+
# @param timeout value for the command to complete. Defaults to 30
|
54
|
+
# seconds.
|
55
|
+
#
|
56
|
+
def disconnect(hostname='localhost', port='5555', timeout=30)
|
57
|
+
execute_adb_with(timeout, "disconnect #{hostname}:#{port}")
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# list all connected devices
|
62
|
+
#
|
63
|
+
# @param timeout value for the command to complete. Defaults to 30
|
64
|
+
# seconds.
|
65
|
+
#
|
66
|
+
def devices(timeout=30)
|
67
|
+
execute_adb_with(timeout, 'devices')
|
68
|
+
device_list = last_stdout.split("\n")
|
69
|
+
device_list.shift
|
70
|
+
device_list.collect { |device| device.split("\t").first }
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# wait for a device to complete startup
|
75
|
+
#
|
76
|
+
# @param [Hash] which device to wait for. Valid keys are :device,
|
77
|
+
# :emulator, and :serial.
|
78
|
+
# @param timeout value for the command to complete. Defaults to 30
|
79
|
+
# seconds.
|
80
|
+
#
|
81
|
+
def wait_for_device(target={}, timeout=30)
|
82
|
+
execute_adb_with(timeout, "#{which_one(target)} wait-for-device")
|
83
|
+
end
|
84
|
+
|
85
|
+
#
|
86
|
+
# install an apk file to a device
|
87
|
+
#
|
88
|
+
# @param the path and filename to the apk you wish to install
|
89
|
+
# @param [Hash] which device to wait for. Valid keys are :device,
|
90
|
+
# :emulator, and :serial.
|
91
|
+
# @param timeout value for the command to complete. Defaults to 30
|
92
|
+
# seconds.
|
93
|
+
#
|
94
|
+
def install(installable, target={}, timeout=30)
|
95
|
+
execute_adb_with(timeout, "#{which_one(target)} install #{installable}")
|
96
|
+
raise ADBError, "Could not install #{installable}" unless stdout_contains "Success"
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# uninstall an apk file to a device
|
101
|
+
#
|
102
|
+
# @param the package name of the apk ou wish to uninstall
|
103
|
+
# @param [Hash] which device to wait for. Valid keys are :device,
|
104
|
+
# :emulator, and :serial.
|
105
|
+
# @param timeout value for the command to complete. Defaults to 30
|
106
|
+
# seconds.
|
107
|
+
#
|
108
|
+
def uninstall(package, target={}, timeout=30)
|
109
|
+
execute_adb_with(timeout, "#{which_one(target)} uninstall #{package}")
|
110
|
+
raise ADBError, "Could not uninstall #{package}" unless stdout_contains "Success"
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def execute_adb_with(timeout, arguments)
|
116
|
+
args = arguments.split
|
117
|
+
process = ChildProcess.build('adb', *args)
|
118
|
+
process.io.stdout, process.io.stderr = std_out_err
|
119
|
+
process.start
|
120
|
+
kill_if_longer_than(process, timeout)
|
121
|
+
@last_stdout = output(process.io.stdout)
|
122
|
+
@last_stderr = output(process.io.stderr)
|
123
|
+
end
|
124
|
+
|
125
|
+
def which_one(target)
|
126
|
+
direct = ''
|
127
|
+
direct = '-d' if target[:device]
|
128
|
+
direct = '-e' if target[:emulator]
|
129
|
+
direct = "-s #{target[:serial]}" if target[:serial]
|
130
|
+
direct
|
131
|
+
end
|
132
|
+
|
133
|
+
def kill_if_longer_than(process, timeout)
|
134
|
+
begin
|
135
|
+
process.poll_for_exit(timeout)
|
136
|
+
rescue ChildProcess::TimeoutError
|
137
|
+
process.stop
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
def output(file)
|
142
|
+
file.rewind
|
143
|
+
out = file.read
|
144
|
+
file.close
|
145
|
+
file.unlink
|
146
|
+
out
|
147
|
+
end
|
148
|
+
|
149
|
+
def std_out_err
|
150
|
+
return ::Tempfile.new("adb-out#{Time.now}"), ::Tempfile.new("adb-err#{Time.now}")
|
151
|
+
end
|
152
|
+
|
153
|
+
def stdout_contains(expected)
|
154
|
+
last_stdout.include? expected
|
155
|
+
end
|
156
|
+
end
|
data/lib/ADB/errors.rb
ADDED
data/lib/ADB/version.rb
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe ADB do
|
4
|
+
it "should know how to start the adb server" do
|
5
|
+
ADB.should_receive(:last_stdout).and_return("daemon started successfully")
|
6
|
+
should_call_adb_with('start-server')
|
7
|
+
ADB.start_server
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should know how to stop the adb server" do
|
11
|
+
should_call_adb_with('kill-server')
|
12
|
+
ADB.stop_server
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should stop process if it takes too long" do
|
16
|
+
ADB.should_receive(:last_stdout).and_return("device")
|
17
|
+
process = double('process')
|
18
|
+
process.should_receive(:start)
|
19
|
+
process.should_receive(:poll_for_exit).and_raise(ChildProcess::TimeoutError)
|
20
|
+
process.should_receive(:stop)
|
21
|
+
mock_output_file(process)
|
22
|
+
ChildProcess.should_receive(:build).with('adb', 'devices').and_return(process)
|
23
|
+
ADB.devices
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should know how to provide list of devices" do
|
27
|
+
ADB.should_receive(:last_stdout).and_return("device")
|
28
|
+
should_call_adb_with('devices')
|
29
|
+
ADB.devices
|
30
|
+
end
|
31
|
+
|
32
|
+
context "when connecting to a device" do
|
33
|
+
before(:each) do
|
34
|
+
ADB.should_receive(:last_stdout).and_return("connected to localhost")
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should connect successfully" do
|
38
|
+
should_call_adb_with('connect', 'localhost:5555')
|
39
|
+
ADB.connect('localhost', '5555')
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should default to using port 5555" do
|
43
|
+
should_call_adb_with('connect', 'localhost:5555')
|
44
|
+
ADB.connect('localhost')
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should default to using host localhost" do
|
48
|
+
should_call_adb_with('connect', 'localhost:5555')
|
49
|
+
ADB.connect
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when disconnecting from a device" do
|
54
|
+
it "should disconnect successfully" do
|
55
|
+
should_call_adb_with('disconnect', 'localhost:5555')
|
56
|
+
ADB.disconnect('localhost', '5555')
|
57
|
+
end
|
58
|
+
|
59
|
+
it "should default to using port 5555" do
|
60
|
+
should_call_adb_with('disconnect', 'localhost:5555')
|
61
|
+
ADB.disconnect('localhost')
|
62
|
+
end
|
63
|
+
|
64
|
+
it "should default to using host localhost" do
|
65
|
+
should_call_adb_with('disconnect', 'localhost:5555')
|
66
|
+
ADB.disconnect
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "wating for a device to start" do
|
71
|
+
it "should wait for only device" do
|
72
|
+
should_call_adb_with('wait-for-device')
|
73
|
+
ADB.wait_for_device
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should wait for the only connected device" do
|
77
|
+
should_call_adb_with('-d', 'wait-for-device')
|
78
|
+
ADB.wait_for_device :device => 'blah'
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should wait for the only emulator" do
|
82
|
+
should_call_adb_with('-e', 'wait-for-device')
|
83
|
+
ADB.wait_for_device :emulator => 'blah'
|
84
|
+
end
|
85
|
+
|
86
|
+
it "should wait for a device when using serial number" do
|
87
|
+
should_call_adb_with('-s', 'sernum', 'wait-for-device')
|
88
|
+
ADB.wait_for_device :serial => 'sernum'
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
context "when installing an apk" do
|
93
|
+
it "should be able to install an application" do
|
94
|
+
ADB.should_receive(:last_stdout).and_return("Success")
|
95
|
+
should_call_adb_with('install', 'Test.apk')
|
96
|
+
ADB.install 'Test.apk'
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should install to the only connected device" do
|
100
|
+
ADB.should_receive(:last_stdout).and_return("Success")
|
101
|
+
should_call_adb_with('-d', 'install', 'Test.apk')
|
102
|
+
ADB.install 'Test.apk', :device => 'blah'
|
103
|
+
end
|
104
|
+
|
105
|
+
it "should install to the only emulator" do
|
106
|
+
ADB.should_receive(:last_stdout).and_return("Success")
|
107
|
+
should_call_adb_with('-e', 'install', 'Test.apk')
|
108
|
+
ADB.install 'Test.apk', :emulator => 'blah'
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should install to a target using serial number" do
|
112
|
+
ADB.should_receive(:last_stdout).and_return("Success")
|
113
|
+
should_call_adb_with('-s', 'sernum', 'install', 'Test.apk')
|
114
|
+
ADB.install 'Test.apk', :serial => 'sernum'
|
115
|
+
end
|
116
|
+
|
117
|
+
it "should raise an error when the install fails" do
|
118
|
+
ADB.should_receive(:last_stdout).and_return("some error")
|
119
|
+
should_call_adb_with('install', 'Test.apk')
|
120
|
+
expect { ADB.install('Test.apk') }.to raise_error(ADBError)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
context "when uninstalling an apk" do
|
125
|
+
it "should be able to uninstall an application" do
|
126
|
+
ADB.should_receive(:last_stdout).and_return('Success')
|
127
|
+
should_call_adb_with('uninstall', 'com.example')
|
128
|
+
ADB.uninstall 'com.example'
|
129
|
+
end
|
130
|
+
|
131
|
+
it "should uninstall from the only connected device" do
|
132
|
+
ADB.should_receive(:last_stdout).and_return('Success')
|
133
|
+
should_call_adb_with('-d', 'uninstall', 'com.example')
|
134
|
+
ADB.uninstall 'com.example', :device => 'blah'
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should uninstall from the only emulator" do
|
138
|
+
ADB.should_receive(:last_stdout).and_return('Success')
|
139
|
+
should_call_adb_with('-e', 'uninstall', 'com.example')
|
140
|
+
ADB.uninstall 'com.example', :emulator => 'blah'
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should unistall from a device using the serial number" do
|
144
|
+
ADB.should_receive(:last_stdout).and_return('Success')
|
145
|
+
should_call_adb_with('-s', 'sernum', 'uninstall', 'com.example')
|
146
|
+
ADB.uninstall 'com.example', :serial => 'sernum'
|
147
|
+
end
|
148
|
+
|
149
|
+
it "should raise an error when the uninstall fails" do
|
150
|
+
ADB.should_receive(:last_stdout).and_return('some error')
|
151
|
+
should_call_adb_with('uninstall', 'com.example')
|
152
|
+
expect { ADB.uninstall('com.example') }.to raise_error(ADBError)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
|
157
|
+
def should_call_adb_with(*args)
|
158
|
+
ChildProcess.should_receive(:build).with('adb', *args).and_return(process_mock)
|
159
|
+
end
|
160
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
|
5
|
+
require 'rspec'
|
6
|
+
require 'ADB'
|
7
|
+
require 'childprocess'
|
8
|
+
|
9
|
+
include ADB
|
10
|
+
|
11
|
+
def process_mock
|
12
|
+
process_mock = double('process_mock')
|
13
|
+
process_mock.should_receive(:start)
|
14
|
+
process_mock.should_receive(:poll_for_exit)
|
15
|
+
mock_output_file(process_mock)
|
16
|
+
process_mock
|
17
|
+
end
|
18
|
+
|
19
|
+
def mock_output_file(output)
|
20
|
+
output.should_receive(:io).exactly(4).times.and_return(output)
|
21
|
+
output.should_receive(:stdout=)
|
22
|
+
output.should_receive(:stdout).and_return(output)
|
23
|
+
output.should_receive(:stderr=)
|
24
|
+
output.should_receive(:stderr).and_return(output)
|
25
|
+
output.should_receive(:rewind).twice
|
26
|
+
output.should_receive(:read).twice.and_return([])
|
27
|
+
output.should_receive(:close).twice
|
28
|
+
output.should_receive(:unlink).twice
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ADB
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jeffrey S. Morgan
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: childprocess
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.3.5
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.3.5
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.11.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.11.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: cucumber
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 1.2.0
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 1.2.0
|
62
|
+
description: Simple wrapper over Android Debug Bridge command-line tool
|
63
|
+
email:
|
64
|
+
- jeff.morgan@leandog.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- .rvmrc
|
72
|
+
- ADB.gemspec
|
73
|
+
- ChangeLog
|
74
|
+
- Gemfile
|
75
|
+
- Guardfile
|
76
|
+
- LICENSE
|
77
|
+
- README.md
|
78
|
+
- Rakefile
|
79
|
+
- cucumber.yml
|
80
|
+
- features/ADB.feature
|
81
|
+
- features/step_definitions/adb_steps.rb
|
82
|
+
- features/support/ApiDemos.apk
|
83
|
+
- features/support/env.rb
|
84
|
+
- lib/ADB.rb
|
85
|
+
- lib/ADB/errors.rb
|
86
|
+
- lib/ADB/version.rb
|
87
|
+
- spec/lib/ADB_spec.rb
|
88
|
+
- spec/spec_helper.rb
|
89
|
+
homepage: http://github.com/cheezy/ADB
|
90
|
+
licenses: []
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
segments:
|
102
|
+
- 0
|
103
|
+
hash: 1303897695555104367
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
hash: 1303897695555104367
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 1.8.24
|
116
|
+
signing_key:
|
117
|
+
specification_version: 3
|
118
|
+
summary: Simple wrapper over Android Debug Bridge command-line tool
|
119
|
+
test_files:
|
120
|
+
- features/ADB.feature
|
121
|
+
- features/step_definitions/adb_steps.rb
|
122
|
+
- features/support/ApiDemos.apk
|
123
|
+
- features/support/env.rb
|
124
|
+
- spec/lib/ADB_spec.rb
|
125
|
+
- spec/spec_helper.rb
|